# Mapping namespace problem

**URL:** <https://discuss.elastic.co/t/mapping-namespace-problem/3928>\
**Category:** Elasticsearch\
**Created:** [February 14, 2011, 5:39pm UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928 "2011-02-14T17:39:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simone\_Zaninello](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Simone\_Zaninello](https://discuss.elastic.co/u/Simone_Zaninello)\
**Post date:** [February 14, 2011, 5:39pm UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/1 "2011-02-14T17:39:33Z")

</div>

Hi,

I'm having the following problem:

- Initial state  
I put two different mappings with a field named the same way into a  
single index.  
After that I indexed two documents one for each mapping.

Mappings

curl -XPUT '[http://localhost:9200/localtest/map1/\_mapping](http://localhost:9200/localtest/map1/_mapping)' -d '{  
"map1": {  
"\_source" : {  
"enabled" : false  
},  
"date\_formats": ["date\_time", "yyyyMMddHHmmss",  
"yyyyMMddHHmmssSSS"],  
"\_all": {  
"enabled": true,  
"store": "yes"  
},  
"properties": {  
"field1": {  
"type": "date",  
"store": "yes",  
"format": "yyyyMMddHHmmssSSS",  
"include\_in\_all": false  
}  
}  
}  
}'

curl -XPUT '[http://localhost:9200/localtest/map2/\_mapping](http://localhost:9200/localtest/map2/_mapping)' -d '{  
"map2": {  
"\_source" : {  
"enabled" : false  
},  
"date\_formats": ["date\_time", "yyyyMMddHHmmss",  
"yyyyMMddHHmmssSSS"],  
"\_all": {  
"enabled": true,  
"store": "yes"  
},  
"properties": {  
"field1": {  
"type": "string",  
"store": "yes",  
"term\_vector": "yes",  
"include\_in\_all": false  
}  
}  
}  
}'

documents

curl -XPUT '[http://localhost:9200/localtest/map1/1](http://localhost:9200/localtest/map1/1)' -d '{  
"field1" : "20110214172449000"  
}'

curl -XPUT '[http://localhost:9200/localtest/map2/2](http://localhost:9200/localtest/map2/2)' -d '{  
"field1" : "Test map2 with string type field"  
}'

If I execute a search over this index using the field1 seen as string,  
the query breaks. But if I execute a search over this index using the  
field1 seen as date, the query succeeds.

Query example:  
curl -XGET '[http://localhost:9200/localtest/](http://localhost:9200/localtest/)_/\_search?pretty=true' -d  
'{  
"fields": "_",  
"from" : 0, "size" : 100,  
"query":{  
"bool":{  
"must":{"field":{"field1":""Test""}}  
}  
}  
}'

Returned error:

MapperParsingException[failed to parse date field, tried both date  
format [yyyyMMddHHmmssSSS], and timestamp number]; nested:  
IllegalArgumentException[Invalid format: "Test"];

It seems that the first mapping is the one that determines the field  
type, disregarding any following mappings.

Is it correct? If so, what's the correct way to use mappings?

Best regards  
Simone

---

<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:** [February 16, 2011, 1:57am UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/2 "2011-02-16T01:57:09Z")

</div>

Hard to tell since you embed all in the mail... . Can you gist it (or better yet, create a curl sample of it)? Check [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)  
On Monday, February 14, 2011 at 7:39 PM, Simone Zaninello wrote:

