Should i replace the bool query with filter query?

i'm reading the es document,one chapter says filter will be cached and filter clause not be calculated in score.in my business scenario, i use es to search some eligible data then sorting them by date ,so i need't the score ,does query will be faster if i replace my bool query with filter query?

In ES 1.7 or lower yes. If you are on ES 2.0 and later you should place
your query in the filter clause of the bool query [1].
This will make sure that individual query elements wrapped in the bool
query's filter cache are cached. In your case you're sorting by date and
then ES will never compute score. However if you were sorting by score the
query elements wrapped in the bool query's filter clause will be omitted
from score computation.

1:
https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-bool-query.html#_scoring_with_literal_bool_filter_literal

thank you,i got it.
here is my java query example :
"
QueryBuilders
.boolQuery()
.filter(QueryBuilders.termQuery("status", 1))
.filter(QueryBuilders.termQuery("gender", 1))
"
does it right?

That looks all right.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.