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

最佳答案

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

关于elasticsearch - 查询FilterBuilders elasticsearch 2.4,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41584470/

10-10 18:36