Skip to content
the poor coder

Elasticsearch response format

Poor Man
Published
Reading time
2 min read
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.
Text

{
    "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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC