'SalesForce Open Commerce API product_search

I am new to SalesForce OCAPI. I am working with the product_search api. I am passing the following query

  "query": {
    "text_query": {
      "fields": [
        "id", "name"
      ],
      "search_phrase": "some_search_phrase"
    }   },   "select": "(**)" }

It works fine and I get the response. However, I want to include the "creation_date" field in the query but it doesn't work. link to documentation: https://documentation.b2c.commercecloud.salesforce.com/DOC2/index.jsp?topic=%2Fcom.demandware.dochelp%2FOCAPI%2Fcurrent%2Fdata%2FResources%2FCatalogSearch.html

Here is what I am attempting.

  "query": {
    "text_query": {
      "fields": [
        "id", "name", "creation_date - 2021-11-23T07:38:30.000Z"
      ],
      "search_phrase": "some_search_phrase"
    }
  },
  "select": "(**)"
}

and I get the following response.

{"_v":"21.10","fault":{"arguments":{"field":"creation_date - 2021-11-23T07:38:30.000Z"},"type":"UnqueryableFieldException","message":"The field 'creation_date - 2021-11-23T07:38:30.000Z' can't be queried."}}

There are a few other attributes in the field according to the documentation.

id - String
name - String
online - SiteSpecific Boolean
searchable - SiteSpecific Boolean
valid_from - SiteSpefic DateTime
valid_to - SiteSpecfic DateTime
type - ProductType
creation_date - DateTime

What I am trying to do is to fetch the products after a specific "creation_date" and I don't know whether to use "valid_from" and "valid_to" or the "creation_date"



Solution 1:[1]

This is what I usually do for getting a date range of data on for a filter:

                "filtered_query": {
                    "query": { "match_all_query": {} },
                    "filter": {
                        "range_filter": {
                            "field": "creation_date",
                            "from": last_collection_date.strftime("%Y-%m-%dT%H:%M:%S.000Z"), #2021-06-10T01:00:00.000Z
                            "to": date_now.strftime("%Y-%m-%dT%H:%M:%S.000Z") #2021-06-10T01:00:00.000Z
                        }
                    }
                }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matt Notter