Ann Ann - 1 month ago 12
PHP Question

Elastic search - text search not working

I need to search a text content with special characters for multiple fields.
eg: name_text contains - "Hello , How are you ? "

if i search the word "how","are" i got the result but incase of "thow" i am not getting the result.

for searching used

{"simple_query_string": {
"query": "thow",
"flags" : "OR|AND|PREFIX",
"analyzer": "snowball",
"fields": [ "name_text", "address_text" ]
}


I have used nGram and here is my code

"settings":{ "index": {
"analysis": {
"analyzer": {
"autocomplete_term": {
"tokenizer": "autocomplete_edge",
"filter": [
"lowercase"
]
},

"autocomplete_search": {
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
},
"tokenizer": {
"autocomplete_edge": {
"type": "nGram",
"min_gram": 1,
"max_gram": 100
}
}
}
}


and mapping

"name_text": {
"type": "string",
"analyzer": "autocomplete_term"
"search_analyzer": "autocomplete_search"
},
"address_text": {
"type": "string",
"analyzer": "autocomplete_term"
"search_analyzer": "autocomplete_search"
}


Is there anything wrong in my code. Please help me

Answer

You need fuzzy search for that to match:

"simple_query_string": {
  "query": "thow~1",
  "flags": "OR|AND|PREFIX|FUZZY",
  "analyzer": "snowball",
  "fields": [
    "name_text",
    "address_text"
  ]
}