# Get document by id is does not work for some docs but the docs are there

**URL:** https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254
**Category:** Elasticsearch
**Created:** [November 5, 2013, 3:48am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254 "2013-11-05T03:48:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Francisco\_Viramontes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francisco_viramontes/32/1998_2.png) [@Francisco\_Viramontes](https://discuss.elastic.co/u/Francisco_Viramontes)
#### Post date: [November 5, 2013, 3:48am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/1 "2013-11-05T03:48:01Z")

</div>

Hi!

I could not find another person reporting this issue and I am totally  
baffled by this weird issue. The problem is pretty straight forward. I have  
an index with multiple mappings where I use parent child associations. The  
parent is topic, the child is reply. I noticed that some topics where not  
being found via the has\_child filter with exactly the same information just  
a different topic id. That is how I went down the rabbit hole and ended up  
noticing that I cannot get to a topic with its ID.

What is even more strange is that I have a script that recreates the index  
from a SQL source and everytime the same IDS are not found by elastic search

For example if I do this:

curl -XGET '[http://localhost:9200/topics/topic\_en/173](http://localhost:9200/topics/topic_en/173)' | prettyjson  
\<paco/topic\_search\>  
% Total % Received % Xferd Average Speed Time Time Time  
Current  
Dload Upload Total Spent Left  
Speed  
100 80 100 80 0 0 26143 0 --:--:-- --:--:-- --:--:--  
40000  
\_index: topics\_20131104211439  
\_type: topic\_en  
\_id: 173  
exists: false

Nothing, but the doc is there:

curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search](http://127.0.0.1:9200/topics/topic_en/_search)' -d  
'{"query":{"term":{"id":"173"}}}' | prettyjson  
% Total % Received % Xferd Average Speed Time Time Time  
Current  
Dload Upload Total Spent Left  
Speed  
100 2127 100 2096 100 31 894k 13543 --:--:-- --:--:-- --:--:--  
1023k  
took: 1  
timed\_out: false  
\_shards:  
total: 5  
successful: 5  
failed: 0  
hits:  
total: 1  
max\_score: 1  
hits:  
-  
\_index: topics\_20131104211439  
\_type: topic\_en  
\_id: 173  
\_score: 1  
\_source:

This is a sample dataset, the gaps on non found IDS is non linear, actually  
most are not found. And again. If I drop and rebuild the index again the  
same documents cant be found via GET api and the same ids that ES likes are  
found.

I cant think of anything I am doing that is wrong here. Any ideas?

Cheers

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [November 5, 2013, 5:55am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/2 "2013-11-05T05:55:38Z")

</div>

I guess it's due to routing. Children are routed to the same shard as the parent.

So here elasticsearch hits a shard based on doc id (not routing / parent key) which does not have your child doc.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 nov. 2013 à 04:48, Paco Viramontes [kidpollo@gmail.com](mailto:kidpollo@gmail.com) a écrit :

> Hi!
> 
> I could not find another person reporting this issue and I am totally baffled by this weird issue. The problem is pretty straight forward. I have an index with multiple mappings where I use parent child associations. The parent is topic, the child is reply. I noticed that some topics where not being found via the has\_child filter with exactly the same information just a different topic id. That is how I went down the rabbit hole and ended up noticing that I cannot get to a topic with its ID.
> 
> What is even more strange is that I have a script that recreates the index from a SQL source and everytime the same IDS are not found by Elasticsearch
> 
> For example if I do this:
> 
> curl -XGET '[http://localhost:9200/topics/topic\_en/173](http://localhost:9200/topics/topic_en/173)' | prettyjson \<paco/topic\_search\>  
> % Total % Received % Xferd Average Speed Time Time Time Current  
> Dload Upload Total Spent Left Speed  
> 100 80 100 80 0 0 26143 0 --:--:-- --:--:-- --:--:-- 40000  
> \_index: topics\_20131104211439  
> \_type: topic\_en  
> \_id: 173  
> exists: false
> 
> Nothing, but the doc is there:
> 
> curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search](http://127.0.0.1:9200/topics/topic_en/_search)' -d '{"query":{"term":{"id":"173"}}}' | prettyjson  
> % Total % Received % Xferd Average Speed Time Time Time Current  
> Dload Upload Total Spent Left Speed  
> 100 2127 100 2096 100 31 894k 13543 --:--:-- --:--:-- --:--:-- 1023k  
> took: 1  
> timed\_out: false  
> \_shards:  
> total: 5  
> successful: 5  
> failed: 0  
> hits:  
> total: 1  
> max\_score: 1  
> hits:  
> -  
> \_index: topics\_20131104211439  
> \_type: topic\_en  
> \_id: 173  
> \_score: 1  
> \_source:
> 
> This is a sample dataset, the gaps on non found IDS is non linear, actually most are not found. And again. If I drop and rebuild the index again the same documents cant be found via GET api and the same ids that ES likes are found.
> 
> I cant think of anything I am doing that is wrong here. Any ideas?
> 
> ## Cheers
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Francisco\_Viramontes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francisco_viramontes/32/1998_2.png) [@Francisco\_Viramontes](https://discuss.elastic.co/u/Francisco_Viramontes)
#### Post date: [November 5, 2013, 6:35am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/3 "2013-11-05T06:35:34Z")

</div>

Right, if I provide the routing in case of the parent it does work.

curl -XGET '[http://localhost:9200/topics/topic\_en/147?routing=4](http://localhost:9200/topics/topic_en/147?routing=4)'

So whats wrong with my search query that works for children of some parents?

curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search?routing=4](http://127.0.0.1:9200/topics/topic_en/_search?routing=4)' -d '{"query":{"filtered":{"query":{"bool":{"should":[{"query\_string":{"query":"matra","fields":["topic.subject"]}},{"has\_child":{"type":"reply\_en","query":{"query\_string":{"query":"matra","fields":["reply.content"]}}}}]}},"filter":{"and":{"filters":[{"term":{"community\_id":4}}]}}}},"sort":,"from":0,"size":25}'  
{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}

* * *

Francisco Viramontes  
a.k.a. PAco

[twitter.com/kidpollo](http://twitter.com/kidpollo) ([http://www.twitter.com/](http://www.twitter.com/))  
[Facebook](http://facebook.com/fviramontes) ([Facebook](http://facebook.com/fviramontes))  
[linkedin.com/in/fviramontes](http://linkedin.com/in/fviramontes) ([http://www.linkedin.com/in/fviramontes](http://www.linkedin.com/in/fviramontes))

On Monday, November 4, 2013 at 9:48 PM, Paco Viramontes wrote:

> Hi!
> 
> I could not find another person reporting this issue and I am totally baffled by this weird issue. The problem is pretty straight forward. I have an index with multiple mappings where I use parent child associations. The parent is topic, the child is reply. I noticed that some topics where not being found via the has\_child filter with exactly the same information just a different topic id. That is how I went down the rabbit hole and ended up noticing that I cannot get to a topic with its ID.
> 
> What is even more strange is that I have a script that recreates the index from a SQL source and everytime the same IDS are not found by Elasticsearch
> 
> For example if I do this:
> 
> curl -XGET '[http://localhost:9200/topics/topic\_en/173](http://localhost:9200/topics/topic_en/173)' | prettyjson \<paco/topic\_search\>  
> % Total % Received % Xferd Average Speed Time Time Time Current  
> Dload Upload Total Spent Left Speed  
> 100 80 100 80 0 0 26143 0 --:--:-- --:--:-- --:--:-- 40000  
> \_index: topics\_20131104211439  
> \_type: topic\_en  
> \_id: 173  
> exists: false
> 
> Nothing, but the doc is there:
> 
> curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search](http://127.0.0.1:9200/topics/topic_en/_search)' -d '{"query":{"term":{"id":"173"}}}' | prettyjson  
> % Total % Received % Xferd Average Speed Time Time Time Current  
> Dload Upload Total Spent Left Speed  
> 100 2127 100 2096 100 31 894k 13543 --:--:-- --:--:-- --:--:-- 1023k  
> took: 1  
> timed\_out: false  
> \_shards:  
> total: 5  
> successful: 5  
> failed: 0  
> hits:  
> total: 1  
> max\_score: 1  
> hits:  
> -  
> \_index: topics\_20131104211439  
> \_type: topic\_en  
> \_id: 173  
> \_score: 1  
> \_source:
> 
> This is a sample dataset, the gaps on non found IDS is non linear, actually most are not found. And again. If I drop and rebuild the index again the same documents cant be found via GET api and the same ids that ES likes are found.
> 
> I cant think of anything I am doing that is wrong here. Any ideas?
> 
> Cheers
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/B\_R0xxisU2g/unsubscribe](https://groups.google.com/d/topic/elasticsearch/B_R0xxisU2g/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) ([mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com)).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [November 5, 2013, 7:42am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/4 "2013-11-05T07:42:20Z")

</div>

Hm. Could help with a full curl recreation as I don't have a clear overview here.  
Basically, I'd say that that you are searching for parent docs but in child index/type rest end point.

Are you sure you search should run on topic\_en/\_search?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

5 novembre 2013 at 07:35:48, Francisco Viramontes ([kidpollo@gmail.com](mailto:kidpollo@gmail.com)) a écrit:

Right, if I provide the routing in case of the parent it does work.

curl -XGET '[http://localhost:9200/topics/topic\_en/147?routing=4](http://localhost:9200/topics/topic_en/147?routing=4)'

So whats wrong with my search query that works for children of some parents?

curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search?routing=4](http://127.0.0.1:9200/topics/topic_en/_search?routing=4)' -d '{"query":{"filtered":{"query":{"bool":{"should":[{"query\_string":{"query":"matra","fields":["topic.subject"]}},{"has\_child":{"type":"reply\_en","query":{"query\_string":{"query":"matra","fields":["reply.content"]}}}}]}},"filter":{"and":{"filters":[{"term":{"community\_id":4}}]}}}},"sort":[],"from":0,"size":25}'  
{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

* * *

Francisco Viramontes  
a.k.a. PAco

[twitter.com/kidpollo](http://twitter.com/kidpollo)

> **[Francisco Javier Viramontes](https://www.facebook.com/fviramontes)**
>
> Francisco Javier Viramontes is on Facebook. Join Facebook to connect with Francisco Javier Viramontes and others you may know. Facebook gives people the power to share and makes the world more open...

  
[linkedin.com/in/fviramontes](http://linkedin.com/in/fviramontes)

On Monday, November 4, 2013 at 9:48 PM, Paco Viramontes wrote:

Hi!

I could not find another person reporting this issue and I am totally baffled by this weird issue. The problem is pretty straight forward. I have an index with multiple mappings where I use parent child associations. The parent is topic, the child is reply. I noticed that some topics where not being found via the has\_child filter with exactly the same information just a different topic id. That is how I went down the rabbit hole and ended up noticing that I cannot get to a topic with its ID.

What is even more strange is that I have a script that recreates the index from a SQL source and everytime the same IDS are not found by elastic search

For example if I do this:

curl -XGET '[http://localhost:9200/topics/topic\_en/173](http://localhost:9200/topics/topic_en/173)' | prettyjson \<paco/topic\_search\>  
% Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 80 100 80 0 0 26143 0 --:--:-- --:--:-- --:--:-- 40000  
\_index: topics\_20131104211439  
\_type: topic\_en  
\_id: 173  
exists: false

Nothing, but the doc is there:

curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search](http://127.0.0.1:9200/topics/topic_en/_search)' -d '{"query":{"term":{"id":"173"}}}' | prettyjson  
% Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 2127 100 2096 100 31 894k 13543 --:--:-- --:--:-- --:--:-- 1023k  
took: 1  
timed\_out: false  
\_shards:  
total: 5  
successful: 5  
failed: 0  
hits:  
total: 1  
max\_score: 1  
hits:  
-  
\_index: topics\_20131104211439  
\_type: topic\_en  
\_id: 173  
\_score: 1  
\_source:

This is a sample dataset, the gaps on non found IDS is non linear, actually most are not found. And again. If I drop and rebuild the index again the same documents cant be found via GET api and the same ids that ES likes are found.

I cant think of anything I am doing that is wrong here. Any ideas?

## Cheers

You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/B\_R0xxisU2g/unsubscribe](https://groups.google.com/d/topic/elasticsearch/B_R0xxisU2g/unsubscribe).  
To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Francisco\_Viramontes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/francisco_viramontes/32/1998_2.png) [@Francisco\_Viramontes](https://discuss.elastic.co/u/Francisco_Viramontes)
#### Post date: [November 5, 2013, 7:51am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/5 "2013-11-05T07:51:48Z")

</div>

Seems I failed to specify the `_routing` field in the bulk indexing put call. ¬¬

From the documentation I would never have figured that out

* * *

Francisco Viramontes  
a.k.a. PAco

[twitter.com/kidpollo](http://twitter.com/kidpollo) ([http://www.twitter.com/](http://www.twitter.com/))  
[Facebook](http://facebook.com/fviramontes) ([Facebook](http://facebook.com/fviramontes))  
[linkedin.com/in/fviramontes](http://linkedin.com/in/fviramontes) ([http://www.linkedin.com/in/fviramontes](http://www.linkedin.com/in/fviramontes))

On Tuesday, November 5, 2013 at 12:35 AM, Francisco Viramontes wrote:

> Right, if I provide the routing in case of the parent it does work.
> 
> curl -XGET '[http://localhost:9200/topics/topic\_en/147?routing=4](http://localhost:9200/topics/topic_en/147?routing=4)'
> 
> So whats wrong with my search query that works for children of some parents?
> 
> curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search?routing=4](http://127.0.0.1:9200/topics/topic_en/_search?routing=4)' -d '{"query":{"filtered":{"query":{"bool":{"should":[{"query\_string":{"query":"matra","fields":["topic.subject"]}},{"has\_child":{"type":"reply\_en","query":{"query\_string":{"query":"matra","fields":["reply.content"]}}}}]}},"filter":{"and":{"filters":[{"term":{"community\_id":4}}]}}}},"sort":,"from":0,"size":25}'  
> {"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> * * *
> 
> Francisco Viramontes  
> a.k.a. PAco
> 
> [twitter.com/kidpollo](http://twitter.com/kidpollo) ([http://www.twitter.com/](http://www.twitter.com/))  
> [Facebook](http://facebook.com/fviramontes) ([Facebook](http://facebook.com/fviramontes))  
> [linkedin.com/in/fviramontes](http://linkedin.com/in/fviramontes) ([http://www.linkedin.com/in/fviramontes](http://www.linkedin.com/in/fviramontes))
> 
> On Monday, November 4, 2013 at 9:48 PM, Paco Viramontes wrote:
> 
> > Hi!
> > 
> > I could not find another person reporting this issue and I am totally baffled by this weird issue. The problem is pretty straight forward. I have an index with multiple mappings where I use parent child associations. The parent is topic, the child is reply. I noticed that some topics where not being found via the has\_child filter with exactly the same information just a different topic id. That is how I went down the rabbit hole and ended up noticing that I cannot get to a topic with its ID.
> > 
> > What is even more strange is that I have a script that recreates the index from a SQL source and everytime the same IDS are not found by Elasticsearch
> > 
> > For example if I do this:
> > 
> > curl -XGET '[http://localhost:9200/topics/topic\_en/173](http://localhost:9200/topics/topic_en/173)' | prettyjson \<paco/topic\_search\>  
> > % Total % Received % Xferd Average Speed Time Time Time Current  
> > Dload Upload Total Spent Left Speed  
> > 100 80 100 80 0 0 26143 0 --:--:-- --:--:-- --:--:-- 40000  
> > \_index: topics\_20131104211439  
> > \_type: topic\_en  
> > \_id: 173  
> > exists: false
> > 
> > Nothing, but the doc is there:
> > 
> > curl -XGET '[http://127.0.0.1:9200/topics/topic\_en/\_search](http://127.0.0.1:9200/topics/topic_en/_search)' -d '{"query":{"term":{"id":"173"}}}' | prettyjson  
> > % Total % Received % Xferd Average Speed Time Time Time Current  
> > Dload Upload Total Spent Left Speed  
> > 100 2127 100 2096 100 31 894k 13543 --:--:-- --:--:-- --:--:-- 1023k  
> > took: 1  
> > timed\_out: false  
> > \_shards:  
> > total: 5  
> > successful: 5  
> > failed: 0  
> > hits:  
> > total: 1  
> > max\_score: 1  
> > hits:  
> > -  
> > \_index: topics\_20131104211439  
> > \_type: topic\_en  
> > \_id: 173  
> > \_score: 1  
> > \_source:
> > 
> > This is a sample dataset, the gaps on non found IDS is non linear, actually most are not found. And again. If I drop and rebuild the index again the same documents cant be found via GET api and the same ids that ES likes are found.
> > 
> > I cant think of anything I am doing that is wrong here. Any ideas?
> > 
> > Cheers
> > 
> > --  
> > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/B\_R0xxisU2g/unsubscribe](https://groups.google.com/d/topic/elasticsearch/B_R0xxisU2g/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) ([mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com)).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:08am UTC](https://discuss.elastic.co/t/get-document-by-id-is-does-not-work-for-some-docs-but-the-docs-are-there/14254/6 "2017-07-06T02:08:55Z")

</div>


