# Can't get document by id

**URL:** <https://discuss.elastic.co/t/cant-get-document-by-id/131759>\
**Category:** Elasticsearch\
**Created:** [May 14, 2018, 2:34pm UTC](https://discuss.elastic.co/t/cant-get-document-by-id/131759 "2018-05-14T14:34:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiocatalao](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@fabiocatalao](https://discuss.elastic.co/u/fabiocatalao)\
**Post date:** [May 14, 2018, 2:34pm UTC](https://discuss.elastic.co/t/cant-get-document-by-id/131759/1 "2018-05-14T14:34:39Z")

</div>

Hi,

I'm being unable to get documents that I index using Java API from the index by id. I'm using the following code to prepare the index:

```
IndexRequest indexRequest = new IndexRequest(myindex, mytype, myid)
                    .source(mysource.toString())
                    .routing(myrootingkey);

```

When I try to get a document I receive an empty found.

```
GET mynode.:9200/myindex/1/211535
    {
        "_index": "myindex",
        "_type": "1",
        "_id": "211535",
        "found": false
    }

```

I've also tried to manually add a document and this way I'm able to get the document.

I've searched for it and found some users with the same problem but most of them use older elasticsearch versions. I'm currently on 5.5.4 so the problem could not be the same.  
I've found some information that the problem could be related to the rooting key but I couldn't find any official information about this bug/feature or how does it affect it.

Can someone explain to me what I'm doing wrong and why can't I make it work the way I'm doing it?

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 14, 2018, 2:37pm UTC](https://discuss.elastic.co/t/cant-get-document-by-id/131759/2 "2018-05-14T14:37:06Z")

</div>

If you index with a routing key, you need to query using it too.

---

<div class="post-metadata">

**Author:** ![fabiocatalao](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@fabiocatalao](https://discuss.elastic.co/u/fabiocatalao)\
**Post date:** [May 14, 2018, 3:12pm UTC](https://discuss.elastic.co/t/cant-get-document-by-id/131759/3 "2018-05-14T15:12:08Z")

</div>

Thank you.  
I've successfully made it work adding _?routing=routing\_key_ arg.  
I'm going to rethink the way we are using routing as it has other disadvantages that were not taken into account at the time it was implemented.

---

<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 11, 2018, 3:18pm UTC](https://discuss.elastic.co/t/cant-get-document-by-id/131759/4 "2018-06-11T15:18:01Z")

</div>

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