.setParams("count", "_count")方法不存在
时间: 2023-07-19 16:45:47 浏览: 152
python-常用单词及语法_1681366872966.doc
非常抱歉,我的回答有误。确实,`setParams` 方法并不存在。如果需要使用 Script Query,可以使用以下代码:
```java
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// 设置查询条件
searchSourceBuilder.query(QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("supplierNo", "C2217")));
// 设置返回结果数量
searchSourceBuilder.size(0);
// 禁用返回总命中数
searchSourceBuilder.trackTotalHits(false);
// 构建 composite 聚合
CompositeAggregationBuilder compositeAggregation = AggregationBuilders.composite("my_buckets")
.size(10)
.sources(
AggregationBuilders.terms("erpGoodsId").field("erpGoodsId").order("asc"),
AggregationBuilders.terms("batchNum").field("batchNum").order("asc"),
AggregationBuilders.terms("wmsProductCode").field("wmsProductCode").missing("null").order("asc")
);
// 构建 filter 聚合
FilterAggregationBuilder filterAggregation = AggregationBuilders.filter("filter_empty_dest",
QueryBuilders.scriptQuery(new Script("params.count != null"))
.setScriptParams(Map.of("count", "_count"))
);
// 将 filter 聚合作为 composite 聚合的子聚合
compositeAggregation.subAggregation(filterAggregation);
// 将 composite 聚合作为查询的聚合
searchSourceBuilder.aggregation(compositeAggregation);
```
以上代码中使用了 `Script` 类来构建脚本查询,并使用 `setScriptParams` 方法来设置脚本参数。这样可以在 Script Query 中使用 `_count` 参数。
阅读全文