Search Criteria

Overview

All of the endpoints that make use of these POST method and receive the criteria as a JSON object. Generally, we refer to this object as the search criteria - as it takes the same arguments as a DAL criteria. Some endpoints expect more parameters than specified here - however, these differ from one endpoint to another, so we don't specify them here.
A typical search criteria looks like this:
1
{
2
"limit": 10,
3
"associations": {
4
"manufacturer": {},
5
"propertyIds": {},
6
"cover": {},
7
"options": {
8
"associations": {
9
"productOptions": {},
10
"group": {}
11
}
12
}
13
},
14
"includes": {
15
"product": [
16
"calculatedPrice",
17
"cover",
18
"id",
19
"translated",
20
"seoUrls",
21
"manufacturer",
22
"propertyIds",
23
"options"
24
],
25
"product_media": [
26
"media"
27
],
28
"media": [
29
"thumbnails",
30
"width",
31
"height",
32
"url"
33
],
34
"calculated_price": [
35
"unitPrice",
36
"quantity"
37
]
38
}
39
}
Copied!
In the following we'll go through the different parameters, a criteria can be assembled from:
Parameter
Usage
associations
Allows to load additional data to the standard data of an entity
includes
Restricts the output to the defined fields
ids
Limits the search to a list of Ids
total-count-mode
Defines whether a total must be determined
page
Defines at which page the search result should start
limit
Defines the number of entries to be determined
filter
Allows you to filter the result and aggregations
post-filter
Allows you to filter the result, but not the aggregations
query
Enables you to determine a ranking for the search result
term
Enables you to determine a ranking for the search result
sort
Defines the sorting of the search result
aggregations
Specify aggregations to be computed on-the-fly
grouping
Lets you group records by fields

Parameters

associations

The associations parameter allows you to load additional data to the minimal data set of an entity without sending an extra request - similar to a SQL Join. The key of the parameter is the property name of the association in the entity. You can pass a nested criteria just for that association - e.g. to perform a sort to or apply filters within the association.
1
{
2
"associations": {
3
"products": {
4
"limit": 5,
5
"filter": [
6
{ "type": "equals", "field": "active", "value": true }
7
],
8
"sort": [
9
{ "field": "name", "order": "ASC" }
10
]
11
}
12
}
13
}
Copied!

includes (apiAlias)

The includes parameter allows you to restrict the returned fields.
  • Transfer only what you need - reduces response payload
  • Easier to consume for client applications
  • When debugging, the response is smaller and you can concentrate on the essential fields
1
{
2
"includes": {
3
"product": ["id", "name"]
4
}
5
}
6
​
7
// Reponse
8
{
9
"total": 120,
10
"data": [
11
{
12
"name": "Synergistic Rubber Fish Soda",
13
"id": "012cd563cf8e4f0384eed93b5201cc98",
14
"apiAlias": "product"
15
},
16
{
17
"name": "Mediocre Plastic Ticket Lift",
18
"id": "075fb241b769444bb72431f797fd5776",
19
"apiAlias": "product"
20
}
21
]
22
}
Copied!
All response types come with a apiAlias field which you can use to identify the type in your includes field. If you only want a categories id, add: "category": ["id"]. For entities, this is the entity name: product, product_manufacturer, order_line_item, ... For other non-entity-types like a listing result or a line item, check the full response. This pattern applies not only to simple fields but also to associations.

ids

If you want to perform a simple lookup using just the ids of records, you can pass a list of those using the ids field:
1
{
2
"ids": [
3
"012cd563cf8e4f0384eed93b5201cc98",
4
"075fb241b769444bb72431f797fd5776",
5
"090fcc2099794771935acf814e3fdb24"
6
]
7
}
Copied!

total-count-mode

The total-count-mode parameter can be used to define whether the total for the total number of hits should be determined for the search query. This parameter supports the following values:
  • 0 [default] - No total is determined
    • Purpose: This is the most performing mode because MySQL Server does not need to run the SQL_CALC_FOUND_ROWS in the background.
    • Purpose: Should be used if pagination is not required
  • 1 - An exact total is determined.
    • Purpose: Should be used if a pagination with exact page number has to be displayed
    • Disadvantage: Performance intensive. Here you have to work with SQL_CALC_FOUND_ROWS
  • 2 - It is determined whether there is a next page
    • Advantage: Good performance, same as 0.
    • Purpose: Can be used well for infinite scrolling, because with infinite scrolling the information is enough to know if there is a next page to load
1
{
2
"total-count-mode": 1
3
}
Copied!

page & limit

The page and limit parameters can be used to control pagination. The page parameter is 1-indexed.
1
{
2
"page": 1,
3
"limit": 5
4
}
Copied!

filter

