Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elastic search array score

I have a document has an array like

doc1

{
"item_type":"bag",
"color":["red","blue","green","orange"]
}

doc2

{
"item_type":"shirt",
"color":["red"]
}

when I do a multi_match search like

{ "query": { "multi_match": { "query": "red bag", "type": "cross_fields", "fields": ["item_type","color"] } } }

The doc2 has much higher score, I understand color filed has less items get higher score and it get worse if I have more colors in doc1.

So is there a way I can ask Elasticsearch to score the same for an array field no matter how many items are there?

like image 951
Rene Xu Avatar asked May 20 '15 10:05

Rene Xu


People also ask

How does Elastic Search calculate score?

The default scoring algorithm used by Elasticsearch is BM25. There are three main factors that determine a document's score: Term frequency (TF) — The more times that a search term appears in the field we are searching in a document, the more relevant that document is.

How do I map an array in Elasticsearch?

Elasticsearch does not have an array data type because any field may contain zero or more values by default. Indeed we can index an array of values without defining this within the field's mapping. Please remember that all values within an array must be of the same data type or at least coercion needs to be possible.

What is Max score in Elasticsearch?

Once upon a time... The idea is quite simple: say that you want to collect the top 10 matches, that the maximum score for the term "elasticsearch" is 3.0 and the maximum score for the term "kibana" is 5.0.

How do I change my Elasticsearch score?

According to your comment, you need the _score to be multiplied by the document's score field. You can achieve it simply by removing the boost_mode parameter, the default boost_mode is to multiply the _score with whatever value comes out of the field_value_factor function.


1 Answers

If you do not want to account for field length (fieldNorm) during the scoring you could disable norms for a field in the mapping.

For example the mapping for the above example would be

   {
   "properties": {
      "item_type": {
         "type": "string"
      },
      "color": {
         "type": "string",
         "norms": {
            "enabled": false
         }
      }
   }
}

This article from elasticsearch definitive guide gives a good insight into field-length-norms.

like image 142
keety Avatar answered Oct 07 '22 06:10

keety