【发布时间】:2016-06-23 18:32:13
【问题描述】:
我在 elasticsearch (v2.3.3) 之上构建了一个 Web 应用程序。为了过滤查询,我使用了 elasticsearch 的后置过滤器。但是我开始知道,如果我使用后置过滤器,那么过滤的性能优势将会丢失,因为我没有使用任何聚合或差异过滤。 (参考:https://www.elastic.co/guide/en/elasticsearch/guide/current/_post_filter.html)
这就是我的 elasticsearch 客户端的样子:
Client client = TransportClient.builder().build().addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),
9300));
SearchResponse response = client.prepareSearch("index_name")
.setTypes("index_type")
.setQuery(QueryBuilders.simpleQueryStringQuery(query)
.field("newContent").field("T"))
.setPostFilter(QueryBuilders.termQuery(Collection, true))
.setFetchSource(new String[] { "U", "UE", "UD", "T" }, null)
.setVersion(true).addHighlightedField("newContent").setFrom(0)
.setSize(10).execute().actionGet();
我还了解到,在 elasticsearch 2.x 版本中过滤查询已被贬值。有没有其他方法可以帮助我在执行查询之前应用过滤器?我可能遗漏了一些明显的东西。非常感谢您的帮助。
【问题讨论】:
标签: elasticsearch elasticsearch-java-api