Irrelevant result set


(Pranesh) #1

I am getting irrelevant search results in ES. May be my query is wrong or may be issue with my mappings.
Can some one help me to find the issue.

Mapping:
PUT /test
{  
   "mappings":{  
      "test":{  
         "properties":{  
            "customerId":{  
               "type":"string",
               "analyzer":"index_ngram",
               "search_analyzer":"search_ngram",
               "fields": {
                   "customerIdRaw":{
                       "type": "string", 
                       "index": "not_analyzed"
                   }
               }
            }
         }
      }
   },
   "settings":{  
      "analysis":{  
         "filter":{  
            "desc_ngram":{  
               "type":"ngram",
               "min_gram":8,
               "max_gram":20
            }
         },
         "analyzer":{  
            "index_ngram":{  
               "type":"custom",
               "tokenizer":"keyword",
               "filter":[  
                   "lowercase",
                   "desc_ngram"
               ]
            },
            "search_ngram":{  
               "type":"custom",
               "tokenizer":"keyword",
               "filter":["lowercase"]
            }
         }
      }
   }
}

JSON:

PUT test/test/1?pretty
{
  "customerId": "TESTING456",
  "phoneNo":"xxxxxx"
}

PUT test/test/2?pretty
{
  "customerId": "123",
  "phoneNo":"xxxxx"
}

Search Query:

POST /test/_search
"query": {"match": {
       "customerId": "123"
    }
    
Result:

{
   "took": 9,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 1,
      "hits": [
         {
            "_index": "test",
            "_type": "test",
            "_id": "2",
            "_score": 1,
            "_source": {
               "customerId": "123",
               "phoneNo": "xxxxxx"
            }
         },
         {
            "_index": "test",
            "_type": "test",
            "_id": "1",
            "_score": 1,
            "_source": {
               "customerId": "TESTING456",
               "phoneNo": "xxxxxx"
            }
         }
      ]
   }
}

Expected result is only one but it is returning all.


(system) #2