SearchResponse response = client.prepareSearch(esIndex).setTypes(esType)
.setIndicesOptions(IndicesOptions.fromOptions(true, true, false, false)) // 忽略不可用或不存在的index .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(boolQuery)
.setPostFilter(rangeQueryBuilder).addSort(sort, sortOrder).setFrom(start).setSize(rows)
.setPreference("_primary_first")
// .setExplain(true) //设置是否按查询匹配度排序(加上这个参数报错)
.execute().actionGet();
SearchHit[] hits = response.getHits().getHits();
long total = response.getHits().getTotalHits();
StringBuilder context = new StringBuilder();
for (SearchHit hit : hits) {
Map<String, Object> sourceMap = hit.getSource();
Iterator<String> it = sourceMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
Object value = sourceMap.get(key);
}
}
查询实例
最新推荐文章于 2024-04-27 00:53:29 发布