Now, i have more filter. Only search to document with field published=1.
And the filter that i plan to used to accomplished that is by using post_filter, unfortunately as far as i know, post_filter is not accept array object.
You can just add a bool query inside post_filter and inside the bool query add your geo_distance and a term (for published=1) as filter clause.
I do wonder why you use post_filter. It only makes sense in combination with aggregations, in order to show counts where certain filter are not applied. If you don't need to do that, then I recommend you to place your filters in the filter clause of the bool query that you already have defined as your main query. This way the query will execute much more efficiently.
Hi! Thanks for the reply. I will try it, and grt back with the result.
I use post_filter here to get document matched with keyword, which still in 20km in radius.
I'have try it (use query filter instead post_filter). If i put the geo filter on query filter clause, then i will get "not matched" with keyword document in less relevant result, right? Which we just want to result only matched keyword document.
CMIIW, anyway let me know if there is better approach for my search criteria.
Queries inside bool query's filter clause don't contribute to the score, so they don't make a document more relevant. A filter clause either does or doesn't match and a document need to match with all filter clauses otherwise it is not a hit. That behaviour is similar to what you have experienced when placing a query inside the post_filter.
Thanks for sharing that. The difference in hit count is unexpected to me. I think somehow the term query (for published=1) gets parsed differently in the two search requests.
Can you execute both queries in the validate query API (/_validate/query?explain=true&rewrite=true)?
Also I like to know whether the results are still the same if the match query is used instead of the term query for published=1.
_validate endpoint doesn't support post_filter, sort, from and size it's give a and error. that's why i cannot share the output with post_filter query.
A bool query with only should clauses automatically sets minimum_should_match to 1 if it has not been specified. A bool query with should clauses and required clauses (filter or must), the minimum_should_match is set to 0 if it has not been specified. The idea behind this is that if there are only should clauses, at one should clause must match (otherwise all documents would match). If there are required clauses then should clauses are optional by default. I had forgotten this detail
Yes, Elasticsearch is then able in many cases to execute the search request more efficiently, so if you can place queries in the bool query's filter clause then you should do that.
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.