Skip to main content

Facets & Filters

Request

Method: POST

Endpoint: /v1.4/search

Any fields returned in the results can be used for Aggregation (facets) and Range (filter min and max). For the fields you specify for aggregation and range, you will get the associated document count (for the aggregation) and min & max range (for the range) as part of your results, which will help you display the information (count & range) in the F/E.

Aggregation: Any text field can be used for "Aggregation". In the results, the fields that have double quotes around the value are the "text" fields. For example, "search_category": "Televisions".

Range: Any number field can be used for "Range". In the results, the fields that do NOT have double quotes around the value are the "number" fields. For example, "org_price": 1.0.

Scope: The scope field in the request is used to define filters that narrow down the search results. It can include conditions for both text (aggregation) and numeric (range) fields. The scope is structured as an object where the keys are the field names and the values are the conditions to be applied.

  • Text (Aggregation): Specify the values to filter by for text fields. The search results will include documents that match any of the specified values.
  • Number (Range): Define a range by specifying the minimum and maximum values for numeric fields. The search results will include documents that fall within the specified range.

By combining these filters, you can create complex queries to retrieve precisely the data you need.

Fields

FieldTypeRequiredDefaultDescription
customer_idStringYesRandom unique customer id generate by PA tracker
website_idStringYesClient unique website id provided by PA
qStringYesInput search query string
clientStringYesUnique client shortcode provided by PA
startIntegerYesDefines the offset from the first result you want to fetch
sizeIntegerNo20The max number of results you want returned with your query
scopeObjectNoSearch results will be filtered based on what you put in the scope.

Examples

Aggregation (facet)

Send a request to get "type" and "brand" as aggregation

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"aggregations": ["type","brand"]
}'

Range (facet)

Send a request to get "price" and "ratings" as range

info

All fields used for "Range", must be numeric. If they are not, then the result will return error.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"range_fields": ["price","ratings"]
}'

Scope for text (filtering)

Send a request to get search results filtered by values of Type product OR Type article

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"scope": {
"Type": ["product", "article"]}
}'

Scope for number (filtering)

Send a request to get search results filtered by a range of height.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"scope": {
"height": {
"min": 10,
"max": 1000}}
}'

Scope using a combination of text & number and multiple filters

Send a request to get search results filtered by values of Type product AND Brand LG AND a range of height.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"scope": {
"Type": ["product"],
"brand": ["LG"],
"height": {
"min": 10,
"max": 1000}}
}'