# Query on Id field of nested documents fails

**URL:** <https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293>\
**Category:** Elasticsearch\
**Created:** [June 24, 2014, 1:43pm UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293 "2014-06-24T13:43:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dazraf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dazraf/32/1444_2.png) [@dazraf](https://discuss.elastic.co/u/dazraf)\
**Post date:** [June 24, 2014, 1:43pm UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/1 "2014-06-24T13:43:01Z")

</div>

Hi,

Very grateful for any help with the following (rather urgent) issue.  
Gist: [https://gist.github.com/dazraf/55ebb900b3c17583bf58](https://gist.github.com/dazraf/55ebb900b3c17583bf58)

The script clears the indices and sets up dynamic mapping so that all child  
documents are treated as nested.  
Then there are two queries on fields of  
_message.statistics.timings.measure.thing_.  
The first, on _uniqueThing_ field succeeds.  
The second on the _id_ field fails with zero documents.

Not sure why the second query is failing to locate any documents.

Any help much appreciated!

thanks  
Fuzz.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0397e742-d483-45aa-a4db-da300416d9da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0397e742-d483-45aa-a4db-da300416d9da%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dazraf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dazraf/32/1444_2.png) [@dazraf](https://discuss.elastic.co/u/dazraf)\
**Post date:** [June 26, 2014, 3:35pm UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/2 "2014-06-26T15:35:30Z")

</div>

Hi,

Could anyone help please? We're kind of stuck right now - trying to get to  
a point that we demonstrate ES working for our use-cases to get management  
blessing.

thanks  
Fuzz.

On Tuesday, 24 June 2014 14:43:01 UTC+1, dazraf wrote:

> Hi,
> 
> Very grateful for any help with the following (rather urgent) issue.  
> Gist: [Nested document search fails on "id" field · GitHub](https://gist.github.com/dazraf/55ebb900b3c17583bf58)
> 
> The script clears the indices and sets up dynamic mapping so that all  
> child documents are treated as nested.  
> Then there are two queries on fields of  
> _message.statistics.timings.measure.thing_.  
> The first, on _uniqueThing_ field succeeds.  
> The second on the _id_ field fails with zero documents.
> 
> Not sure why the second query is failing to locate any documents.
> 
> Any help much appreciated!
> 
> thanks  
> Fuzz.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/74ca426d-05ae-4f2c-bf55-738b4669e752%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/74ca426d-05ae-4f2c-bf55-738b4669e752%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dazraf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dazraf/32/1444_2.png) [@dazraf](https://discuss.elastic.co/u/dazraf)\
**Post date:** [June 26, 2014, 4:29pm UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/3 "2014-06-26T16:29:37Z")

</div>

Is this related to this issue?

> <https://github.com/elastic/elasticsearch/issues/3022>
>
> Add support for including the matching nested inner objects per hit element.

On Tuesday, 24 June 2014 14:43:01 UTC+1, dazraf wrote:

> Hi,
> 
> Very grateful for any help with the following (rather urgent) issue.  
> Gist: [Nested document search fails on "id" field · GitHub](https://gist.github.com/dazraf/55ebb900b3c17583bf58)
> 
> The script clears the indices and sets up dynamic mapping so that all  
> child documents are treated as nested.  
> Then there are two queries on fields of  
> _message.statistics.timings.measure.thing_.  
> The first, on _uniqueThing_ field succeeds.  
> The second on the _id_ field fails with zero documents.
> 
> Not sure why the second query is failing to locate any documents.
> 
> Any help much appreciated!
> 
> thanks  
> Fuzz.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 27, 2014, 8:15pm UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/4 "2014-06-27T20:15:35Z")

</div>

It is not related to that issue. In that issue, your query would work, but  
all the nested documents are returned, not just the relevant.

It seems like the query fails on fields named "id". If you rename that  
field, the query works, so it has nothing to do with your mapping. I would  
report it as a bug or use another field name.

--  
Ivan

On Thu, Jun 26, 2014 at 9:29 AM, dazraf [farzad.pezeshkpour@gmail.com](mailto:farzad.pezeshkpour@gmail.com)  
wrote:

> Is this related to this issue?  
> [https://github.com/elasticsearch/elasticsearch/issues/3022](https://github.com/elasticsearch/elasticsearch/issues/3022)
> 
> On Tuesday, 24 June 2014 14:43:01 UTC+1, dazraf wrote:
> 
> > Hi,
> > 
> > Very grateful for any help with the following (rather urgent) issue.  
> > Gist: [Nested document search fails on "id" field · GitHub](https://gist.github.com/dazraf/55ebb900b3c17583bf58)
> > 
> > The script clears the indices and sets up dynamic mapping so that all  
> > child documents are treated as nested.  
> > Then there are two queries on fields of  
> > _message.statistics.timings.measure.thing_.  
> > The first, on _uniqueThing_ field succeeds.  
> > The second on the _id_ field fails with zero documents.
> > 
> > Not sure why the second query is failing to locate any documents.
> > 
> > Any help much appreciated!
> > 
> > thanks  
> > Fuzz.
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCjSKdgk%3D--P9UGzN06TjQ%3DbePyWUneCdALGos2DehbGQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCjSKdgk%3D--P9UGzN06TjQ%3DbePyWUneCdALGos2DehbGQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dazraf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dazraf/32/1444_2.png) [@dazraf](https://discuss.elastic.co/u/dazraf)\
**Post date:** [June 28, 2014, 11:51am UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/5 "2014-06-28T11:51:47Z")

</div>

Hi Ivan,

Thanks very much for the response! It's great to know you're able to  
reproduce the use-case.

Although one can always write custom mappings or change the client, our aim  
is to:

1. Avoid using schema-specific mappings; and
2. Avoid forcing the clients with any schema constraints

Querying/filtering by a nested "id" field should be supported as any other  
field I think - seeing that the documents do not preclude this use.  
Therefore, perhaps its reasonable to raise a bug report and see it fixed.  
Would you agree?

many thanks and kind regards,

Fuzz.

On Friday, 27 June 2014 21:16:24 UTC+1, Ivan Brusic wrote:

> It is not related to that issue. In that issue, your query would work, but  
> all the nested documents are returned, not just the relevant.
> 
> It seems like the query fails on fields named "id". If you rename that  
> field, the query works, so it has nothing to do with your mapping. I would  
> report it as a bug or use another field name.
> 
> --  
> Ivan
> 
> On Thu, Jun 26, 2014 at 9:29 AM, dazraf \<[farzad.pe...@gmail.com](mailto:farzad.pe...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Is this related to this issue?  
> > [https://github.com/elasticsearch/elasticsearch/issues/3022](https://github.com/elasticsearch/elasticsearch/issues/3022)
> > 
> > On Tuesday, 24 June 2014 14:43:01 UTC+1, dazraf wrote:
> > 
> > > Hi,
> > > 
> > > Very grateful for any help with the following (rather urgent) issue.  
> > > Gist: [Nested document search fails on "id" field · GitHub](https://gist.github.com/dazraf/55ebb900b3c17583bf58)
> > > 
> > > The script clears the indices and sets up dynamic mapping so that all  
> > > child documents are treated as nested.  
> > > Then there are two queries on fields of  
> > > _message.statistics.timings.measure.thing_.  
> > > The first, on _uniqueThing_ field succeeds.  
> > > The second on the _id_ field fails with zero documents.
> > > 
> > > Not sure why the second query is failing to locate any documents.
> > > 
> > > Any help much appreciated!
> > > 
> > > thanks  
> > > Fuzz.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/14de51ef-8569-476b-9495-edd2c4967837%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/560a3ed9-58e9-4861-92e6-ce1709b43275%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/560a3ed9-58e9-4861-92e6-ce1709b43275%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:19am UTC](https://discuss.elastic.co/t/query-on-id-field-of-nested-documents-fails/18293/6 "2017-07-06T01:19:11Z")

</div>


