我尝试在弹性搜索中为多个字段设置后置过滤器。但它不起作用。请告诉我如何设置?
SearchResponse searchResponse = client.prepareSearch("idx_articles").setTypes("articles")
.setPostFilter(QueryBuilders.matchQuery("pubish", true))
.setPostFilter(QueryBuilders.matchQuery("status", "active"))
.setQuery(QueryBuilders.wildcardQuery("title", "pub"+"*"))
.addSort("articleVersion", SortOrder.DESC) // Filter
.execute().actionGet();
它只考虑.setPostFilter(QueryBuilders.matchQuery(“status”,“active”))
它没有考虑过滤器.setPostFilter(QueryBuilders.matchQuery(“pubish”,true))
请告诉我如何设置多个场滤波器?
答案 0 :(得分:0)
你可以使用Bool过滤器Inside Post过滤器,如下所示
setPostFilter(FilterBuilders.boolFilter()
.must(FilterBuilders.termFilter("pubish", true))
.must(FilterBuilders.termFilter("status", "active")))
供参考
https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.3/bool-filter.html