Of course. My goal is to seeing search results instantly so-called search-as-you-type.
I have been trying different approaches. Now I am using fuzzy query.
At first, it seems working, but then I realized it does not behave as accurate as I expected, which is to have matching results on top and then the rest.
For example, I got text Cafe... even though there are contents start with Cafe.
Is there any way to achieve this? Below you may find the mapping along with settings.
BTW, this won't be actual one as soon as I have found out what settings should be but I want to have an index like this so I kinda play with queries.
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20,
"token_chars": [
"letter",
"digit"
]
},
"gram_filter": {
"type": "ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit"
]
}
},
"tokenizer": {
"edge_ngram_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit"
]
},
"ngram_tokenizer": {
"type": "ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit"
]
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
},
"ngram_analyzer": {
"tokenizer": "ngram_tokenizer",
"filter": [
"lowercase"
]
},
"gram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"gram_filter"
]
},
"edge_ngram_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "edge_ngram_tokenizer"
},
"edge_ngram_search_analyzer": {
"tokenizer": "lowercase"
}
}
}
},
"mappings": {
"_doc": {
"_source": {
"enabled": true
},
"dynamic": false,
"properties": {
"name": {
"type": "text",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete"
},
"ngram": {
"type": "text",
"analyzer": "ngram_analyzer"
},
"gram": {
"type": "text",
"analyzer": "gram_analyzer"
},
"edge_ngram": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "edge_ngram_search_analyzer"
}
}
}
}
}
}
}