Filtering order search

You can use SearchOrder API along with the resultFilter and queryFilter to refine your search results. You can apply these filters in combination with an aggregator to aggregate the search results and derive purposeful and relevant business insights.

Before you begin, take a moment to understand the following terms in context of Order Search: discoverability and findability are two important terms. Discoverability is when you find the perfect order, even though you might not be looking for it. Findability is when you find the exact order you were looking for, even if all you knew about it was some information snippet from it. Order filtering, when done right, can solve both issues. It helps you refine the results to the specific order you might be looking for and finds orders you might be interested in based on a certain criteria. For example, OrderLine.PersonInfoShipTo.City, OrderLine.ItemId, OrderDate, or OriginalTotalAmount.

Filtering using resultFilter

Result filter is a standard pattern to filter search hits. It acts as a post filter and applies directly on the search hits. When you use result filters, the actual search hits are filtered after the aggregations are calculated. Therefore, it does not impact the aggregation results.

The following search query returns all orders that have OriginalTotalAmount greater than 10. These results are further filtered by a criteria where OrderLine.PersonInfoShipTo.City is set to Littleton. However, the aggregation is applied on the original query result set, and not on the filtered set.
{
 "query": {
   "match": [
     {
       "condition": "MUST",
       "field": "OriginalTotalAmount",
       "value": "10",
       "operator": "gt"
     }
   ]
 },
 "cursor": {
   "pageNumber":"1",
   "pageSize":"10"
 },
 "aggregate": [
   {
     "field": "OrderLine.PersonInfoShipTo.City"
   }
 ],
 "resultFilter": [
   {
     "condition":"MUST",
     "field":"OrderLine.PersonInfoShipTo.City",
     "value":"Littleton"
   }
 ]
}

Filtering using queryFilter

It is a standard pattern to filter search hits. You can apply queryFilter to both search and aggregation queries. The documents that do not match the filter constraints are filtered out. Query filters do not affect the score of matching documents but impact the hits and the aggregation results.

Refer to the following example. The search query looks for all orders that have OriginalTotalAmount greater than 10. These results are further filter by a criteria where OrderLine.PersonInfoShipTo.City is set to Littleton. And, aggregation is applied on those filter results. Therefore, final order is set after all filters are applied.
{
    "query": {
      "match": [
        {
          "condition": "MUST",
          "field": "OriginalTotalAmount",
          "value": "10",
          "operator": "gt"
        }
      ]
    },
    "cursor": {
      "pageNumber":"1",
      "pageSize":"10"
    },
    "aggregate": [
      {
        "field": "OrderLine.PersonInfoShipTo.City"
      }
    ],
    "queryFilter":[
      {
        "condition":"MUST",
        "field":"OrderLine.PersonInfoShipTo.City",
        "value":"Littleton"
      }
    ]
  }

Supported filter types

For more information, see the following table for supported filter types.

Filter type Usage
NORMAL Use for Terms, expressions, and match filter patterns.
RANGE Use for Range or Daterange filter patterns.
WILDCARD Use for startsWith, contains, and endsWith filter patterns.
REGEX Use for Regex type filter patterns.

Combining search queries, filters, and aggregations

You can use the SearchOrderAPI in the following possible combinations:
  • Only query or documentQuery or rawQuery
  • (Query or documentQuery or rawQuery)+aggregator
  • Either queryFilter or resultFilter
  • (Either queryFilter or resultFilter)+aggregator
  • (Query or documentQuery or rawQuery)+(Either queryFilter or resultFilter)
  • (Query or documentQuery or rawQuery)+(Either queryFilter or resultFilter)+aggregator