QueryFilterBuilder弹性搜索2.4

时间:2017-01-11 06:50:54

标签: elasticsearch

我现在已经将这段代码作为弹性搜索2.4。不推荐使用QueryFilterBuilder并显示错误。 QueryFilterBuilder queryFilterBuilder = FilterBuilders.queryFilter(esQueryBuilder);我试图用QueryBuider替换它,但它不接受。

 if (StringUtils.isNotBlank(textQuery)) {
  QueryBuilder esQueryBuilder = CatalogKeywordSearchHelper.getAppropriateESQueryForUserQuery(storeId, textQuery);
  QueryFilterBuilder queryFilterBuilder = FilterBuilders.queryFilter(esQueryBuilder);
  filterBuildersMap.put(IdxSchemaConstants.TEXT_QUERY, queryFilterBuilder);
}

1 个答案:

答案 0 :(得分:1)

在ES 2.0中不推荐使用查询过滤器,从那时起查询现在可以在过滤器上下文中使用,您只需使用bool/filter查询并将查询放入其中:

 if (StringUtils.isNotBlank(textQuery)) {
    QueryBuilder esQueryBuilder = CatalogKeywordSearchHelper.getAppropriateESQueryForUserQuery(storeId, textQuery);

    # change this line
    BoolQueryBuilder queryFilterBuilder = QueryBuilders.boolQuery()
        .filter(esQueryBuilder);

    filterBuildersMap.put(IdxSchemaConstants.TEXT_QUERY, queryFilterBuilder);
}