How do I change magento 2 minisearch logic from OR to AND? Right now if I search for 'Shoe laces', it returns all products with terms either 'shoe' or 'laces'. I need fulltext search, so that only product with full term 'Shoe laces' are returned. How do I achieve this?


I found the solution , create a file search_request.xml in your module's etc folder ,

copy the entire node from vendor/Magento/CatalogSearch/etc/search_request.xml

and change

<queryReference clause="should" ref="search" />

to this

<queryReference clause="must" ref="search" />

do not forget to add sequence in your module file.

in case you installed your module and added after that, just change your module version and run setup:upgrade again , thanks

  • Please read your answer after posting it. The code samples haven't been visible. I changed that now. – Andreas von Studnitz Jun 21 '18 at 14:17
  • Please check this link eddiemay.me.uk/2019/06/20/magento-2-and-or-search-operators – lavb Feb 20 '20 at 17:26
  • Hi, I followed this and now the search synonyms are not working. If I add synonyms: read,rid then searching read or rid comes up with no result. Please help.! – ishu Feb 25 '20 at 6:29

those settings will not work.

make it like below:


$conditions[] = [ 'condition' => $queryValue['condition'], 'body' => [ $condition => [ $resolvedField => [ 'query' => $value, 'boost' => isset($match['boost']) ? $match['boost'] : 1, 'operator' => 'and', ], ], ], ];

this will give you exact results.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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