0

I'm using ngram analyzer for indexing and standard analyzer for query.

currently i have indexed multiphone and iphone.

when i search for iphone the score and therefore relevancy of multiphone is higher than iphone.

how should i build query in order to get higher score for iphone?

the query that i execute is

"query": {
   "filtered": {
     "query": {
       "multi_match": {
         "query": "iphone",
           "fields": [
               "englishName",
               "aliasName"
            ]
        }
     },

what i need is that iphone score be higher than multiphone.

what about performance?

Amir Jalali
  • 3,132
  • 4
  • 33
  • 46

1 Answers1

0

I have answered similar question here

Basically you need to add raw version of the field to your mapping. You could use keyword analzyer with lowercase filter or you can make it "index" : "not_analyzed" or even use default standard analyzer.

Then you do a bool query and add a clause for the exact match and It will be scored higher.

EDIT : Example

You could map your englishName field as follow

englishName: {
    type: 'string',
    index_analyzer: 'ngram_analyzer',
    search_analyzer: 'standard',
    "fields": {
        "raw": {
            "type": "string",
            "index" : "not_analyzed" <--- here
        }
    }
}

You could do the same with aliasName Then your query would look something like this

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "iphone",
            "fields": [
              "englishName",
              "aliasName"
            ]
          }
        },
        {
          "multi_match": {
            "query": "iphone",
            "fields": [
              "englishName.raw",
              "aliasName.raw"
            ],
            "boost": 5
          }
        }
      ]
    }
  }
}

iphone will be scored higher with this query

Hope this helps.

Community
  • 1
  • 1
ChintanShah25
  • 12,366
  • 3
  • 43
  • 44