本文介绍了将弹性搜索从1.4.3迁移到2.4代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在从弹性搜索1.4.3迁移到2.4和
替换从弹性搜索文档和其他参考文献引用的代码,需要更换和Filter?



代码: -

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

//对于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 ); 

//对于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 = QueryBuilders.boolQuery()
.filter(excPlatformFilter)
.filter(incPlatformEmptyFilter);


I am migrating from elastic search 1.4.3 to 2.4 andreplaced piece of code referred from elastic search docs and other references need replacement of andFilter?

Code:-

  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;}
}
解决方案

You can do it like this:

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);

这篇关于将弹性搜索从1.4.3迁移到2.4代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 14:14