I would like to search a document in two fields : name + words.
I want to boost the score if the word searched is in the field name.
I search the word "google".
As you can see, the second result has a better score than the third.
But the third should be the second because it has the word "google" in the field name.
Could you explain me why the boost doesn't work please ?
I can't answer without knowing how you indexed the documents. When I indexed 3 documents with the same fields that you showed, and then executed the bool query that you have, I got google 1 first, then google 2, then the other document, so the scoring was as you would expect.
But I would be cautious in reading too much into scoring with such few documents. First, depending on what scoring you are using (probably TF/IDF which is the default), the number of words in the matching fields matter - the more terms in the field, the less weight any one term in the field has. Second, scoring actually occurs on a per shard basis, so the score is actually computed on the shard in which the document exists. Since you only have 3 documents, if you have 5 shards, each of those documents probably exists on its own shard, in which case the scoring doesn't have as much relevance in relation to each other. This scoring tends to even out when there are many documents on each shard, but when there are so few documents on each shard, scoring may not be what you'd expect.
And if you want to get the details of how scoring is done, you can run the search with the explain option:
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.