I have an issue with the mapping analyzer to the field.
My priority is based on search (i want to autocomplete search based on the given text) 1 must match from the left side (1 priority), 2 any word in the given text (2 priority), 3 any character like the combination in the given text (3 priority)
**1. I created field mapping with the custom analyzer.**
`
"properties" => [
"name" => [
"type" => "search_as_you_type",
"analyzer" => "my_tokenizer",
],
];
`
**2. created a custom analyzer**
{
"settings": {
"analysis": {
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 10,
"token_chars": ["letter", "digit", "symbol"]
}
},
"analyzer": {
"my_analyzer":{
"tokenizer": "my_tokenizer"
}
}
}
}
}
**3. Search query**
'query' => [
'query_string' => [
'default_field' => "name",
'query' => "test",
'default_operator' => "AND",
],
],
**The result I am getting:**
TEST
ABC TEST
NAKT TZY TEST
TEST POST
TEST VN
**What I want :**
TEST
TEST VN
TEST POST
ABC TEST
NAKT TZY TEST
I don't understand why you use an analyzer for a search_as_you_type field that you want to use as an autocomplete. The search_as_you_type already creates the subfields with ngram.
I mapped like this:
And the query below ran as you want.
See more: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html