# Problems with nested fields with the same names

**URL:** <https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439>\
**Category:** Elasticsearch\
**Created:** [May 19, 2011, 6:06pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439 "2011-05-19T18:06:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![butlermh](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@butlermh](https://discuss.elastic.co/u/butlermh)\
**Post date:** [May 19, 2011, 6:06pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/1 "2011-05-19T18:06:09Z")

</div>

Hi Shay, Clint, everyone,

I am having some problems with documents that contain nested fields  
with the same name as fields in the enclosing document.

Here are some examples.

I create a simple document representing an album:

curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}'

RESPONSE:  
{"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}

Then I query it

curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)

RESPONSE:  
{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
"\_source" : { "album":"Best of Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}}]}}

All okay, Good. Now let's try doing the same thing but with the nested  
fields using the same name as one in the encompassing object.

curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}'

RESPONSE:  
{"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}

curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)

RESPONSE:  
{"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

No results? Is this right? Are nested fields with the same name not allowed?

Now for something else strange. I decide to go back to my original  
design, put the original version of the document back.

curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}'

RESPONSE:  
{"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}

curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)

{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

Still no results? Why is querying failing now?

I have been working with some quite complicated templates to overcome  
this problem, but they do not seem to solve it. This is the simplest  
test case I could come up with to demonstrate the behavior.

Best wishes, and thank you for ES!

Mark

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 19, 2011, 6:19pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/2 "2011-05-19T18:19:43Z")

</div>

Thats because the actual name of the field when its indexed for the inner fields is "tracks.title", not title, and you search for something that would match it.

If you want all the those fields to be indexed as title, without prefixing it with the objects path, then you can set the path in the object mapping level of tracks: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).

-shay.banon  
On Thursday, May 19, 2011 at 9:06 PM, Mark Butler wrote:  
Hi Shay, Clint, everyone,

> I am having some problems with documents that contain nested fields  
> with the same name as fields in the enclosing document.
> 
> Here are some examples.
> 
> I create a simple document representing an album:
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> 
> Then I query it
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
> "\_source" : { "album":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> All okay, Good. Now let's try doing the same thing but with the nested  
> fields using the same name as one in the encompassing object.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> No results? Is this right? Are nested fields with the same name not allowed?
> 
> Now for something else strange. I decide to go back to my original  
> design, put the original version of the document back.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> Still no results? Why is querying failing now?
> 
> I have been working with some quite complicated templates to overcome  
> this problem, but they do not seem to solve it. This is the simplest  
> test case I could come up with to demonstrate the behavior.
> 
> Best wishes, and thank you for ES!
> 
> Mark

---

<div class="post-metadata">

**Author:** ![butlermh](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@butlermh](https://discuss.elastic.co/u/butlermh)\
**Post date:** [May 19, 2011, 7:42pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/3 "2011-05-19T19:42:23Z")

</div>

Thanks Shay.

I change my query

curl -XGET [http://localhost:9200/music/album/\_search/?q=tracks.title:blinded](http://localhost:9200/music/album/_search/?q=tracks.title:blinded)

RESPONSE:

{"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.26010898,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.26010898,  
"\_source" : { "title":"Best of Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}}]}}

That works. Good.

Now I create a template using object mapping:

curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
{"properties": {"tracks": {"type" : "object","path" :  
"just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
: "title"} } } } } }'

RESPONSE:  
{"ok":true,"acknowledged":true}

and now try the original query:

curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)

RESPONSE:  
{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}

But it still fails. What I am doing wrong in my mapping? Here is the  
mapping in pretty print:

{ "album":  
{"properties":  
{"tracks":  
{"type" : "object","  
path" : "just\_name",  
"properties" :  
{"title" :  
{"type" : "string", "index\_name" : "title"} } } } } }

Also, I must confess I am still a little confused, in my previous  
email, why does my first query return results?

Kind regards,

Mark

On 19 May 2011 19:19, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> Thats because the actual name of the field when its indexed for the inner  
> fields is "tracks.title", not title, and you search for something that would  
> match it.  
> If you want all the those fields to be indexed as title, without prefixing  
> it with the objects path, then you can set the path in the object mapping  
> level of  
> tracks: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).  
> -shay.banon
> 
> On Thursday, May 19, 2011 at 9:06 PM, Mark Butler wrote:
> 
> Hi Shay, Clint, everyone,
> 
> I am having some problems with documents that contain nested fields  
> with the same name as fields in the enclosing document.
> 
> Here are some examples.
> 
> I create a simple document representing an album:
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> 
> Then I query it
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
> "\_source" : { "album":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> All okay, Good. Now let's try doing the same thing but with the nested  
> fields using the same name as one in the encompassing object.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> No results? Is this right? Are nested fields with the same name not allowed?
> 
> Now for something else strange. I decide to go back to my original  
> design, put the original version of the document back.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> Still no results? Why is querying failing now?
> 
> I have been working with some quite complicated templates to overcome  
> this problem, but they do not seem to solve it. This is the simplest  
> test case I could come up with to demonstrate the behavior.
> 
> Best wishes, and thank you for ES!
> 
> Mark

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 19, 2011, 7:43pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/4 "2011-05-19T19:43:41Z")

