74 votes
Accepted

What are the allowed condition types in Magento 2?

available conditions "eq" => equalValue "neq" => notEqualValue "like" => likeValue "nlike" => notLikeValue "is" => isValue "...
Bilal Usean's user avatar
  • 9,977
45 votes
Accepted

Magento2: How to add multiple AND and OR conditions to filter/filterGroups?

Yes it is possible You can create an \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder \Magento\Framework\Api\FilterBuilder $filterBuilder \Magento\Framework\Api\Search\...
Mohamed El Mrabet's user avatar
8 votes

how to use Search rest api in magento 2?

Try: http://localhost/magento2/index.php/rest/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filterGroups][0][filters][0][field]=search_term&searchCriteria[...
Olubajo Bolaji's user avatar
8 votes
Accepted

Filtered response does not show total records in response of REST APIs in Magento 2

Ok I found the solution, I checked some core files of catalog module and I can see that search criteria and total records are not in items index so I just need to update my request like below. http:/...
Ramkishan Suthar's user avatar
7 votes
Accepted

Customer Repository Interface, Limit Results

Figured it out. http://devdocs.magento.com/guides/v2.2/extension-dev-guide/searching-with-repositories.html $searchCriteria = $this->searchCriteria ->setFilterGroups([$...
Ethan Yehuda's user avatar
7 votes
Accepted

Magento2: Collection to SearchCriteria

I'm not test yet but it should work public function __construct( ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder, ...
mrtuvn's user avatar
  • 3,273
6 votes
Accepted

Magento 2: difference between Api\SearchCriteriaBuilder and Api\Search\SearchCriteriaBuilder?

They build different objects: Magento\Framework\Api\SearchCriteria Magento\Framework\Api\Search\SearchCriteria (which extends the former) The Search/SearchCriteria has two additional methods: /** *...
Fabian Schmengler's user avatar
4 votes
Accepted

Use preconfigured builders (e.g. for SearchCriteria) in Magento 2

I love the ideas you present. Immutability doesn't go well with builders, having state is part of their job. So how about this, which is very close to what you suggest anyway, if I understand you ...
Vinai's user avatar
  • 14k
4 votes

Filtered response does not show total records in response of REST APIs in Magento 2

You need to select total count too to fetch it. Add total_count at the end of your request like this: REQUEST,total_count
Kamal Paliwal's user avatar
3 votes

Magento2: How to add multiple AND and OR conditions to filter/filterGroups?

Magento applies the OR operator within the filters in the filter group, while the AND operator for joining the filter groups. This makes conditions like (A and B) or (C and D) tricky to implement. ...
Peter Karsai's user avatar
3 votes
Accepted

How can we return an array of search results in APIs Magento 2

I just fixed this. Need to create one more interface for this. CategoryArrayItemInterface <?php namespace Vendor\CustomAPIs\Api\Data; /** * Interface which represents associative array item. */...
Ramkishan Suthar's user avatar
3 votes

Magento 2 API: Filter orders by extension attribute

Firstly, your query string contains commas (,) when it should contain ampersands (&): /rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=warehouse&searchCriteria[filter_groups]...
Agnes's user avatar
  • 787
3 votes

SearchCriteria with 'OR' filter

You can try with, $title = $this->filterBuilder->setField('title') ->setValue('%keyword%') ->setConditionType('like') ->create(); $content = $this-&...
Rakesh Jesadiya's user avatar
3 votes

Search criteria builder does not filter an "out_of_stock" products

It's because stock status was added when product collection is loading. You can see how it works as the following \Magento\Catalog\Model\ProductRepository::getList() ... $collection->...
bachlee89's user avatar
  • 1,287
3 votes
Accepted

Difference between SearchCriteria VS SearchResults Vs SearchCriteriaBuilder and when should we use it?

As per my understanding, I will give an explanation about SearchCriteria, Search result, searchCriteriaBuilder in below. Search Criteria: A Search Criteria is an implementation of the ...
Chirag Patel's user avatar
  • 6,126
