How to give higher score to exact searches than phonetic ones in Elasticsearch?

I am currenty using Elasticsearch's phonetic analyzer. I want the query to give higher score to exact matches then phonetic ones. Here is the query I am using:

{
    "query": {
        "multi_match" : {
            "query" : "Abhijeet",
            "fields" : ["content", "title"]




        }
    },         
     "size": 10,
     "_source": [ "title", "bench", "court", "id_" ],
     "highlight": {
        "fields" : {
            "title" : {},
            "content":{}
        }
    }

}


When I search for Abhijeet , the top queries are Abhijit and only later does Abhijeet come. I want the exact matches to appear first, all the time and then the phonetic ones. Can this be done?

You don't have to settle on one indexing strategy or querying strategy:

  • Index your field multiple ways in the mapping using multi-fields
  • Query your data using a bool query containing an array of should clauses - some targeting the phonetic field, others the field used for exact-matching. The bool query will take care of scoring docs that match both clauses highest.
1 Like

H @Mark_Harwood !
So for example I have the content field that contans the phonetic analyzer. Now when I search in the field I want the exact matches to come first, then the phonetic matches. I am just beginning out and if it isn't much trouble to you, a code example showing this will be really helpful.

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