查询实例
程序员文章站
2022-03-27 12:22:58
...
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);
}
}
下一篇: solr单机查询代码实例