Over 3000 of our SKUs contain special characters such as "-", "/", "&". The problem is when we try to search regular SKU (e.g. ABC123) on the front end it returns the correct result; however when we try to search the SKU having special characters (e.g. ABC-123), it returns multiple results, and sometimes the original SKU doesn't even appear on first 5 pages. How can we resolve this issue?

Thank you.

3 Answers 3


Add Below code in below file.


Add below line Number 86 replace condition

if ($matchKey != 'match_phrase_prefix') {
    $matchQuery['operator'] = "AND";



It seems that Elasticsearch treats the "-" character as word delimiter. You could tell Elasticsearch to ignore (strip) the "-" when indexing the SKU. The user can still enter the character, but Elasticsearch will treat it as being left out during the search process.

The Elasticsearch docs should give you guidance to configure a tokenizer to achieve this, e.g. check edge_ngram tokenizer https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html


Since I am not a coder, I did another trick searching for SKUs with special characters, the way this is achieved is to use the meta_keyword field to populate the SKU replacing special characters with spaces. For example, SKU "ABC-123" would have “ABC 123” in the meta_keyword field. When the user enters “ABC-123” in the search bar the proper SKU is the first item returned in the search results (if sorted by “Relevance”).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.