# Return only the data inside hits \[ \]

**URL:** <https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 7:32am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576 "2019-05-24T07:32:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 24, 2019, 7:32am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/1 "2019-05-24T07:32:17Z")

</div>

Hi,

I have a query that returns the `hits` field nested inside `key` and`aggregations`.

I'm using curl to send the data to logstash for further processing and I would like to make my life a bit easier by only having to process whatever is in the hits field. However if I do something like `/_search?q=elasticsearch&filter_path=took,hits.hits._id,hits.hits._score` the return is always `hits []`.

My documents looks like this

```
  "aggregations" : {
    "location" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "8913514",
          "doc_count" : 6898,
          "latest_data" : {
            "hits" : {
              "total" : {
                "value" : 6898,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "test",
                  "_type" : "doc",
                  "_id" : "123",
                  "_score" : null,
                  "_source" : {
                    "@timestamp" : "2017-08-04T16:59:00.209Z",
                    "gps_location_geo" : "12345",
                    "location" : "somewhere"
                  },
                  "sort" : [
                    "somewhere"
                  ]
                }
              ]
            }
          }
        }
```

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [May 24, 2019, 7:35am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/2 "2019-05-24T07:35:08Z")

</div>

> [@Sjaak01](#):
>
> `filter_path=took,hits.hits._id,hits.hits._score`

I think you'll need `filter_path=took,hits.hits.*._id,hits.hits.*._score` since `hits.hits` is an array of objects.

---

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 24, 2019, 8:00am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/3 "2019-05-24T08:00:25Z")

</div>

Unfortunately that does not work. It only returns took.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [May 24, 2019, 8:33am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/4 "2019-05-24T08:33:09Z")

</div>

Can you share an example response without any `filter_path` so we can see what we're trying to filter?

---

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 24, 2019, 8:41am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/5 "2019-05-24T08:41:50Z")

</div>

Hi David,

The output looks like this:

```
{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 43,
    "successful" : 43,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "location" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "8913514",
          "doc_count" : 6898,
          "latest_data" : {
            "hits" : {
              "total" : {
                "value" : 6898,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "test",
                  "_type" : "doc",
                  "_id" : "123",
                  "_score" : null,
                  "_source" : {
                    "@timestamp" : "2017-08-04T16:59:00.209Z",
                    "gps_location_geo" : "12345",
                    "location" : "somewhere"
                  },
                  "sort" : [
                    "somewhere"
                  ]
                }
              ]
            }
          }
        }
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 21, 2019, 8:41am UTC](https://discuss.elastic.co/t/return-only-the-data-inside-hits/182576/6 "2019-06-21T08:41:54Z")

</div>

Closed on June 21, 2019, 8:41am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
