Closed
Description
When you have a / in the suggest query, it fails with the following exception:
"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[index][0]: SearchParseException[[index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"filtered\":{\"query\":{\"bool\":{\"must\":[{\"function_score\":{\"query\":{\"bool\":{\"must\":[{\"multi_match\":{\"query\":\"pants\\/\",\"type\":\"best_fields\",\"minimum_should_match\":\"100%\",\"fields\":[\"autocomplete_nl.edge_ngram_front\"],\"fuzziness\":\"0.5\",\"prefix_length\":\"1\",\"max_expansions\":\"20\",\"analyzer\":\"whitespace\"}}],\"should\":[{\"multi_match\":{\"query\":\"pants\\/\",\"type\":\"best_fields\",\"tie_breaker\":1,\"fields\":[\"autocomplete_nl.edge_ngram_front\"],\"analyzer\":\"analyzer_nl\"}}]}},\"functions\":[{\"filter\":{\"query\":{\"query_string\":{\"query\":\"pants\\/\",\"default_field\":\"autocomplete_nl.whitespace\"}}},\"boost_factor\":10}]}}]}},\"filter\":{\"bool\":{\"must\":[{\"terms\":{\"visibility\":[3,4]}},{\"terms\":{\"status\":[1]}},{\"terms\":{\"in_stock\":[1]}},{\"terms\":{\"store_id\":[1]}}],\"_cache\":true}}}},\"fields\":[\"entity_id\"],\"track_scores\":true,\"sort\":[{\"_score\":\"desc\"}],\"from\":0,\"size\":\"3\"}]]]; nested: QueryParsingException[[index] Failed to parse query [pants/]]; nested: ParseException[Cannot parse 'pants/': Lexical error at line 1, column 7. Encountered: <EOF> after : \"\"]; nested: TokenMgrError[Lexical error at line 1, column 7. Encountered: <EOF> after : \"\"]; }]","status":400}
The error lead me to this issue in the elasticsearch repo: elastic/elasticsearch#2980
Escaping the query seems the most logical solution to this, however I don't know this module that well. I tested with escaping the query when it's set in Smile_ElasticSearch_Model_Resource_Engine_Elasticsearch_Query_Abstract::setFulltextQuery($query)
which worked well for me.
For some reason this exception doesn't occur when I search on the same query.
If you agree with this, I can make a PR.