The content request object

Add a content JSON object in a Sitecore Discover Search and Recommendation request to specify the type of content you want to see in the search results. To further customize results, you can specify the maximum number of results, sorting type, and fields displayed for each <content_type> in the request.

The following shows the structure of the content object in a request:

RequestResponse
{
    "content": {
	"<content_type>": {
		"max": 10,
		"sort": {
			"type": "text",
			"order": "asc"
		},
		"get_fields": false,
		"field": {
			"value": [
                            "<content_field>"
                        ]
		}
	}
    }
}

Keys

The following table describes the key that the content object contains.

Key

Type

Description

Value

content_type

Content type object

Required.

Type of content that can be queried one at a time or multiple instances at a time.

Each content type requires a feed or another data source.

The only out-of-the-box content_type we support is product.

Default: product

product

Content type object

The following table describes the keys in the content type object:

Key

Type

Description

max

integer

Optional.

Limits the number of results of the content returned per page.

Default: n_item

sort

Sort object

Optional.

Determines the sort order of the <content_type>

Example:

RequestResponse
{"type": "text",
 "order": "asc"}

get_fields

Boolean

Optional.

If you set this to true, the response returns a list of all possible content field names.

Default: false

field

array of strings

Optional

The available <content_field> per <content_type> in the query.

Sort object

The following table describes the keys in the sort object:

Key

Type

Description

Value

type

string

Required.

Whether you want to sort content alphabetically or by the number of items that have this value.

For example, a search result has five red and four blue items. If you specify the sort type as count, the red items appear first because there are more red items than blue.

  • count (default)

  • text

order

string

Required.

Whether you want to sort content in an ascending or descending order.

  • desc (default)

  • asc

The following table describes the keys related to the content object:

Key

Type

Description

n_item

integer

Optional.

Total number of the items to be returned for all <content_types> requested in the content object.

Note

The n_item you specify impacts the latency of the request. We recommend you use a value of less than or equal to 48, typically, between 10 and 24. Any number greater than 48 might degrade the latency of the request, and SLAs cannot be guaranteed.

Default: 10

page_number

integer

Optional.

Page number to be returned. The page contains a maximum of n_item items.

Note

The page_number does not return the maximum number of n_item items if there are not enough items on the last page or if querying content does not have enough pages.

Default: 1

Example:

A request for page_number 5 gives you content to be shown on the 5th page.

Example

The following code shows a request to get the name and price of 10 products:

RequestResponse
{
    "n_item": 10,
    "content": {
        "product": {
            "field": {
                "value": [
                    "price"
                ]
            }
        }
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,