I'm trying to create a search with suggestions in my website with Elasticsearch. I have a "title" field that has set the mappings this way.
"mappings" : {
"products" : {
"properties" : {
"title": {
"type" : "completion",
"analyzer": "simple",
"search_analyzer": "standard"
}
}
}
}
And this is the search query I'm going to use.
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": [ "title^2", "description"],
"query": "cuboard",
"fuzziness": "AUTO"
}
}]
}
}
When I run this it returns an error. I use analyzer for get suggestions & it works well. Can't I use fuzziness in analyzed fields in Elasticsearch for searches?
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"bool\" : {\n \"must\" : [\n {\n \"multi_match\" : {\n \"query\" : \"cuboard\",\n \"fields\" : [\n \"discrip^1.0\",\n \"title^2.0\"\n ],\n \"type\" : \"best_fields\",\n \"operator\" : \"OR\",\n \"slop\" : 0,\n \"fuzziness\" : \"AUTO\",\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"fuzzy_transpositions\" : true,\n \"boost\" : 1.0\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}",
"index_uuid": "VIpm20b0Rra0PI1fyKCsKQ",
"index": "offers"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "products",
"node": "gTaPvDb2QXyR3VdK0gX3qg",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"bool\" : {\n \"must\" : [\n {\n \"multi_match\" : {\n \"query\" : \"cuboard\",\n \"fields\" : [\n \"discrip^1.0\",\n \"title^2.0\"\n ],\n \"type\" : \"best_fields\",\n \"operator\" : \"OR\",\n \"slop\" : 0,\n \"fuzziness\" : \"AUTO\",\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"fuzzy_transpositions\" : true,\n \"boost\" : 1.0\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}",
"index_uuid": "VIpm20b0Rra0PI1fyKCsKQ",
"index": "offers",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Can only use fuzzy queries on keyword and text fields - not on [title] which is of type [completion]"
}
}
}
]
},
"status": 400
}