gpt4 book ai didi

elasticsearch - QueryBuilders数组 Elasticsearch 2.4

转载 作者:行者123 更新时间:2023-12-03 01:49:33 32 4
gpt4 key购买 nike

 QueryBuilder missingFiletr = QueryHelper.andQuery(incCatsEmptyFilter, excCatsEmptyFilter, incEmptyFilter, excEmptyFilter);

我正在调用andQuery方法以及 和FilterBuilders的所有参数()
现在要去 filterBuilders 数组,我要将其提取到 filterBuilder 中,因为我想对所有queryBuilders进行 。格式正确吗
public static QueryBuilder andQuery(QueryBuilder... filterBuilders) {
QueryBuilder filterBuilder = null;

if (filterBuilders != null && filterBuilders.length > 0) {

for(int i = 0 ; i < filterBuilders.length ; i++){
filterBuilder = QueryBuilders.boolQuery().filter(filterBuilders[i]);
}

}
return filterBuilder;

}

最佳答案

不,您要在每次迭代中创建一个新的bool/filter查询,并将其重新分配给相同的变量,但这种方法将不起作用。您需要这样做:

public static QueryBuilder andQuery(QueryBuilder... filterBuilders) {
BoolQueryBuilder filterBuilder = null;

if (filterBuilders != null && filterBuilders.length > 0) {
// create the bool query here
filterBuilder = QueryBuilders.boolQuery();

for(QueryBuilder filter : filterBuilders){
// add each filter to the bool query here
filterBuilder.filter(filter);
}

}
return filterBuilder;
}

关于elasticsearch - QueryBuilders数组 Elasticsearch 2.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606310/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com