Questions tagged [search-criteria]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
29 votes
2 answers
38k views

Filtering a Magento 2 Object Repository

In Magento 2, can you use a product repository to filter by product attributes? In Magento 2, you can use a search criteria object \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria, ...
Alana Storm's user avatar
  • 44.3k
25 votes
2 answers
30k views

What are the allowed condition types in Magento 2?

What is the list of allowed condition types while adding filter to search criteria in Magento 2? All of the examples about search criteria in the internet use eq condition type. Is there any other? ...
Bunyamin Inan's user avatar
14 votes
2 answers
15k views

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

I'm trying to use a product repository to fetch a list of products. I want to fetch based on two filters, combined with an AND criteria, but things don't seem to be working. Do I not understand how ...
Alana Storm's user avatar
  • 44.3k
11 votes
3 answers
23k views

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

The question is too close to this topic: Magento 2: Product Repositories, Filter Groups, and `AND` but is it possible to create criteria with multiple OR and AND? In my case i would like to create ...
Anthony's user avatar
  • 784
10 votes
5 answers
6k views

Magento 2 API: Filter orders by extension attribute

I have an extension with an attribute assigned to order items called warehouse. I can see this attribute under the property "extension_attributes". I need to filter orders based on this attribute. I ...
Jim's user avatar
  • 101
7 votes
2 answers
9k views

Using searchCriteria while searching attributes in magento 2.0

Fetching attribute info, if I apply multiple filters in a single search criteria, it does not work. But in case of single filter it works perfectly. Multiple filters HTTP request: http://192.168.1....
nr5's user avatar
  • 460
7 votes
1 answer
2k views

Magento 2: How to change Advanced Search from "AND" to "OR"?

I'm stuck with this situation: I have 2 select-type attributes: A and B for example In both of the attributes, I have the same list of Options (but they are different option ids) For example In ...
linharex's user avatar
6 votes
1 answer
5k views

Magento 2 rest api - get orders with products' custom attributes

I would like to have the proper cURL command for getting all pending orders with the products' custom attributes in Magento 2 REST API. I use this, but there are no custom attributes on the products ...
chrispooh's user avatar
6 votes
1 answer
2k views

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

For searching in repositories we are using searchCriteriaInterface but i noticed sometimes we are using SearchCriteriaBuilder as well. In which case we should use searchCriteriaBuilder? What's the ...
Jackson Wyss's user avatar
5 votes
2 answers
3k views

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

Warning, this is a long winded question about module architecture. I'm not mad if it gets closed as opinion based, but I hope someone has a better idea than me. In Magento 2 we have builders like the ...
Fabian Schmengler's user avatar
5 votes
1 answer
3k views

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

I'm trying to use the Get Orders API with searchCriteria to filter Orders with base_subtotal range between two values. But I have only been able to use the lt and gt. I'm unable to use both in the ...
Bassel N. Yahia's user avatar
5 votes
1 answer
4k views

Magento 2 API Product Search Option Attributes

I'd like to be able to search products via the API but in my experiments so far I've found that if I am searching for a value of an option attribute (e.g. drop-down list) then I have to specify the ID ...
robjingram's user avatar
4 votes
2 answers
1k views

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

I am using GET V1/products endpoint to fetch product list. I want to fetch sku and name only. http://localhost/magento/rest/default/V1/products?searchCriteria[sortOrders][0][direction]=ASC&...
Ramkishan Suthar's user avatar
4 votes
2 answers
7k views

how to use Search rest api in magento 2?

How to get items using search rest apis,example: I want to search watch in mogento2,how can i get the data from rest apis. Tried like this : http://localhost/magento2/index.php/rest/V1/search?...
Rgv's user avatar
  • 211
4 votes
1 answer
597 views

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

Those two classes are very similar but I don't get the differences and why should one be used instead of another ? Magento\Framework\Api\Search\SearchCriteriaBuilder => a handful of references in the ...
Raphael at Digital Pianism's user avatar
4 votes
1 answer
2k views

How to use V1/search to get the names and SKU's of the magento products

How to use V1/search to get the names and SKU's of the magento products? I need a text based search to get the names and SKU's of the magento products. While using V1/products API, the response is ...
nr5's user avatar
  • 460
4 votes
2 answers
2k views

Search criteria builder does not filter an "out_of_stock" products