</div>

make sure to set the mapping on a clean index without it being defined before.  
On Thursday, May 19, 2011 at 10:42 PM, Mark Butler wrote:

> Thanks Shay.
> 
> I change my query
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=tracks.title:blinded](http://localhost:9200/music/album/_search/?q=tracks.title:blinded)
> 
> RESPONSE:
> 
> {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.26010898,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.26010898,  
> "\_source" : { "title":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> That works. Good.
> 
> Now I create a template using object mapping:
> 
> curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
> {"properties": {"tracks": {"type" : "object","path" :  
> "just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
> : "title"} } } } } }'
> 
> RESPONSE:  
> {"ok":true,"acknowledged":true}
> 
> and now try the original query:
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> But it still fails. What I am doing wrong in my mapping? Here is the  
> mapping in pretty print:
> 
> { "album":  
> {"properties":  
> {"tracks":  
> {"type" : "object","  
> path" : "just\_name",  
> "properties" :  
> {"title" :  
> {"type" : "string", "index\_name" : "title"} } } } } }
> 
> Also, I must confess I am still a little confused, in my previous  
> email, why does my first query return results?
> 
> Kind regards,
> 
> Mark
> 
> On 19 May 2011 19:19, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> 
> > Thats because the actual name of the field when its indexed for the inner  
> > fields is "tracks.title", not title, and you search for something that would  
> > match it.  
> > If you want all the those fields to be indexed as title, without prefixing  
> > it with the objects path, then you can set the path in the object mapping  
> > level of  
> > tracks: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).  
> > -shay.banon
> > 
> > On Thursday, May 19, 2011 at 9:06 PM, Mark Butler wrote:
> > 
> > Hi Shay, Clint, everyone,
> > 
> > I am having some problems with documents that contain nested fields  
> > with the same name as fields in the enclosing document.
> > 
> > Here are some examples.
> > 
> > I create a simple document representing an album:
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> > 
> > Then I query it
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > RESPONSE:  
> > {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
> > "\_source" : { "album":"Best of Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}}]}}
> > 
> > All okay, Good. Now let's try doing the same thing but with the nested  
> > fields using the same name as one in the encompassing object.
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > RESPONSE:  
> > {"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > No results? Is this right? Are nested fields with the same name not allowed?
> > 
> > Now for something else strange. I decide to go back to my original  
> > design, put the original version of the document back.
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > Still no results? Why is querying failing now?
> > 
> > I have been working with some quite complicated templates to overcome  
> > this problem, but they do not seem to solve it. This is the simplest  
> > test case I could come up with to demonstrate the behavior.
> > 
> > Best wishes, and thank you for ES!
> > 
> > Mark

---

<div class="post-metadata">

**Author:** ![butlermh](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@butlermh](https://discuss.elastic.co/u/butlermh)\
**Post date:** [May 19, 2011, 8:01pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/5 "2011-05-19T20:01:27Z")

</div>

Hi Shay,

Sorry - that was the problem. Thanks, especially for replying so promptly.

These commands worked for me:

curl -XDELETE '[http://localhost:9200/music/](http://localhost:9200/music/)'

{"ok":true,"acknowledged":true}

curl -XPUT [http://localhost:9200/music/](http://localhost:9200/music/)

{"ok":true,"acknowledged":true}

curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
{"properties": {"tracks": {"type" : "object","path" :  
"just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
: "title"} } } } } }'

{"ok":true,"acknowledged":true}

curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}'

{"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}

curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)

{"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.095891505,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.095891505,  
"\_source" : { "title":"Best of Thomas Dolby", "tracks":  
[{"title":"Hyperactive","number":1},{"title":"She blinded me with  
science","number":2}]}}]}}

On 19 May 2011 20:43, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> make sure to set the mapping on a clean index without it being defined  
> before.
> 
> On Thursday, May 19, 2011 at 10:42 PM, Mark Butler wrote:
> 
> Thanks Shay.
> 
> I change my query
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=tracks.title:blinded](http://localhost:9200/music/album/_search/?q=tracks.title:blinded)
> 
> RESPONSE:
> 
> {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.26010898,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.26010898,  
> "\_source" : { "title":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> That works. Good.
> 
> Now I create a template using object mapping:
> 
> curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
> {"properties": {"tracks": {"type" : "object","path" :  
> "just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
> : "title"} } } } } }'
> 
> RESPONSE:  
> {"ok":true,"acknowledged":true}
> 
> and now try the original query:
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> But it still fails. What I am doing wrong in my mapping? Here is the  
> mapping in pretty print:
> 
> { "album":  
> {"properties":  
> {"tracks":  
> {"type" : "object","  
> path" : "just\_name",  
> "properties" :  
> {"title" :  
> {"type" : "string", "index\_name" : "title"} } } } } }
> 
> Also, I must confess I am still a little confused, in my previous  
> email, why does my first query return results?
> 
> Kind regards,
> 
> Mark
> 
> On 19 May 2011 19:19, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> 
> Thats because the actual name of the field when its indexed for the inner  
> fields is "tracks.title", not title, and you search for something that would  
> match it.  
> If you want all the those fields to be indexed as title, without prefixing  
> it with the objects path, then you can set the path in the object mapping  
> level of  
> tracks: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).  
> -shay.banon
> 
> On Thursday, May 19, 2011 at 9:06 PM, Mark Butler wrote:
> 
> Hi Shay, Clint, everyone,
> 
> I am having some problems with documents that contain nested fields  
> with the same name as fields in the enclosing document.
> 
> Here are some examples.
> 
> I create a simple document representing an album:
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> 
> Then I query it
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
> "\_source" : { "album":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> All okay, Good. Now let's try doing the same thing but with the nested  
> fields using the same name as one in the encompassing object.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> RESPONSE:  
> {"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> No results? Is this right? Are nested fields with the same name not allowed?
> 
> Now for something else strange. I decide to go back to my original  
> design, put the original version of the document back.
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> RESPONSE:  
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> 
> Still no results? Why is querying failing now?
> 
> I have been working with some quite complicated templates to overcome  
> this problem, but they do not seem to solve it. This is the simplest  
> test case I could come up with to demonstrate the behavior.
> 
> Best wishes, and thank you for ES!
> 
> Mark

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 19, 2011, 8:09pm UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/6 "2011-05-19T20:09:55Z")

</div>

Great, note you can provide the mappings in the create index request, thus not allowing any sneaky document to come between the create index and put mapping API calls.  
On Thursday, May 19, 2011 at 11:01 PM, Mark Butler wrote:

> Hi Shay,
> 
> Sorry - that was the problem. Thanks, especially for replying so promptly.
> 
> These commands worked for me:
> 
> curl -XDELETE '[http://localhost:9200/music/](http://localhost:9200/music/)'
> 
> {"ok":true,"acknowledged":true}
> 
> curl -XPUT [http://localhost:9200/music/](http://localhost:9200/music/)
> 
> {"ok":true,"acknowledged":true}
> 
> curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
> {"properties": {"tracks": {"type" : "object","path" :  
> "just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
> : "title"} } } } } }'
> 
> {"ok":true,"acknowledged":true}
> 
> curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}'
> 
> {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> 
> curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> 
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.095891505,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.095891505,  
> "\_source" : { "title":"Best of Thomas Dolby", "tracks":  
> [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> science","number":2}]}}]}}
> 
> On 19 May 2011 20:43, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> 
> > make sure to set the mapping on a clean index without it being defined  
> > before.
> > 
> > On Thursday, May 19, 2011 at 10:42 PM, Mark Butler wrote:
> > 
> > Thanks Shay.
> > 
> > I change my query
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=tracks.title:blinded](http://localhost:9200/music/album/_search/?q=tracks.title:blinded)
> > 
> > RESPONSE:
> > 
> > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.26010898,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.26010898,  
> > "\_source" : { "title":"Best of Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}}]}}
> > 
> > That works. Good.
> > 
> > Now I create a template using object mapping:
> > 
> > curl -XPUT [http://localhost:9200/music/album/\_mapping](http://localhost:9200/music/album/_mapping) -d '{"album":  
> > {"properties": {"tracks": {"type" : "object","path" :  
> > "just\_name","properties" : {"title" : {"type" : "string", "index\_name"  
> > : "title"} } } } } }'
> > 
> > RESPONSE:  
> > {"ok":true,"acknowledged":true}
> > 
> > and now try the original query:
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > RESPONSE:  
> > {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > But it still fails. What I am doing wrong in my mapping? Here is the  
> > mapping in pretty print:
> > 
> > { "album":  
> > {"properties":  
> > {"tracks":  
> > {"type" : "object","  
> > path" : "just\_name",  
> > "properties" :  
> > {"title" :  
> > {"type" : "string", "index\_name" : "title"} } } } } }
> > 
> > Also, I must confess I am still a little confused, in my previous  
> > email, why does my first query return results?
> > 
> > Kind regards,
> > 
> > Mark
> > 
> > On 19 May 2011 19:19, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> > 
> > Thats because the actual name of the field when its indexed for the inner  
> > fields is "tracks.title", not title, and you search for something that would  
> > match it.  
> > If you want all the those fields to be indexed as title, without prefixing  
> > it with the objects path, then you can set the path in the object mapping  
> > level of  
> > tracks: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).  
> > -shay.banon
> > 
> > On Thursday, May 19, 2011 at 9:06 PM, Mark Butler wrote:
> > 
> > Hi Shay, Clint, everyone,
> > 
> > I am having some problems with documents that contain nested fields  
> > with the same name as fields in the enclosing document.
> > 
> > Here are some examples.
> > 
> > I create a simple document representing an album:
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":1}
> > 
> > Then I query it
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > RESPONSE:  
> > {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max\_score":0.13424811,"hits":[{"\_index":"music","\_type":"album","\_id":"1","\_score":0.13424811,  
> > "\_source" : { "album":"Best of Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}}]}}
> > 
> > All okay, Good. Now let's try doing the same thing but with the nested  
> > fields using the same name as one in the encompassing object.
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "title":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":2}
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > RESPONSE:  
> > {"took":6,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > No results? Is this right? Are nested fields with the same name not allowed?
> > 
> > Now for something else strange. I decide to go back to my original  
> > design, put the original version of the document back.
> > 
> > curl -XPUT [http://localhost:9200/music/album/1](http://localhost:9200/music/album/1) -d '{ "album":"Best of  
> > Thomas Dolby", "tracks":  
> > [{"title":"Hyperactive","number":1},{"title":"She blinded me with  
> > science","number":2}]}'
> > 
> > RESPONSE:  
> > {"ok":true,"\_index":"music","\_type":"album","\_id":"1","\_version":3}
> > 
> > curl -XGET [http://localhost:9200/music/album/\_search/?q=title:blinded](http://localhost:9200/music/album/_search/?q=title:blinded)
> > 
> > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > Still no results? Why is querying failing now?
> > 
> > I have been working with some quite complicated templates to overcome  
> > this problem, but they do not seem to solve it. This is the simplest  
> > test case I could come up with to demonstrate the behavior.
> > 
> > Best wishes, and thank you for ES!
> > 
> > Mark

---

<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, 4:05am UTC](https://discuss.elastic.co/t/problems-with-nested-fields-with-the-same-names/4439/7 "2017-07-06T04:05:48Z")

</div>


