Elasticsearch response format
- Published
- Reading time
- 2 min read
- Length
- 333 words
On this page
Elasticsearch Response Format#
Elasticsearch is an open-source search engine that stores and retrieves data using a JSON-based query language. It is highly scalable and can handle a large amount of data. When we perform a search query on Elasticsearch, it returns a response in a particular format.
Response Format#
The response format of Elasticsearch has three main parts:
- Meta Information: This part contains metadata about the request and the response.
- Hits: This part contains the actual search results.
- Aggregations: This part contains the aggregations (statistics) of the search results.
Meta Information#
The meta information section contains information about the request and the response. It includes the following:
- took: This field indicates how long the request took to execute, in milliseconds.
- timed_out: This field indicates whether the request timed out or not.
- _shards: This field contains information about how many shards were searched and how many of them returned successful results.
Hits#
The hits section contains the actual search results. It includes the following:
- total: This field indicates the total number of documents that matched the search query.
- max_score: This field indicates the maximum score of all matching documents.
- hits: This field is an array of actual search results. Each hit contains information about the matched document, such as its index, ID, and score.
Aggregations#
The aggregations section contains the statistics of the search results. It includes the following:
- aggregation_name: This field indicates the name of the aggregation.
- doc_count: This field indicates the number of documents that match the aggregation.
- aggregation_results: This field contains the actual aggregation results.
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"title": "My Title",
"description": "My Description"
}
}
]
},
"aggregations": {
"my_aggregation": {
"doc_count": 1,
"my_sum": {
"value": 100
}
}
}
}Overall, Elasticsearch provides a powerful and flexible search engine that returns search results in a well-structured format. It is highly customizable and can be configured to meet a wide range of search requirements.