Increase score for unique words matched

This one is a little tricky to explain, but here goes.

I have an index with mappings that look like this:

{
   "mappings":{ 
      "properties":{ 
         "manufacturer":{ 
            "type":"text",
            "analyzer":"standard"
         },
         "product":{ 
            "type":"text",
            "analyzer":"standard"
         }
      }
   }
}

And I have some documents that look like this:

[ 
   { 
      "manufacturer":"foo bar",
      "product":"baz by foo bar"
   },
   { 
      "manufacturer":"foo bar",
      "product:":"something something something qux"
   }
]

Lastly, I have a query that looks like this:

{
   "query":{
      "bool":{
         "should":[
            {
               "match":{
                  "manufacturer":{
                     "query":"foo qux"
                  }
               }
            },
            {
               "match":{
                  "product":{
                     "query":"foo qux"
                  }
               }
            }
         ]
      }
   }
}

Running the query, the document with baz by foo bar ranks higher than something something something qux. I suspect the reason is because foo matches both fields in the first document (and closer to the start of each field) where qux matches one document, and farther towards the end of the field than foo does. I'm guessing a bit there.

What I want to do is have something something something qux rank higher, since it matches both tokens in the query (foo and qux) and not just one of the terms twice.

Thanks in advance.

If you do not understand why some scoring happens, you can always use "explain": true in your request to get some enlightenment. See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-explain and the explain API

that said I suppose you would need to change a query quite a bit in order to make this work, as foo is matched in both fields, compared to qux. Not really sure if the multi_match is of any help here, but you may want to read about the different type options available.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.