search #
Searches documents.
There is a limit to how many documents can be returned by a single search query. That limit is by default set at 10000 documents, and you can't get over it even with the from and size pagination options.
To handle larger result sets, you have to either create a cursor by providing a value to the scroll option or, if you sort the results, by using the Elasticsearch search_after command.
Query Syntax #
HTTP #
URL: http://kuzzle:7512/<index>/<collection>/_search[?from=<int>][&size=<int>][&scroll=<time to live>][&includeTrash=<boolean>]
Method: POST
Body:{
"query": {
// ...
},
"aggregations": {
// ...
},
"sort": [
// ...
]
}Other protocols #
{
"index": "<index>",
"collection": "<collection>",
"controller": "document",
"action": "search",
"body": {
"query": {
// ...
},
"aggregations": {
// ...
},
"sort": [
// ...
]
},
// optional:
"from": <starting offset>,
"size": <page size>,
"scroll": "<scroll duration>",
"includeTrash": <boolean>
}Arguments #
collection: collection nameindex: index name
Optional: #
from: paginates search results by defining the offset from the first result you want to fetch. Usually used with thesizeargumentincludeTrash: if true, include documents in the trashcanscroll: creates a forward-only result cursor. This option must be set with a time duration, at the end of which the cursor is destroyed. If set, a cursor identifier namedscrollIdis returned in the results. This cursor can then be moved forward using the scroll API actionsize: set the maximum number of documents returned per result page
Body properties #
Optional: #
query: the search query itself, using the ElasticSearch Query DSL syntax.aggregations: control how the search result should be aggregatedsort: contains a list of fields, used to sort search results, in order of importance
An empty body matches all documents in the queried collection.
Response #
Returns a paginated search result set, with the following properties:
aggregations: provides aggregation information. Present only if anaggregationsobject has been provided in the search bodyhits: array of found documents. Each document has the following properties:_id: document unique identifier_score: relevance score_source: new document content
scrollId: identifier to the next page of result. Present only if thescrollargument has been settotal: total number of found documents. Can be greater than the number of documents in a result page, meaning that other matches than the one retrieved are available
{
"status": 200,
"error": null,
"index": "<index>",
"collection": "<collection>",
"action": "search",
"controller": "document",
"requestId": "<unique request identifier>",
"result": {
"scrollId": "<scroll id>",
"hits": [
{
"_id": "<document unique identifier>",
"_score": 1,
"_source": {
// document content
}
},
{
"_id": "<another document unique identifier>",
"_score": 1,
"_source": {
// document content
}
}
],
// Present only if aggregation parameters have been set
"aggregations": {
"aggs_name": {
}
},
"total": 42
}
}