Hello community,
I am using ES on my local machine with version of 8.10.4
I was experimenting with search-as-you-type lately and I am confused by "._2gram" and "._3gram" fields. I created a basic index as
PUT autosuggest_trial_2
{
"mappings": {
"properties": {
"description": {
"type": "search_as_you_type",
"analyzer": "my_custom_analyzer"
}
}
},
"settings": {
"analysis": {
"filter": {
"my_ascii_folding": {
"type": "asciifolding"
}
},
"analyzer": {
"my_custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "my_ascii_folding", "trim"]
}
}
}
}
}
Then I built a search query as:
GET autosuggest_trial_2/_search
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "for men shoe",
"fields": [
"description",
"description._2gram",
"description._3gram"
],
"type": "bool_prefix",
"operator": "AND"
}
}
}
}
}
The results are exactly what I wanted to see. However, when I remove "description._2gram"
and "description._3gram"
from fields in search query, the results are same. So, I am confused about why I give these fields. Also, some examples added "._index_prefix"
as well.
When I add "profile": true
to my search query, I can see that search query uses "description._2gram"
and that's a relief. Maybe elasticsearch adds these fields automatically?
Is there an explanation as to why? Thanks.