> Hi,
> 
> I'm having the following problem:
> 
> - Initial state  
> I put two different mappings with a field named the same way into a  
> single index.  
> After that I indexed two documents one for each mapping.
> 
> Consider this as an example
> 
> Mappings
> 
> curl -XPUT '[http://localhost:9200/localtest/map1/\_mapping](http://localhost:9200/localtest/map1/_mapping)' -d '{  
> "map1": {  
> "\_source" : {  
> "enabled" : false  
> },  
> "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> "yyyyMMddHHmmssSSS"],  
> "\_all": {  
> "enabled": true,  
> "store": "yes"  
> },  
> "properties": {  
> "field1": {  
> "type": "date",  
> "store": "yes",  
> "format": "yyyyMMddHHmmssSSS",  
> "include\_in\_all": false  
> }  
> }  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/localtest/map2/\_mapping](http://localhost:9200/localtest/map2/_mapping)' -d '{  
> "map2": {  
> "\_source" : {  
> "enabled" : false  
> },  
> "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> "yyyyMMddHHmmssSSS"],  
> "\_all": {  
> "enabled": true,  
> "store": "yes"  
> },  
> "properties": {  
> "field1": {  
> "type": "string",  
> "store": "yes",  
> "term\_vector": "yes",  
> "include\_in\_all": false  
> }  
> }  
> }  
> }'
> 
> documents
> 
> curl -XPUT '[http://localhost:9200/localtest/map1/1](http://localhost:9200/localtest/map1/1)' -d '{  
> "field1" : "20110214172449000"  
> }'
> 
> curl -XPUT '[http://localhost:9200/localtest/map2/2](http://localhost:9200/localtest/map2/2)' -d '{  
> "field1" : "Test map2 with string type field"  
> }'
> 
> If I execute a search over this index using the field1 seen as string,  
> the query breaks. But if I execute a search over this index using the  
> field1 seen as date, the query succeeds.
> 
> Query example:  
> curl -XGET '[http://localhost:9200/localtest/\*/\_search?pretty=true](http://localhost:9200/localtest/*/_search?pretty=true)' -d  
> '{  
> "fields": "\*",  
> "from" : 0, "size" : 100,  
> "query":{  
> "bool":{  
> "must":{"field":{"field1":""Test""}}  
> }  
> }  
> }'
> 
> Returned error:
> 
> MapperParsingException[failed to parse date field, tried both date  
> format [yyyyMMddHHmmssSSS], and timestamp number]; nested:  
> IllegalArgumentException[Invalid format: "Test"];
> 
> It seems that the first mapping is the one that determines the field  
> type, disregarding any following mappings.
> 
> Is it correct? If so, what's the correct way to use mappings?
> 
> Best regards  
> Simone

---

<div class="post-metadata">

**Author:** ![Simone\_Zaninello](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Simone\_Zaninello](https://discuss.elastic.co/u/Simone_Zaninello)\
**Post date:** [February 16, 2011, 11:17am UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/3 "2011-02-16T11:17:45Z")

</div>

Sorry I didn't read the help page.

I will do as you suggest.

Thanks

On 16 Feb, 02:57, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Hard to tell since you embed all in the mail... . Can you gist it (or better yet, create a curl sample of it)? Checkhttp://www.elasticsearch.org/help
> 
> On Monday, February 14, 2011 at 7:39 PM, Simone Zaninello wrote:
> 
> > Hi,
> 
> > I'm having the following problem:
> 
> > - Initial state  
> > I put two different mappings with a field named the same way into a  
> > single index.  
> > After that I indexed two documents one for each mapping.
> 
> > Consider this as an example
> 
> > Mappings
> 
> > curl -XPUT '[http://localhost:9200/localtest/map1/\_mapping'-d](http://localhost:9200/localtest/map1/_mapping'-d) '{  
> > "map1": {  
> > "\_source" : {  
> > "enabled" : false  
> > },  
> > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > "yyyyMMddHHmmssSSS"],  
> > "\_all": {  
> > "enabled": true,  
> > "store": "yes"  
> > },  
> > "properties": {  
> > "field1": {  
> > "type": "date",  
> > "store": "yes",  
> > "format": "yyyyMMddHHmmssSSS",  
> > "include\_in\_all": false  
> > }  
> > }  
> > }  
> > }'
> 
> > curl -XPUT '[http://localhost:9200/localtest/map2/\_mapping'-d](http://localhost:9200/localtest/map2/_mapping'-d) '{  
> > "map2": {  
> > "\_source" : {  
> > "enabled" : false  
> > },  
> > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > "yyyyMMddHHmmssSSS"],  
> > "\_all": {  
> > "enabled": true,  
> > "store": "yes"  
> > },  
> > "properties": {  
> > "field1": {  
> > "type": "string",  
> > "store": "yes",  
> > "term\_vector": "yes",  
> > "include\_in\_all": false  
> > }  
> > }  
> > }  
> > }'
> 
> > documents
> 
> > curl -XPUT '[http://localhost:9200/localtest/map1/1'-d](http://localhost:9200/localtest/map1/1'-d) '{  
> > "field1" : "20110214172449000"  
> > }'
> 
> > curl -XPUT '[http://localhost:9200/localtest/map2/2'-d](http://localhost:9200/localtest/map2/2'-d) '{  
> > "field1" : "Test map2 with string type field"  
> > }'
> 
> > If I execute a search over this index using the field1 seen as string,  
> > the query breaks. But if I execute a search over this index using the  
> > field1 seen as date, the query succeeds.
> 
> > Query example:  
> > curl -XGET '[http://localhost:9200/localtest/\*/\_search?pretty=true'-d](http://localhost:9200/localtest/*/_search?pretty=true'-d)  
> > '{  
> > "fields": "\*",  
> > "from" : 0, "size" : 100,  
> > "query":{  
> > "bool":{  
> > "must":{"field":{"field1":""Test""}}  
> > }  
> > }  
> > }'
> 
> > Returned error:
> 
> > MapperParsingException[failed to parse date field, tried both date  
> > format [yyyyMMddHHmmssSSS], and timestamp number]; nested:  
> > IllegalArgumentException[Invalid format: "Test"];
> 
> > It seems that the first mapping is the one that determines the field  
> > type, disregarding any following mappings.
> 
> > Is it correct? If so, what's the correct way to use mappings?
> 
> > Best regards  
> > Simone

