Public Queries
Once you have created a Query and obtained a queryKey, you can finally execute a PublicQuery.
Public Query endpoint is intended for public use - it is your responsibility to ensure that none of the sensitive data is returned with the selectFields
parameter in the Query configuration.
Basic Query
Basic Query - Request
Now you just need to send an HTTP POST request to the following endpoint, while replacing the queryKey with the one obtained in the previous step.
/v1/query/{queryKey}
The most basic query can consist of just a query string:
{
"searchText": "bread"
}
Basic Query - Response
The response will be your query result based on your query string and query configuration:
{
"searchText": "television",
"total": 4,
"items": [
{
"id": 1,
"name": "Samsung Television",
"category": ["Electronics"],
"rating": 5
},
{
"id": 3,
"name": "LG Television",
"category": ["Electronics"],
"rating": 4
},
{
"id": 4,
"name": "Television Set",
"category": ["Electronics"],
"rating": 3
},
{ "id": 5, "name": "Televisions", "category": ["Electronics"], "rating": 2 }
]
}
- searchText - returns the original user query;
- total - total number of items that match the query;
- items - list of items that match the query.
Basic pagination
Basic pagination - Request
To perform a query with basic pagination parameters, you need to add two additional fields to the Public Query body:
{
"searchText": "bread",
"limit": 2,
"offset": 2
}
limit - defines max. number of items per page;
offset - defines how many items need to be skipped. For example, to get the 3rd page of the results, with page size of 10, one would need to pass pagination parameters as
{"limit": 10, "offset": 20}
.
Basic pagination - Response
The pagination query response additionally includes the limit and the offset settings that were passed with request:
{
"searchText": "television",
"total": 4,
"items": [
{ "id": 4, "name": "Television Set", "category": ["Electronics"], "rating": 3 },
{ "id": 5, "name": "Televisions", "category": ["Electronics"], "rating": 2 }
],
"limit": 2,
"offset": 2
}
Next steps:
Query configuration is much more powerful. To learn more about facets, filtering, boosting and other parameters, check Public Queries - Advanced, or view our quick document, mapping and query configuration Examples.