Relevant data not coming in elasticsearch

Hi,
I am building a search with edge ngram.

Here is my mapping:

PUT xyz
{
"settings": {
    "analysis": {
      "filter": {
		"autocomplete": {
          "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 15,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      },
      "analyzer": {
		"autocomplete_search": {
          "tokenizer": "standard",
		  "type": "custom",
          "filter": [ "autocomplete","lowercase" ]
        }
      }
    }
  },

    "mappings" : {
      "properties" : {
        "codevalue" : {
          "type" : "text",
		  "analyzer": "autocomplete_search"
        }
      }
    }
}

My search query is

GET xyz/_search
{ "_source": "codevalue", 
  "query":{
    "match": {
      "codevalue": {
        "query": "CP 12"
        
      } 
      
    }
  }
}

Result is:

{"codevalue" : "CP 12"},
{"codevalue" : "DP 12"},
{"codevalue" : "CP 11315 : Part 12"},
{"codevalue" : "CP 11777 : Part 12"},
{"codevalue" : "CP 13557 : Part 12"},
{"codevalue" : "CP 228 : Part 12"},
{"codevalue" : "CP 3025 : Part 12"},
{"codevalue" : "CP 5347 : Part 12"},
{"codevalue" : "CP 13109 : Part 12"},
{"codevalue" : "CP 3842 : Part 12"}

I want to get like

"codevalue": "CP 12"
"codevalue": "CP 125"
"codevalue": "CP 12...."
......continued

Thanks

You are using the standard analyzer which breaks into tokens on white space. Any term that starts with CP or 12 will therefore match. I would recommend using the analyze API to see exactly what is indexed.

1 Like

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