用了Elasticsearch,一口气上5T

es GET index/_count转化为restHighLevelClient怎么写?

Elasticsearch | 作者 Han_ | 发布于2020年03月18日 | 阅读数:7596

想统计组合字段的数量,这种dsl转为Java restHighLevelClient怎么写呢?
GET reyun/_count
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "reyun.category.02.children.0201.children.020110.level"
}
},
{
"exists": {
"field": "reyun.category.02.children.0206.children.020619.level"
}
}
]
}
}
}
已邀请:

tacsklet - 公司有用到es

赞同来自:

https://www.elastic.co/guide/e ... .html
官网都有例子的。

God_lockin

赞同来自:

大概这样吧
 
public static void main(String[] args) throws IOException {
List<String> fieldList = Arrays.asList("FieldA", "FieldB");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
fieldList.forEach(field -> boolQueryBuilder.must(QueryBuilders.existsQuery(field)));
searchSourceBuilder.query(boolQueryBuilder);
CountRequest countRequest = new CountRequest()
.indices("index")
.types("type") // not exists in 7+
.source(searchSourceBuilder);
CountResponse countResponse = restHighLevelClient.count(countRequest, RequestOptions.DEFAULT);
System.out.println("Count:" + countResponse.getCount());
}

要回复问题请先登录注册