gpt4 book ai didi

java - 将 Elasticsearch 从 1.4.3 迁移到 2.4 java 代码

转载 作者:行者123 更新时间:2023-12-01 09:02:28 25 4
gpt4 key购买 nike

我正在从 Elasticsearch 1.4.3 迁移到 2.4,并且替换了从 Elasticsearch 文档引用的代码段,其他引用需要替换 andFilter?

代码:-

  TermQueryBuilder incPlatformFilter=QueryBuilders.termQuery(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS, platformId);

//For MissingQuerybuilder
//MissingFilterBuilder incPlatformEmptyFilter = FilterBuilders.missingFilter(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS);
BoolQueryBuilder incPlatformEmptyFilter = new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS));
//NotFilterBuilder
//NotFilterBuilder excPlatformFilter = FilterBuilders.notFilter(FilterBuilders.termFilter(IdxSchemaConstants.FULL_OFFER_ACTION_EXCLUSIVE_PLATFORMS, platformId));
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery(IdxSchemaConstants.FULL_OFFER_ACTION_EXCLUSIVE_PLATFORMS, platformId);
BoolQueryBuilder excPlatformFilter = new BoolQueryBuilder().mustNot(termQueryBuilder);

QueryBuilder platformPartialMatched = QueryHelper.andFilterBuilders(excPlatformFilter, incPlatformEmptyFilter);

public class QueryHelper {
public static QueryBuilder andFilterBuilders(QueryBuilder... filterBuilders) {

QueryBuilder filterBuilder = null;

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

filterBuilder = QueryBuilders.andFilter(filterBuilders);
}
return filterBuilder;}
}

最佳答案

你可以这样做:

TermQueryBuilder incPlatformFilter = QueryBuilders.termQuery(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS, platformId);

//For MissingQuerybuilder
//MissingFilterBuilder incPlatformEmptyFilter = FilterBuilders.missingFilter(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS);
BoolQueryBuilder incPlatformEmptyFilter = new BoolQueryBuilder().mustNot(new ExistsQueryBuilder(IdxSchemaConstants.FULL_OFFER_ACTION_INCLUSIVE_PLATFORMS));
//NotFilterBuilder
//NotFilterBuilder excPlatformFilter = FilterBuilders.notFilter(FilterBuilders.termFilter(IdxSchemaConstants.FULL_OFFER_ACTION_EXCLUSIVE_PLATFORMS, platformId));
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery(IdxSchemaConstants.FULL_OFFER_ACTION_EXCLUSIVE_PLATFORMS, platformId);
BoolQueryBuilder excPlatformFilter = new BoolQueryBuilder().mustNot(termQueryBuilder);

// ==> use a bool/filter to replace the "and" query <<==
QueryBuilder platformPartialMatched = QueryBuilders.boolQuery()
.filter(excPlatformFilter)
.filter(incPlatformEmptyFilter);

关于java - 将 Elasticsearch 从 1.4.3 迁移到 2.4 java 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41567010/

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