The filter parameter allows you to filter the result and aggregations using a multitude of filters and parameters. The filter types are equivalent to the filters available for the DAL.
When you are filtering for nested values - for example you're filtering orders by their transaction state (order.transactions.stateMachineState) - make sure to fetch those in your associations field before.
1
{
2
"associations": {
3
"transactions": {
4
"associations": {
5
"stateMachineState": {}
6
}
7
}
8
},
9
"filter": [
10
{
11
"type": "multi",
12
"operator": "and",
13
"queries": [
14
{
15
"type": "multi",
16
"operator": "or",
17
"queries": [
18
{
19
"type": "equals",
20
"field": "transactions.stateMachineState.technicalName",
21
"value": "paid"
22
},
23
{
24
"type": "equals",
25
"field": "transactions.stateMachineState.technicalName",
26
"value": "open"
27
}
28
]
29
},
30
{
31
"type": "equals",
32
"field": "customFields.exportedFlag",
33
"value": null
34
}
35
]
36
}
37
]
38
}
Copied!

post-filter

Work the same as filter however, they don't apply to aggregations. This is great, when you want to work with aggregations to display facets for a filter navigation, but already filter results based on filters without making an additional request.

query

Use this parameter to create a weighted search query that returns a _score for each found entity. Any filter type can be used for the query. A score has to be defined for each query. The sum of the matching queries then results in the total _score value.
1
{
2
"query": [
3
{
4
"score": 500,
5
"query": { "type": "contains", "field": "name", "value": "Bronze"}
6
},
7
{
8
"score": 500,
9
"query": { "type": "equals", "field": "active", "value": true }
10
},
11
{
12
"score": 100,
13
"query": {
14
"type": "equals",
15
"field": "manufacturerId",
16
"value": "db3c17b1e572432eb4a4c881b6f9d68f"
17
}
18
}
19
]
20
}
Copied!
The resulting score is appended to every resulting record in the extensions.search field:
1
{
2
"total": 5,
3
"data": [
4
{
5
"manufacturerId": "db3c17b1e572432eb4a4c881b6f9d68f",
6
"name": "Awesome Bronze Krill Kream",
7
"extensions": {
8
"search": {
9
"_score": "1100"
10
}
11
},
12
"id": "0acc3aa5c45a492c9a2adb8844cb7adc",
13
"apiAlias": "product"
14
},
15
{
16
"manufacturerId": "d0c0daa910d94b3c8b03c2bef6acb9b8",
17
"name": "Synergistic Bronze New Tab",
18
"extensions": {
19
"search": {
20
"_score": "1000"
21
}
22
},
23
"id": "72858576ac634f209b7ad61db15b7cc3",
24
"apiAlias": "product"
25
},
26
{
27
"manufacturerId": "3b5f9d51803849c68bb72360debd3da0",
28
"name": "Fantastic Paper Zamox",
29
"extensions": {
30
"search": {
31
"_score": "500"
32
}
33
},
34
"id": "18d2b4225ea34b17a6099108da159e7f",
35
"apiAlias": "product"
36
}
37
]
38
}
Copied!

term

Using the term parameter, the server performs a text search on all records based on their data model and weighting as defined in the entity definition using the SearchRanking flag.
Don't use term parameters together with query parameters.
1
{
2
"term": "Awesome Bronze"
3
}
Copied!
The results are formatted the same as for the query parameter above.

sort

The sort parameter allows to control the sorting of the result. Several sorts can be transferred at the same time.
  • The field parameter defines which field is to be used for sorting.
  • The order parameter defines the sort direction.
  • The parameter naturalSorting allows to use a Natural Sorting Algorithm​
1
{
2
"limit": 5,
3
"sort": [
4
{ "field": "name", "order": "ASC", "naturalSorting": true },
5
{ "field": "active", "order": "DESC" }
6
]
7
}
Copied!

aggregations

With the aggregations parameter, meta data can be determined for a search query. There are different types of aggregations which are listed in the reference documentation. A simple example is the determination of the average price from a product search query.
  • Purpose: Calculation of statistics and metrics
  • Purpose: Determination of possible filters
The aggregation types are equivalent to the aggregations available in the DAL:
1
{
2
"limit": 1,
3
"includes": {
4
"product": ["id", "name"]
5
},
6
"aggregations": [
7
{
8
"name": "average-price",
9
"type": "avg",
10
"field": "price"
11
}
12
]
13
}
Copied!

grouping

The grouping parameter allows you to group the result over fields. It can be used to realise queries such as:
  • Fetch one product for each manufacturer
  • Fetch one order per day and customer
1
{
2
"limit": 5,
3
"grouping": ["active"]
4
}
Copied!
Last modified 6mo ago