---

<div class="post-metadata">

**Author:** ![Simone\_Zaninello](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@Simone\_Zaninello](https://discuss.elastic.co/u/Simone_Zaninello)\
**Post date:** [February 16, 2011, 11:49am UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/4 "2011-02-16T11:49:16Z")

</div>

This is the gist with code for my test

[https://gist.github.com/829239](https://gist.github.com/829239)

Is this behaviour correct? If so, what's the correct way to use  
mappings? Aren't they supposed to create different namespaces for  
fields of documents into a index?

On 16 Feb, 02:57, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Hard to tell since you embed all in the mail... . Can you gist it (or better yet, create a curl sample of it)? Checkhttp://www.elasticsearch.org/help
> 
> On Monday, February 14, 2011 at 7:39 PM, Simone Zaninello wrote:
> 
> > Hi,
> 
> > I'm having the following problem:
> 
> > - Initial state  
> > I put two different mappings with a field named the same way into a  
> > single index.  
> > After that I indexed two documents one for each mapping.
> 
> > Consider this as an example
> 
> > Mappings
> 
> > curl -XPUT '[http://localhost:9200/localtest/map1/\_mapping'-d](http://localhost:9200/localtest/map1/_mapping'-d) '{  
> > "map1": {  
> > "\_source" : {  
> > "enabled" : false  
> > },  
> > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > "yyyyMMddHHmmssSSS"],  
> > "\_all": {  
> > "enabled": true,  
> > "store": "yes"  
> > },  
> > "properties": {  
> > "field1": {  
> > "type": "date",  
> > "store": "yes",  
> > "format": "yyyyMMddHHmmssSSS",  
> > "include\_in\_all": false  
> > }  
> > }  
> > }  
> > }'
> 
> > curl -XPUT '[http://localhost:9200/localtest/map2/\_mapping'-d](http://localhost:9200/localtest/map2/_mapping'-d) '{  
> > "map2": {  
> > "\_source" : {  
> > "enabled" : false  
> > },  
> > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > "yyyyMMddHHmmssSSS"],  
> > "\_all": {  
> > "enabled": true,  
> > "store": "yes"  
> > },  
> > "properties": {  
> > "field1": {  
> > "type": "string",  
> > "store": "yes",  
> > "term\_vector": "yes",  
> > "include\_in\_all": false  
> > }  
> > }  
> > }  
> > }'
> 
> > documents
> 
> > curl -XPUT '[http://localhost:9200/localtest/map1/1'-d](http://localhost:9200/localtest/map1/1'-d) '{  
> > "field1" : "20110214172449000"  
> > }'
> 
> > curl -XPUT '[http://localhost:9200/localtest/map2/2'-d](http://localhost:9200/localtest/map2/2'-d) '{  
> > "field1" : "Test map2 with string type field"  
> > }'
> 
> > If I execute a search over this index using the field1 seen as string,  
> > the query breaks. But if I execute a search over this index using the  
> > field1 seen as date, the query succeeds.
> 
> > Query example:  
> > curl -XGET '[http://localhost:9200/localtest/\*/\_search?pretty=true'-d](http://localhost:9200/localtest/*/_search?pretty=true'-d)  
> > '{  
> > "fields": "\*",  
> > "from" : 0, "size" : 100,  
> > "query":{  
> > "bool":{  
> > "must":{"field":{"field1":""Test""}}  
> > }  
> > }  
> > }'
> 
> > Returned error:
> 
> > MapperParsingException[failed to parse date field, tried both date  
> > format [yyyyMMddHHmmssSSS], and timestamp number]; nested:  
> > IllegalArgumentException[Invalid format: "Test"];
> 
> > It seems that the first mapping is the one that determines the field  
> > type, disregarding any following mappings.
> 
> > Is it correct? If so, what's the correct way to use mappings?
> 
> > Best regards  
> > Simone

