When using the ngram filter with elasticsearch so that when I search for something like \"test\" I return a document \"latest\", \"tests\" and \"test\". Is there a way to make i
You can copy the field content to fields via the mapping. Example:
"fullName": {
"type": "string",
"search_analyzer": "str_search_analyzer",
"index_analyzer": "str_index_analyzer",
"fields": {
"fullWord": { "type": "string" },
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
Note that str_index_analyzer uses nGram here. Then you can build your search to also search against these fields. Example:
{
"query": {
"bool": {
"should": [{
"multi_match": {
"fields": [
"firstName.fullWord",
...
"query": query,
"fuzziness": "0"
}
}],
"must": [{
"multi_match": {
"fields": [
"firstName",...],
"query": query,
"fuzziness": "AUTO"
}
}]
}
}
};
}