I am using Magento 2.3, Am filtering the product collection using the search criteria builder with a custom attribute as the filter. $filter1 = $this->_filterBuilder->setField('...
Octopus's user avatar
  • 345
4 votes
3 answers
7k views

Magento 2 Search Rest API

I need to change the response of Search Rest API in Magento 2. Request:rest/V1/search?searchCriteria[requestName]=quick_search_container &searchCriteria[filterGroups][0][filters][0][field]=...
user avatar
4 votes
0 answers
659 views

Magento 2 - Changing Default Search Query Behavior

I have the following search criteria: /?free_from%5B%5D=265&free_from%5B%5D=266 I'm trying to query all products and return ONLY products with both options A and B selected for the custom ...
Sophie Baxter's user avatar
3 votes
1 answer
4k views

Customer Repository Interface, Limit Results

I'm trying to grab the oldest customer, using the customer repository from the database. Here's my code so far: // if custom is active $isActivefilter = $this->filter ->...
Ethan Yehuda's user avatar
3 votes
0 answers
517 views

Magento 2 rest api: Ignore out of stock products in get products search criteria

I am using the following api call to get products. {{base_url}}/rest/V1/products?searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][0][...
Arun SS's user avatar
  • 441
2 votes
1 answer
8k views

Magento2: Collection to SearchCriteria

How to convert $products = $this->_catalogSearchAdvanced ->getProductCollection() ->addStoreFilter($storeId) ->setCurPage($page) ->setPageSize($...
Miguel's user avatar
  • 549
2 votes
1 answer
3k views

How to print searchCriteriaBuilder query in Magento 2?

How to print searchCriteriaBuilder query in magento 2 ? I tried below code but it is not working. $childProductIds = [1,2,3]; $sortOrder = $this->sortOrderBuilder->setField('price')->...
Pandurang Babar's user avatar
2 votes
1 answer
3k views

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

I need to return array of search results and so far I did this. DashBoardInterface.php <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ...
Ramkishan Suthar's user avatar
2 votes
1 answer
2k views

SearchCriteria with 'OR' filter

I would like to get Cms Pages from repository using search criteria. I need to filter title and content fields. This is how I'm trying to do this: $this->filterBuilder->setField('title'); $this-...
Mage2User's user avatar
2 votes
1 answer
2k views

CatalogSearch results looking for partial SKU

I need to be able to search by partial string of a SKU, for example, if a SKU of a product is "CUS123.5NYS" the customer may also be able to search by "123.5N", but currently, it only works if I ...
Hector Andres Rojas's user avatar
2 votes
1 answer
414 views

Magento search rest api

In the application we are implementing a search function using rest api. The search will happen using multiple filters. By default, magento is using "and" operator between filters for producing search ...
Arun Kasyakar's user avatar
2 votes
1 answer
492 views

How to get the product type by the product SKU?

I have some product SKUs in my custom module and I want to get just the simple products. I don't want to load each product entity by SKU in a loop to get the product type to avoid performance issues. ...
Rafael Corrêa Gomes's user avatar
2 votes
0 answers
51 views

Logical "NOT" in SearchCriteria

I found how to use logical "AND" & "OR" in search criteria: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/searching-with-repositories.html https://devdocs.magento.com/guides/v2.3/...
Alex Gusev's user avatar
  • 1,999
2 votes
0 answers
673 views

Magento 2 - REST API filter order data from shipping and billing address name and telephone number

I need to filter order data based on shipping and billing address name and telephone through rest api For example In order to filter data through status my request url would be something like this: ...
Muhammad Hasham's user avatar
2 votes
0 answers
205 views

Joins on search criteria

Is thery any way to join other tables to SearchCriteriaInterface, while building it, before calling any getList method of any repository? I mean it should work more or less like joining tables on ...
Bartosz Kubicki's user avatar
2 votes
1 answer
3k views

Magento 2 filter products by price from Rest API

Magento-2 we would like to filter the products from REST API I have filtered product by price in the frontend please check the result in the below screenshot (24-MB02 price and special price we ...
Nagaraju Kasa's user avatar
2 votes
0 answers
2k views

Custom Attribute Search using SearchCriteria

I have created some custom attribute like city and I need to search how many products I have in a specific city using SearchCriteria. The SearchCriteria I apply does not filter products on my city ...
Rajkumar .E's user avatar
  • 3,550
2 votes
1 answer
3k views

Filtering data in magento REST API

I use this API to fetch the visible products using the filter: http://192.168.1.180/magento/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[...
nr5's user avatar
  • 460
1 vote
1 answer
1k views

How to filter Multiselect in Magento 2 search Rest API?

I am using magento search rest api. Now i can filter attributes like neck, sleeve, etc.., but i need to give multiple values for same attribute (like mulitple select) My Request: rest/V1/search?...
Lovely Setia's user avatar
1 vote
1 answer
2k views

Magento2: setFilterGroups(array) SearchCriteria Error

I have the following code: $filter1 = $this->_filterBuilder->setField('name') ->setValue('%'.$searchTerm.'%') ->setConditionType("like") ->create(); $filter2 = $this->...
Miguel's user avatar
  • 549
1 vote
1 answer
23 views

I'm looking for the best intelligent search extinsion

I'm looking for the best intelligent search for Magento 2 CE. I need it to show the result fast and fix the issue if customer search for the product by miss spelling not the exact product name and ...
mido's user avatar
  • 49
1 vote
3 answers
536 views

Rand sort on searchCriteria getItems

Is it possible to have a random sort when searching with repositories? Checked dev docs and unsure. Not found much elsewhere. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/searching-...
Dominic Pixie's user avatar
1 vote
1 answer
385 views

Magento 2: How to add multilevel AND and OR conditions to searchCriteria?

What i want to achieve is this - attr1 = 'val1' AND attr2 = 'val2' AND ((attr_s1 = 'val_s1' AND attr_d1 = 'val_d1' AND attr_t1 = 'val_t1') OR (attr_s2 = 'val_s2' AND attr_d2 = 'val_d2' AND ...
Amol Agre's user avatar
1 vote
1 answer
346 views

SearchCriteria Logical OR and AND search

I am trying to get a search criteria to become the following SQL: WHERE (a = 1 AND b = 2) OR (c = 3) Magento2 Documentation only has the example where AND and OR are reversed. Is this even possible? ...
Domeglic's user avatar
  • 542
1 vote
3 answers
774 views

Magento 2.3: Search is not working for specific search terms/queries

I'm having a strange issue with our website. The issue is that, when I'm searching with some specific keywords like TV, AC, It's not giving me the results and its returning empty results as below ...
MagentoDev's user avatar
1 vote
0 answers
71 views

Using SearchCriteria and FIlterBuilders is it possible to have a nested AND condition inside ORs?

So I know how to create AND condition using the addFilter and how to add OR conditions using FilterBuilder however if I wanted to do do a search like (only using searchCriteria, no direct collection ...
IdiotDev's user avatar
1 vote
0 answers
120 views

How to change search query in quick search from 'like%' => '%like%'

I have word to search 'luma' I type 'lum'in search then I have result. But i type 'uma', I have no result. I think query of search is "LIKE 'value%'". So i want change it to "LIKE '%...
TrinhfTrinhf's user avatar
1 vote
0 answers
411 views

SearchCriteria vs Collection - Query Performance Difference

I am trying to refactor get category data method. Initially, it was written with Collection filter. Later I refactored with the search builder interface. When I tried to compare the querying time, I ...
blakcaps's user avatar
  • 1,965
1 vote
0 answers
312 views

Magento 2 Search - how to show result when customer search for a SKU with prefix and suffix? EX: AA-SKU1234

Is there a way to return result for 'SKU', if the customer search for the term like 'AA-SKU2033'? Currently, our product has the following format on the actual product sticker 'AA-SKU2033' 'AA-' is ...
Mage Explorer's user avatar
1 vote
1 answer
1k views

Magento 2 how to pass if exist search criteria in rest api call

I need to filter getList records in my rest api call. I have following: searchCriteria[filter_groups][0][filters][0][field]=city_ref&searchCriteria[filter_groups][0][filters][0][condition_type]=...
Duddy Woody's user avatar
1 vote
0 answers
269 views

Search using REST endpoints on two different columns with OR condition in Magento 2

I'm using Magento v2.3 and using API to search products. Following is the search criteria code. 'searchCriteria[filterGroups][0][filters][0][field]': 'name', 'searchCriteria[filterGroups][0][filters]...
Nausif's user avatar
  • 1,534
1 vote
1 answer
362 views

Why quantity_and_stock_status is always 1 in /V1/products?searchCriteria in Magento-2.2.7?

I am using Magento-2.2.7 . If i call this endpoint /V1/products?searchCriteria , it always show each product having same quantity_and_stock_status . Whenever product is in_stock or out_of_stock it ...
Lovely Setia's user avatar
1 vote
0 answers
1k views

Magento 2 Rest Api - Is this searchCriteria filter correct?

I'm trying to retrieve virtual products, which have been modified before a certain date and which still are in stock I'm using this /rest/V1/products?searchCriteria[filter_groups][0][filters][0]...
Mark CR's user avatar
  • 21
1 vote
1 answer
174 views

Fetch products from several SKUs where their price don't match from a list

I have a predefined list of SKUs with prices in an array, and I would like to return the products within Magento that matches those SKUs but not the price. As a quick solution, I have constructed an ...
Smithee's user avatar
  • 309