# Documents and property naming

**URL:** <https://discuss.elastic.co/t/documents-and-property-naming/4583>\
**Category:** Elasticsearch\
**Created:** [June 9, 2011, 1:13am UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583 "2011-06-09T01:13:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [June 9, 2011, 1:13am UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/1 "2011-06-09T01:13:36Z")

</div>

I saw a post a couple days ago on the list where someone was saying that the  
same property name reused across multiple types must have the same mapping.

I guess I just wanted someone to confirm whether this is true or not. It  
seems like this would have a huge impact on most document designs if it is  
accurate.

I thought the type name was actually used behind the scenes as a prefix for  
each attribute. Consider this example:

$ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"user" : "kimchy",  
"post\_date" : "2009-11-15T14:12:12",  
"message" : "trying out Elastic Search"  
}'

Isn't the user property actually indexed at the Lucene layer as  
'tweet.user'? Wouldn't this mean that each property name within a type has a  
unique mapping?

---

<div class="post-metadata">

**Author:** ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)\
**Post date:** [June 9, 2011, 8:53am UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/2 "2011-06-09T08:53:37Z")

</div>

- deleted -

---

<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:** [June 9, 2011, 7:07pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/3 "2011-06-09T19:07:07Z")

</div>

Heya,

Yes, that is the case (and they are not stored in Lucene using a type prefix).. Or, more specifically, if they are using a different type, you would need to prefix the type of the doc you want to search on (for example: twitter.user as the field name in queries). In general though, you want to keep them using the same type.

-shay.banon

On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:

> I saw a post a couple days ago on the list where someone was saying that the same property name reused across multiple types must have the same mapping.
> 
> I guess I just wanted someone to confirm whether this is true or not. It seems like this would have a huge impact on most document designs if it is accurate.
> 
> I thought the type name was actually used behind the scenes as a prefix for each attribute. Consider this example:
> 
> > $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > "user" : "kimchy",
> > 
> > "post\_date" : "2009-11-15T14:12:12",
> > 
> > "message" : "trying out Elastic Search"
> > 
> > }'
> 
> Isn't the user property actually indexed at the Lucene layer as 'tweet.user'? Wouldn't this mean that each property name within a type has a unique mapping?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [June 9, 2011, 8:59pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/4 "2011-06-09T20:59:15Z")

</div>

Are "client.username" and "supplier.username" considered the same or  
different field names from the perspective of mapping?

On Thu, Jun 9, 2011 at 3:07 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Heya,
> 
> Yes, that is the case (and they are not stored in Lucene using a type  
> prefix).. Or, more specifically, if they are using a different type, you  
> would need to prefix the type of the doc you want to search on (for example:  
> twitter.user as the field name in queries). In general though, you want to  
> keep them using the same type.
> 
> -shay.banon
> 
> On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:
> 
> I saw a post a couple days ago on the list where someone was saying that  
> the same property name reused across multiple types must have the same  
> mapping.
> 
> I guess I just wanted someone to confirm whether this is true or not. It  
> seems like this would have a huge impact on most document designs if it is  
> accurate.
> 
> I thought the type name was actually used behind the scenes as a prefix for  
> each attribute. Consider this example:
> 
> $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "kimchy",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> Isn't the user property actually indexed at the Lucene layer as  
> 'tweet.user'? Wouldn't this mean that each property name within a type has a  
> unique mapping?

---

<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:** [June 9, 2011, 10:42pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/5 "2011-06-09T22:42:54Z")

</div>

If client and supplier are types, then the field name that will be indexed in Lucene will be username. If username is in one case a string, and in one case a long, and you query on username, you will get failures. If you query on client.username, you will not (and it will get filtered automatically to only match on client documents).

On Thursday, June 9, 2011 at 11:59 PM, James Cook wrote:

> Are "client.username" and "supplier.username" considered the same or different field names from the perspective of mapping?
> 
> On Thu, Jun 9, 2011 at 3:07 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > Heya,
> > 
> > Yes, that is the case (and they are not stored in Lucene using a type prefix).. Or, more specifically, if they are using a different type, you would need to prefix the type of the doc you want to search on (for example: twitter.user as the field name in queries). In general though, you want to keep them using the same type.
> > 
> > -shay.banon
> > 
> > On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:
> > 
> > > I saw a post a couple days ago on the list where someone was saying that the same property name reused across multiple types must have the same mapping.
> > > 
> > > I guess I just wanted someone to confirm whether this is true or not. It seems like this would have a huge impact on most document designs if it is accurate.
> > > 
> > > I thought the type name was actually used behind the scenes as a prefix for each attribute. Consider this example:
> > > 
> > > > $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > > > "user" : "kimchy",
> > > > 
> > > > "post\_date" : "2009-11-15T14:12:12",
> > > > 
> > > > "message" : "trying out Elastic Search"
> > > > 
> > > > }'
> > > 
> > > Isn't the user property actually indexed at the Lucene layer as 'tweet.user'? Wouldn't this mean that each property name within a type has a unique mapping?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [June 10, 2011, 12:58pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/6 "2011-06-10T12:58:08Z")

