# Document exist check

**URL:** <https://discuss.elastic.co/t/document-exist-check/45789>\
**Category:** Elasticsearch\
**Created:** [March 30, 2016, 12:41pm UTC](https://discuss.elastic.co/t/document-exist-check/45789 "2016-03-30T12:41:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raunak/32/4446_2.png) [@raunak](https://discuss.elastic.co/u/raunak)\
**Post date:** [March 30, 2016, 12:41pm UTC](https://discuss.elastic.co/t/document-exist-check/45789/1 "2016-03-30T12:41:43Z")

</div>

Given the scenario where the index contains documents with ids 1,2,3,4,5,6,7. A user saves document 1, 3, and 7 in their session, and sometime later, document 3 is removed from the index.

What query can I use against the index to know the list of documents that are no longer in the index? I could fire a bulk get, so perform a get on doc with ids [1,3,7] and write custom logic in my code to see which docs didn't return. Is there a method/query that in built in elasticsearch to let me do that?

I'm using elasticsearch version 2.2.0.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [March 30, 2016, 1:43pm UTC](https://discuss.elastic.co/t/document-exist-check/45789/2 "2016-03-30T13:43:47Z")

</div>

Hi,

better than a bulk get would be to make use of the [Ids Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html) something like this:

```auto
GET /i/t/_search 
{
  "query": { 
    "ids": {
        "type" : "t",
        "values" :[1,3,7]
    } 
  },
  "fields": []
}

```

That should be quiet fast and id you only need the ID then the `fields` portion makes sure only meta data gets included in the result, so you get:

```auto
"hits": {
    "total": 3,
    "max_score": 1,
    "hits": [
      {
        "_index": "i",
        "_type": "t",
        "_id": "1",
        "_score": 1
      },
      {
        "_index": "i",
        "_type": "t",
        "_id": "7",
        "_score": 1
      },
      {
        "_index": "i",
        "_type": "t",
        "_id": "3",
        "_score": 1
      }
    ]
  }

```

You still need to figure out which ids from your query list are missing in the result, at least there is no easy built-in way to do so I think.

---

<div class="post-metadata">

**Author:** ![raunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raunak/32/4446_2.png) [@raunak](https://discuss.elastic.co/u/raunak)\
**Post date:** [March 30, 2016, 1:52pm UTC](https://discuss.elastic.co/t/document-exist-check/45789/3 "2016-03-30T13:52:59Z")

</div>

@cbuescher That is currently what I'm doing. I was hoping there might be an inbuilt method based on the new aggregation module. A man has to hope 🙂

@Dale_McDiarmid Is there any inbuilt method that can be used here?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [March 30, 2016, 1:54pm UTC](https://discuss.elastic.co/t/document-exist-check/45789/4 "2016-03-30T13:54:34Z")

</div>

@raunak sorry, but that sounds interessting, will keep digging

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 31, 2016, 1:55am UTC](https://discuss.elastic.co/t/document-exist-check/45789/5 "2016-03-31T01:55:00Z")

</div>

> [@raunak](#):
>
> @Dale_McDiarmid Is there any inbuilt method that can be used here?

It's not really polite to ping people like this that aren't involved in your thread at all 🙂

---

<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 5, 2017, 11:03pm UTC](https://discuss.elastic.co/t/document-exist-check/45789/6 "2017-07-05T23:03:50Z")

</div>


