I have faced the problem in using Magento2 with search result commonly search based on SKU but I want to search product using the name of the product so I want to change the search query in Magento2 but I am not found any option in admin section and code file so can anybody help me to change search query.

2 Answers 2


For that, i suggest you to override the core catalog_search and search module first and then you can get solution inside the model folder.

Check this 2 files: vendor/magento/module-catalog-search/Model/Layer/Search/Plugin/CollectionFilter.php afterFilter(){}

vendor/magento/module-search/Model/Query.php getSuggestCollection(){}

Hope this can be helpful.


  • I will try this solution and get back to you with my comments. Thanks for your valuable information. Feb 18, 2020 at 6:31
  • Feel free to ask anything if you need. :) Feb 20, 2020 at 6:41

you have to set AND operator in your elastic search json queries, Override the module-elasticsearch/SearchAdapter/Query/Builder/Match.php. file in your custom module and then The code you have to edit in the build function in line no 75

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

Also make sure you are not setting the operator in match_phrase_prefix.

After this you'll get exact matches in catalog search.

This has been tested well for magento CC 2.4.0

  • This is not working with M2.4.1 & M2.4.2
    – Yogita
    Aug 18, 2021 at 5:50

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.