</div>

Sorry I wasn't clear.

In my example, I meant that supplier.username and client.username were part  
of the same type.

So, document =  
{  
supplier: {  
username: "user1",  
},  
client: {  
username: "[joe@cool.com](mailto:joe@cool.com)"  
}  
}

I would want to use two different mappings for this case. Are there any  
issues with this?

Thanks

On Thu, Jun 9, 2011 at 6:42 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> If client and supplier are types, then the field name that will be  
> indexed in Lucene will be username. If username is in one case a string, and  
> in one case a long, and you query on username, you will get failures. If you  
> query on client.username, you will not (and it will get filtered  
> automatically to only match on client documents).
> 
> On Thursday, June 9, 2011 at 11:59 PM, James Cook wrote:
> 
> Are "client.username" and "supplier.username" considered the same or  
> different field names from the perspective of mapping?
> 
> On Thu, Jun 9, 2011 at 3:07 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> Heya,
> 
> Yes, that is the case (and they are not stored in Lucene using a type  
> prefix).. Or, more specifically, if they are using a different type, you  
> would need to prefix the type of the doc you want to search on (for example:  
> twitter.user as the field name in queries). In general though, you want to  
> keep them using the same type.
> 
> -shay.banon
> 
> On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:
> 
> I saw a post a couple days ago on the list where someone was saying that  
> the same property name reused across multiple types must have the same  
> mapping.
> 
> I guess I just wanted someone to confirm whether this is true or not. It  
> seems like this would have a huge impact on most document designs if it is  
> accurate.
> 
> I thought the type name was actually used behind the scenes as a prefix for  
> each attribute. Consider this example:
> 
> $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "kimchy",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> Isn't the user property actually indexed at the Lucene layer as  
> 'tweet.user'? Wouldn't this mean that each property name within a type has a  
> unique mapping?

---

<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:** [June 10, 2011, 2:09pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/7 "2011-06-10T14:09:41Z")

</div>

No issues in this case.

On Friday, June 10, 2011 at 3:58 PM, James Cook wrote:

> Sorry I wasn't clear.
> 
> In my example, I meant that supplier.username and client.username were part of the same type.
> 
> So, document =  
> {  
> supplier: {  
> username: "user1",  
> },  
> client: {  
> username: "[joe@cool.com](mailto:joe@cool.com) ([mailto:joe@cool.com](mailto:joe@cool.com))"  
> }  
> }
> 
> I would want to use two different mappings for this case. Are there any issues with this?
> 
> Thanks
> 
> On Thu, Jun 9, 2011 at 6:42 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > If client and supplier are types, then the field name that will be indexed in Lucene will be username. If username is in one case a string, and in one case a long, and you query on username, you will get failures. If you query on client.username, you will not (and it will get filtered automatically to only match on client documents).
> > 
> > On Thursday, June 9, 2011 at 11:59 PM, James Cook wrote:
> > 
> > > Are "client.username" and "supplier.username" considered the same or different field names from the perspective of mapping?
> > > 
> > > On Thu, Jun 9, 2011 at 3:07 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> > > 
> > > > Heya,
> > > > 
> > > > Yes, that is the case (and they are not stored in Lucene using a type prefix).. Or, more specifically, if they are using a different type, you would need to prefix the type of the doc you want to search on (for example: twitter.user as the field name in queries). In general though, you want to keep them using the same type.
> > > > 
> > > > -shay.banon
> > > > 
> > > > On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:
> > > > 
> > > > > I saw a post a couple days ago on the list where someone was saying that the same property name reused across multiple types must have the same mapping.
> > > > > 
> > > > > I guess I just wanted someone to confirm whether this is true or not. It seems like this would have a huge impact on most document designs if it is accurate.
> > > > > 
> > > > > I thought the type name was actually used behind the scenes as a prefix for each attribute. Consider this example:
> > > > > 
> > > > > > $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > > > > > "user" : "kimchy",
> > > > > > 
> > > > > > "post\_date" : "2009-11-15T14:12:12",
> > > > > > 
> > > > > > "message" : "trying out Elastic Search"
> > > > > > 
> > > > > > }'
> > > > > 
> > > > > Isn't the user property actually indexed at the Lucene layer as 'tweet.user'? Wouldn't this mean that each property name within a type has a unique mapping?