3 votes
Accepted

How to print searchCriteriaBuilder query in Magento 2?

Inside of the ProductRepositoryInterface inside of the getList method, you'd do $collection->getSelectSql(true) at some point after the collection is actually loaded. When Magento builds a product ...
Shawn Abramson's user avatar
2 votes

Using searchCriteria with condition_type operators "from" and "to" in Magento 2.0

Here is how to do it, you can to modify your request in two different ways in my opinion: Using less than and greather than http://{magento_host}/magento/rest/default/V1/orders? searchCriteria[...
Raphael at Digital Pianism's user avatar
2 votes

Magento 2: Product Repositories, Filter Groups, and `AND`

In Magento 2 all the filters in same FilterGroup will be added using OR operator. But all the FilterGroup will be added using AND operator. So you will need to add multiple FilterGroups as below: $...
Kamal Singh's user avatar
2 votes
Accepted

Magento2: setFilterGroups(array) SearchCriteria Error

There is no method setFilterGroups in the class Magento\Framework\Api\Search\SearchCriteriaBuilder Not sure if this will work but you can try to remove the line that contains setFilterGroups and ...
Marius's user avatar
  • 198k
2 votes

Magento 2 API: Filter orders by extension attribute

The searchCriteria does not filter results from API response instead from the db/collection instead, if custom attributes in extension_attribute are not available in the db as a column in the table ...
Vivek Kumar's user avatar
  • 5,385
2 votes

CatalogSearch results looking for partial SKU

By default magento doesn't use wildcards (*123.5N*) with ES. Query building logic implemented in class Magento\Elasticsearch\SearchAdapter\Query\Builder\Query (need change query type to query_string).
Alex's user avatar
  • 398
2 votes

How to filter Multiselect in Magento 2 search Rest API?

Your are using wrong filter for Search using REST endpoints condition_type type should be &searchCriteria[filterGroups][1][filters][0][conditionType]=in it gives the result of 0 record. So Used ...
HAROONMIND's user avatar
1 vote

Magento2: SearchCriteria OR/AND

I had to use $searchCriteria->setFilterGroups([$filterGroup]);
Miguel's user avatar
  • 569
1 vote

Magento2: SearchCriteria OR/AND

For OR condition check following code. DI public function __construct( \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Framework\Api\SearchCriteriaBuilder $...
Sohel Rana's user avatar
  • 35.8k
1 vote
Accepted

SearchCriteria Logical OR and AND search

https://en.wikipedia.org/wiki/Distributive_property Distribution of disjunction over conjunction P or (Q and R) <-> (P or Q) and (P or R) So, you can transform you criteria to WHERE (a = 1 OR ...
Max's user avatar
  • 4,054
1 vote

Magento 2 Search Rest API

For get the product information in the Search API you have to use searchCriteria with filters in request URL. Use below API Request URL. Request URL: http://localhost/magentosample230/rest/V1/...
Kirti Nariya's user avatar
  • 3,471
1 vote

What are the allowed condition types in Magento 2?

You can try this one as well from the document https://devdocs.magento.com/guides/v2.3/rest/performing-searches.html
Raviraj's user avatar
  • 49
1 vote

Search Criteria for the products in magento 2

As your custom attribute 'smart_search' is a multiselect attribute, on the creation of the search criteria the value that you have to pass is the option value and not the option label like blue color. ...
Nikolas's user avatar
  • 2,281
1 vote

Magento 2 API: Filter orders by extension attribute

At the moment of writing this (Magento 2.2), I don't think there's a way to filter on extension attributes. Although they're present in the underlying collection's select if you define a <join> ...
Mark van der Sanden's user avatar
1 vote

Assign Multiple Filter to Single FilterGroup in magento 2

Yes, I find out the \Magento\Framework\Api\Search\FilterGroupBuilder have setFilters function to give array of multiple filters. so, i change my code foreach($filter as $fil) { $this-...
Rajkumar .E's user avatar
  • 3,570

Only top scored, non community-wiki answers of a minimum length are eligible