I tried two different approaches for creating index and both are returning anything if I search for part o the word. Basically, if I search for first letters or letters in the m
In my this SO answer, the requirement was kinda prefixed search, ie for text Demetrio1
only searching for de
demet
required, which worked as I created edge-ngram tokenizer to address this, but in this question, requirement is to provide the infix search for which we will use the ngram tokenizer in our custom analyzer.
Below is the step by step example
Index def
{
"settings": {
"index.max_ngram_diff" :10,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram", --> note this
"min_gram": 2,
"max_gram": 8
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
Index sample doc
{
"title" : "Demetrio1"
}
Search query
{
"query" :{
"match" :{
"title" :"met"
}
}
}
search result bring the sample doc:)
"hits": [
{
"_index": "ngram",
"_type": "_doc",
"_id": "1",
"_score": 0.47766083,
"_source": {
"title": "Demetrio1"
}
}
]