---

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [June 10, 2011, 3:15pm UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/8 "2011-06-10T15:15:28Z")

</div>

This was something that caught me by surprise last month and forced me to  
redesign my json to account for it. Just for searching posterity for people  
who search and find this discussion I found the original discussion that  
made me realize this. Shay provides additional information that you may find  
useful in that thread:

"The mappings are recommended to be the same. Its kindda in the middle now,  
I have started (way back) to try and support it better when explicitly  
specifying the type in relevant queries filters, but it does not work when  
they have different analyzers. And, in any case, you would need to  
explicitly specify the type, for example:

{ "term" : { "my\_type.my\_field" : "value" }}.

It does not work though when you execute a search on that type alone  
(/my\_index/my\_type/\_search), i.e., the typeness is not bubbled down.

Those are the two main issues that I can think that I are missing. But, even  
with that, things like facets will become problematic (since there can be  
only one "type" for that field when faceting on it). So, in any case, even  
with those issues "fixed", its recommended that they will have the same  
mapping (analyzer, type, and so on)."

The full thread can be found at:  
[http://elasticsearch-users.115913.n3.nabble.com/Recommended-maximum-fields-per-index-tp2930788p2937852.html](http://elasticsearch-users.115913.n3.nabble.com/Recommended-maximum-fields-per-index-tp2930788p2937852.html)

During that thread it was also discussed to open a issue to document this  
which can be found at:

> <https://github.com/elastic/elasticsearch/issues/927;cid=1306263216528-951>
>
> When several types of an index define a field with the same name, it is treated …as a single field in the Lucene index. As such, their mapping should be compatible (have the same core type).
> 
> This needs to be added to the documentation. Probably under the mapping section.

Bob

On Fri, Jun 10, 2011 at 9:09 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> No issues in this case.
> 
> On Friday, June 10, 2011 at 3:58 PM, James Cook wrote:
> 
> Sorry I wasn't clear.
> 
> In my example, I meant that supplier.username and client.username were part  
> of the same type.
> 
> So, document =  
> {  
> supplier: {  
> username: "user1",  
> },  
> client: {  
> username: "[joe@cool.com](mailto:joe@cool.com)"  
> }  
> }
> 
> I would want to use two different mappings for this case. Are there any  
> issues with this?
> 
> Thanks
> 
> On Thu, Jun 9, 2011 at 6:42 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> If client and supplier are types, then the field name that will be  
> indexed in Lucene will be username. If username is in one case a string, and  
> in one case a long, and you query on username, you will get failures. If you  
> query on client.username, you will not (and it will get filtered  
> automatically to only match on client documents).
> 
> On Thursday, June 9, 2011 at 11:59 PM, James Cook wrote:
> 
> Are "client.username" and "supplier.username" considered the same or  
> different field names from the perspective of mapping?
> 
> On Thu, Jun 9, 2011 at 3:07 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> Heya,
> 
> Yes, that is the case (and they are not stored in Lucene using a type  
> prefix).. Or, more specifically, if they are using a different type, you  
> would need to prefix the type of the doc you want to search on (for example:  
> twitter.user as the field name in queries). In general though, you want to  
> keep them using the same type.
> 
> -shay.banon
> 
> On Thursday, June 9, 2011 at 4:13 AM, James Cook wrote:
> 
> I saw a post a couple days ago on the list where someone was saying that  
> the same property name reused across multiple types must have the same  
> mapping.
> 
> I guess I just wanted someone to confirm whether this is true or not. It  
> seems like this would have a huge impact on most document designs if it is  
> accurate.
> 
> I thought the type name was actually used behind the scenes as a prefix for  
> each attribute. Consider this example:
> 
> $ curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "kimchy",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> Isn't the user property actually indexed at the Lucene layer as  
> 'tweet.user'? Wouldn't this mean that each property name within a type has a  
> unique mapping?

---

<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:03am UTC](https://discuss.elastic.co/t/documents-and-property-naming/4583/9 "2017-07-06T04:03:51Z")

</div>


