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