Rene Xu
Rene Xu

Reputation: 1103

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?

Upvotes: 7

Views: 1628

Answers (1)

keety
keety

Reputation: 17461

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.

Upvotes: 4

Related Questions