|
@@ -84,7 +84,7 @@ public class EsDocTests {
|
|
*/
|
|
*/
|
|
public void putbatchTest() throws IOException {
|
|
public void putbatchTest() throws IOException {
|
|
//创建数据对象
|
|
//创建数据对象
|
|
- List<EsProduct> list = ParseHtml.parse("大数据");
|
|
|
|
|
|
+ List<EsProduct> list = ParseHtml.parse("java");
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
bulkRequest.timeout("2m");
|
|
bulkRequest.timeout("2m");
|
|
for(EsProduct esProduct :list){
|
|
for(EsProduct esProduct :list){
|
|
@@ -212,19 +212,21 @@ public class EsDocTests {
|
|
searchSourceBuilder.sort("num",SortOrder.DESC);
|
|
searchSourceBuilder.sort("num",SortOrder.DESC);
|
|
//模糊查询
|
|
//模糊查询
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
|
+
|
|
boolQueryBuilder.must(QueryBuilders.matchQuery("name","java"));
|
|
boolQueryBuilder.must(QueryBuilders.matchQuery("name","java"));
|
|
boolQueryBuilder.must(QueryBuilders.rangeQuery("price").gt("100").lt("200"));
|
|
boolQueryBuilder.must(QueryBuilders.rangeQuery("price").gt("100").lt("200"));
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
searchSourceBuilder.query(boolQueryBuilder);
|
|
//设置超时
|
|
//设置超时
|
|
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
|
|
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
|
|
//设置起始位置
|
|
//设置起始位置
|
|
- searchSourceBuilder.from(1);
|
|
|
|
|
|
+ searchSourceBuilder.from(10);
|
|
//设置页大小
|
|
//设置页大小
|
|
- searchSourceBuilder.size(30);
|
|
|
|
|
|
+ searchSourceBuilder.size(10);
|
|
//绑定build
|
|
//绑定build
|
|
searchRequest.source(searchSourceBuilder);
|
|
searchRequest.source(searchSourceBuilder);
|
|
//执行搜索
|
|
//执行搜索
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
|
|
+ System.out.println(searchResponse.getHits().getTotalHits());
|
|
//遍历hits
|
|
//遍历hits
|
|
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
|
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
|
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
|
|
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
|