hello
reviewing the elasting eng I material
I came across the topic "nest bool query (Slide 170)" ...
Why does this example influence max_score (is higher) but not the hits total?
Is there a simple explantation?
hello
reviewing the elasting eng I material
I came across the topic "nest bool query (Slide 170)" ...
Why does this example influence max_score (is higher) but not the hits total?
Is there a simple explantation?
Adding a should
clause to a bool
query that contains a must
clause does not change the number of hits, only the scoring.
For example, the following match
query searches for blogs that mention "logstash" in the content
field. Suppose you get 140 hits:
GET blogs/_search
{
"query": {
"match": {
"content": "logstash"
}
}
}
Now let's add a should
clause, so that blogs with "logstash" in the title
field of the blog score higher (we are still requiring the "logstash" is in the content
field):
GET blogs/_search
{
"query": {
"bool": {
"must": {
"match": {
"content": "logstash"
}
},
"should": {
"match": {
"title": "logstash"
}
}
}
}
}
The should
clause does not add any hits to the results. Think about the English word "should" - it is not a requirement that "logstash" be in the title, rather it is something that we would prefer to have in our hits.
So in the bool
query above, you would still get 140 hits. But if a blog has "logstash" in the title
also, then the score from that should
clause is added to the score from the must
clause. In this example above, the max_score would be considerably higher for blogs that have "logstash" in the title. If a blog does not have "logstash" in the title, then its score from the bool
query will be the same as if you ran the match
query without a should
clause.
Hi nsam,
it is because the match_phrase is inside a should clause. Any clause inside the must
must happen. Any clause inside the should
should happen. In other words, any clause inside a should will not discard results, but will impact the score of the documents that match the should
. Not sure that is clear, but hopefully you could understand.
Cheers
both explanation help me to undesrstand ...
so to sum up, the should clause boost the _score and don't influence total count.
thank you
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
© 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.