2

I want perform fuzzy search on user search words(apple iphone 5s). I want to give more score value to first(apple), little less for second and so on.

I started with the query given below but not working as I expected:

{
  "query": {
    "fuzzy_like_this_field": {
      "name": {
        "like_text": "appla^4 iphane^2 5^1",
        "max_query_terms": 12
      }
    }
  },
  "fields": "name",
  "sort": {
    "_score": {
      "order": "desc"
    }
  }
}

May I know how to write this query??

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Mahesh
  • 1,651
  • 5
  • 26
  • 47

1 Answers1

1

I found the answer.

{ 
   "query" : { 
      "bool" : { 
         "should" : [ 
            { 
               "fuzzy" : { 
                  "name" : { 
                     "min_similarity" : 0.5, 
                     "boost" : 4, 
                     "value" : "appla", 
                     "prefix_length" : 0 
                  } 
               } 
            }, 
            { 
               "fuzzy" : { 
                  "name" : { 
                     "min_similarity" : 0.1, 
                     "boost" : 2, 
                     "value" : "iphane", 
                     "prefix_length" : 1 
                  } 
               } 
            } , 
            { 
               "fuzzy" : { 
                  "name" : { 
                     "min_similarity" : 0.1, 
                     "boost" : 1, 
                     "value" : "5", 
                     "prefix_length" : 1 
                  } 
               } 
            }
         ] 
      } 
   } 
} 
Mahesh
  • 1,651
  • 5
  • 26
  • 47
  • Have you spelt the values incorrectly on purpose? Iphane, appla? As in, is that significant to the answer and searching? – Luke May 12 '21 at 21:37