# Is there a way to get all doc ID's from an index for a specified time range?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885
**Category:** Elasticsearch
**Created:** [June 14, 2021, 6:18pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885 "2021-06-14T18:18:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aidenosi](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aidenosi](https://discuss.elastic.co/u/aidenosi)
#### Post date: [June 14, 2021, 6:18pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885/1 "2021-06-14T18:18:06Z")

</div>

Hello,

We recently had an issue that caused one of our servers to report as "down" to heartbeat even though it was up. This caused us to have 3 days of "downtime" in our metrics. We want to fix this by going through and changing all the `monitor.status:down` to `up`.

Is there a way to get all of the document ID's from an index over a certain time range? From what I'm seeing in the API, the only way to GET a document is with the ID. If there a way to get all the IDs from the time range we are looking at, we could go through them each and update the `monitor.status`.

Thanks!

---

<div class="post-metadata">

### Author: ![aidenosi](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aidenosi](https://discuss.elastic.co/u/aidenosi)
#### Post date: [June 14, 2021, 7:48pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885/2 "2021-06-14T19:48:16Z")

</div>

I now have the below query which returns all of the documents I require:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "monitor.name": "<name>"
          }
        },
        {
          "match": {
            "monitor.status": "down"
          }
        },
        {
          "range": { "@timestamp": {"gte": "2020", "lte": "2021"} }
        }
      ]
    }
  }
}

```

Is there a way to filter this through the API to return just the ID's?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 14, 2021, 8:27pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885/3 "2021-06-14T20:27:27Z")

</div>

I think this page could help. [Retrieve selected fields from a search | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html)

---

<div class="post-metadata">

### Author: ![aidenosi](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aidenosi](https://discuss.elastic.co/u/aidenosi)
#### Post date: [June 15, 2021, 5:34pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885/4 "2021-06-15T17:34:35Z")

</div>

Thanks David, I've modified it again and have this:

```auto
GET _search
{
  "from": 0, "size": 10000,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "match": {
            "monitor.name": "<name>"
          }
        },
        {
          "match": {
            "monitor.status": "down"
          }
        },
        {
          "range": { "@timestamp": {"gte": "2021-05-28", "lte": "2021-05-29"} }
        }
      ]
    }
  },
  "stored_fields": ["_id"]
}

```

However, my results look like this:

```auto
{
        "_index" : "devops-healthchecks",
        "_type" : "doc",
        "_id" : "g0HatHkBcgMRSH0wiTnx",
        "_score" : 1.0
      },

```

Is there a way to get **just** the ID's? Or some way to output this to a CSV? As I'll need a list of the ID's to query. I could parse the result in Python but I'd like to save myself some work if possible.

---

<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: [July 13, 2021, 5:34pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-all-doc-ids-from-an-index-for-a-specified-time-range/275885/5 "2021-07-13T17:34:58Z")

</div>

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