---

<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:** [February 17, 2011, 1:03am UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/5 "2011-02-17T01:03:02Z")

</div>

I see the problem now, basically, the types map1 and map2 have different mappings for field1, so unless explicitly specified in the query (map1.field1 or map2.field1 compared to just field1) will cause problems. Usually, it is better to have same name fields cross mapping types to be of hte same type.  
On Wednesday, February 16, 2011 at 1:49 PM, Simone Zaninello wrote:

> This is the gist with code for my test
> 
> [https://gist.github.com/829239](https://gist.github.com/829239)
> 
> Is this behaviour correct? If so, what's the correct way to use  
> mappings? Aren't they supposed to create different namespaces for  
> fields of documents into a index?
> 
> On 16 Feb, 02:57, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Hard to tell since you embed all in the mail... . Can you gist it (or better yet, create a curl sample of it)? Checkhttp://www.elasticsearch.org/help
> > 
> > On Monday, February 14, 2011 at 7:39 PM, Simone Zaninello wrote:
> > 
> > > Hi,
> > 
> > > I'm having the following problem:
> > 
> > > - Initial state  
> > > I put two different mappings with a field named the same way into a  
> > > single index.  
> > > After that I indexed two documents one for each mapping.
> > 
> > > Consider this as an example
> > 
> > > Mappings
> > 
> > > curl -XPUT '[http://localhost:9200/localtest/map1/\_mapping'-d](http://localhost:9200/localtest/map1/_mapping'-d) '{  
> > > "map1": {  
> > > "\_source" : {  
> > > "enabled" : false  
> > > },  
> > > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > > "yyyyMMddHHmmssSSS"],  
> > > "\_all": {  
> > > "enabled": true,  
> > > "store": "yes"  
> > > },  
> > > "properties": {  
> > > "field1": {  
> > > "type": "date",  
> > > "store": "yes",  
> > > "format": "yyyyMMddHHmmssSSS",  
> > > "include\_in\_all": false  
> > > }  
> > > }  
> > > }  
> > > }'
> > 
> > > curl -XPUT '[http://localhost:9200/localtest/map2/\_mapping'-d](http://localhost:9200/localtest/map2/_mapping'-d) '{  
> > > "map2": {  
> > > "\_source" : {  
> > > "enabled" : false  
> > > },  
> > > "date\_formats": ["date\_time", "yyyyMMddHHmmss",  
> > > "yyyyMMddHHmmssSSS"],  
> > > "\_all": {  
> > > "enabled": true,  
> > > "store": "yes"  
> > > },  
> > > "properties": {  
> > > "field1": {  
> > > "type": "string",  
> > > "store": "yes",  
> > > "term\_vector": "yes",  
> > > "include\_in\_all": false  
> > > }  
> > > }  
> > > }  
> > > }'
> > 
> > > documents
> > 
> > > curl -XPUT '[http://localhost:9200/localtest/map1/1'-d](http://localhost:9200/localtest/map1/1'-d) '{  
> > > "field1" : "20110214172449000"  
> > > }'
> > 
> > > curl -XPUT '[http://localhost:9200/localtest/map2/2'-d](http://localhost:9200/localtest/map2/2'-d) '{  
> > > "field1" : "Test map2 with string type field"  
> > > }'
> > 
> > > If I execute a search over this index using the field1 seen as string,  
> > > the query breaks. But if I execute a search over this index using the  
> > > field1 seen as date, the query succeeds.
> > 
> > > Query example:  
> > > curl -XGET '[http://localhost:9200/localtest/\*/\_search?pretty=true'-d](http://localhost:9200/localtest/*/_search?pretty=true'-d)  
> > > '{  
> > > "fields": "\*",  
> > > "from" : 0, "size" : 100,  
> > > "query":{  
> > > "bool":{  
> > > "must":{"field":{"field1":""Test""}}  
> > > }  
> > > }  
> > > }'
> > 
> > > Returned error:
> > 
> > > MapperParsingException[failed to parse date field, tried both date  
> > > format [yyyyMMddHHmmssSSS], and timestamp number]; nested:  
> > > IllegalArgumentException[Invalid format: "Test"];
> > 
> > > It seems that the first mapping is the one that determines the field  
> > > type, disregarding any following mappings.
> > 
> > > Is it correct? If so, what's the correct way to use mappings?
> > 
> > > Best regards  
> > > Simone

---

<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:11am UTC](https://discuss.elastic.co/t/mapping-namespace-problem/3928/6 "2017-07-06T04:11:57Z")

</div>


