0
votes

I am using multi_match with phrase_prefix for full text search in Elasticsearch 5.5. ES query looks like

{
  query: {
    bool: {
      must: {
        multi_match: {
          query: "butt", 
          type: "phrase_prefix", 
          fields: ["item.name", "item.keywords"], 
          max_expansions: 10
        }
      }
    }
  }
}

I am getting following response

[
  {
    "_index": "items_index",
    "_type": "item",
    "_id": "2",
    "_score": 0.61426216,
    "_source": {
      "item": {
        "keywords": "amul butter, milk, butter milk, flavoured",
        "name": "Flavoured Butter"
       }
     }
   },
   {
     "_index": "items_index",
     "_type": "item",
     "_id": "1",
     "_score": 0.39063013,
     "_source": {
       "item": {
         "keywords": "amul butter, milk, butter milk",
         "name": "Butter Milk"
       }
     }
   }
 ]

Mappings is as follows(I am using default mappings)

 {
   "items_index" : {
     "mappings" : {
       "parent_doc": {
         ...
         "properties": {
           "item" : {
             "properties" : {
               "keywords" : {
                 "type" : "text",
                 "fields" : {
                   "keyword" : {
                     "type" : "keyword",
                     "ignore_above" : 256
                   }
                 }
               },
               "name" : {
                 "type" : "text",
                 "fields" : {
                   "keyword" : {
                     "type" : "keyword",
                     "ignore_above" : 256
                   }
                 }
               }
             }
           } 
         }
       }
     }
 } 

How item with "name": "Flavoured Butter" getting higher score of 0.61426216 against the document with "name": "Butter Milk" and score 0.39063013?

I tried applying boost to "item.name" and removing "item.keywords" form search fields getting same results.

How scores in Elasticsearch works? Are above results correct in terms of relavance?

1
could you give us the mapping of the index? because i'm getting a different scoring value of 0.37598053 for doc with "name": "Flavoured Butter" - Praneeth
@ChandraPraneethN I am using default mappings(added in question). Only thing is item is nested document inside its parent, But that should not make any difference. - Pramod Shinde

1 Answers

0
votes

The scoring for phrase_prefix is similar to that of best_fields, meaning that score of a document is the score obtained from the best_field, which here is item.keywords.

So, item.name isn't adding to score

Refer: multi-match-types

You can use 2 multi_match queries to combine the score from keywords and name.

{
   "query": {
      "bool": {
         "must": [{
            "multi_match": {
               "query": "butt",
               "type": "phrase_prefix",
               "fields": [
                  "item.keywords"
               ],
               "max_expansions": 10
            }
         },{
            "multi_match": {
               "query": "butt",
               "type": "phrase_prefix",
               "fields": [
                  "item.name"
               ],
               "max_expansions": 10
            }
         }]
      }
   }
}