If I have a simple query like:
termQuery("name", "Brian")
What is the suggested method of getting that query into filter context in Elasticsearch 2.0?
Wrapping it in a boolQuery?
boolQuery().filter(termQuery("name", "Brian"))
If I have a simple query like:
termQuery("name", "Brian")
What is the suggested method of getting that query into filter context in Elasticsearch 2.0?
Wrapping it in a boolQuery?
boolQuery().filter(termQuery("name", "Brian"))
Yep!
(Assuming you want to run it as a filter e.g. no scoring)
Great thanks.
Does a top level boolQuery().filter(someBigCompoundQuery)
put all of the subqueries into filter context or do I need to put the sub-queries into filter context as well?
Hmm, I'm not sure I understand?
If you add queries to the must
/ must_not
/ should
clauses of a bool, they will be executed as queries. If you add them to the filter
, they turn into a filtering, non-scoring context.
If I have something like
boolQuery().filter(boolQuery().must(termQuery("fname", "Brian"))
.must(termQuery("lname", "Hudson"));
Are the term queries now in filter context and thus individually eligible for caching?
Ah, I see. Yes, you are correct. When you place those queries in a filter context, they will execute as a filter with no scoring, caching, etc.
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.