# Conflict between fields of same name under different types

**URL:** <https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406>\
**Category:** Elasticsearch\
**Created:** [January 18, 2013, 10:08am UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406 "2013-01-18T10:08:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [January 18, 2013, 10:08am UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406/1 "2013-01-18T10:08:41Z")

</div>

Hi,

I have a field 'customValue' typed as integer in type 'type1' and as long  
in type 'type2'. Terms facets on the field is failing. Following is the  
gist:

curl -XDELETE '[http://localhost:9200/try\_test/](http://localhost:9200/try_test/)'

curl -XPOST [http://localhost:9200/try\_test](http://localhost:9200/try_test) -d '{  
"index": {  
"number\_of\_shards": 1,  
"number\_of\_replicas": 0  
}  
}'

curl -XPUT '[http://localhost:9200/try\_test/type1/\_mapping](http://localhost:9200/try_test/type1/_mapping)' -d '{  
"type1": {  
"\_source": {  
"enabled": true  
},  
"properties": {  
"customId": {  
"type": "integer",  
"index": "analyzed"  
},  
"customValue": {  
"type": "integer",  
"index": "analyzed"  
}  
}  
}  
}'

curl -XPUT '[http://localhost:9200/try\_test/type2/\_mapping](http://localhost:9200/try_test/type2/_mapping)' -d '{  
"type2": {  
"\_source": {  
"enabled": true  
},  
"properties": {  
"customId": {  
"type": "integer",  
"index": "analyzed"  
},  
"customValue": {  
"type": "long",  
"index": "analyzed"  
}  
}  
}  
}'

curl -XPOST '[http://localhost:9200/try\_test/type1/](http://localhost:9200/try_test/type1/)' -d '{  
"customId": 2301,  
"customValue": 67  
}'

curl -XPOST '[http://localhost:9200/try\_test/type2/](http://localhost:9200/try_test/type2/)' -d '{  
"customId": 2302,  
"customValue": 678917349187249  
}'

curl -XGET '[http://localhost:9200/try\_test/\_search?pretty=true](http://localhost:9200/try_test/_search?pretty=true)' -d '{  
"query": {  
"match\_all": {}  
},  
"from": 0,  
"size": 0,  
"facets": {  
"facet1": {  
"terms": {  
"field": "customValue",  
"size": 10  
}  
}  
}  
}'

# Failing, which is expected. Trying to facet simultaneously on two

different types can be illegal.

curl -XGET '[http://localhost:9200/try\_test/type1/\_search?pretty=true](http://localhost:9200/try_test/type1/_search?pretty=true)' -d '{  
"query": {  
"match\_all": {}  
},  
"from": 0,  
"size": 0,  
"facets": {  
"facet1": {  
"terms": {  
"field": "customValue",  
"size": 10  
}  
}  
}  
}'

# Failing, why? It should give result, as does the next one.

curl -XGET '[http://localhost:9200/try\_test/type2/\_search?pretty=true](http://localhost:9200/try_test/type2/_search?pretty=true)' -d '{  
"query": {  
"match\_all": {}  
},  
"from": 0,  
"size": 0,  
"facets": {  
"facet1": {  
"terms": {  
"field": "customValue",  
"size": 10  
}  
}  
}  
}'

# Working.

The exception is the following :

{  
"error" : "SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], total failure; shardFailures  
{[h5W2XmgPTKS6pDylfkqBZQ][try\_test][0]:  
QueryPhaseExecutionException[[try\_test][0]:  
query[ConstantScore(NotDeleted(cache(\_type:type1)))],from[0],size[0]: Query  
Failed [Failed to execute main query]]; nested:  
NumberFormatException[Invalid shift value in prefixCoded string (is encoded  
value really an INT?)]; }]",  
"status" : 500  
}

Any hint on how to resolve this? Making everything as long is one solution,  
I know, but other than that? This is failing on both 0.19 and 0.20 version.

Thanks in advance,  
-- Sujoy.

--

---

<div class="post-metadata">

**Author:** ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)\
**Post date:** [January 18, 2013, 12:38pm UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406/2 "2013-01-18T12:38:45Z")

</div>

I'm not sure this is relevant, but from

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> Field names with the same name across types are highly recommended to have  
> the same type and same mapping characteristics (analysis settings for  
> example). There is an effort to allow to explicitly “choose” which field to  
> use by using type prefix (my\_type.my\_field), but it’s not complete, and  
> there are places where it will never work (_like faceting on the field_).

On Friday, 18 January 2013 05:08:41 UTC-5, Sujoy Sett wrote:

> Hi,
> 
> I have a field 'customValue' typed as integer in type 'type1' and as long  
> in type 'type2'. Terms facets on the field is failing. Following is the  
> gist:
> 
> curl -XDELETE '[http://localhost:9200/try\_test/](http://localhost:9200/try_test/)'
> 
> curl -XPOST [http://localhost:9200/try\_test](http://localhost:9200/try_test) -d '{  
> "index": {  
> "number\_of\_shards": 1,  
> "number\_of\_replicas": 0  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/try\_test/type1/\_mapping](http://localhost:9200/try_test/type1/_mapping)' -d '{  
> "type1": {  
> "\_source": {  
> "enabled": true  
> },  
> "properties": {  
> "customId": {  
> "type": "integer",  
> "index": "analyzed"  
> },  
> "customValue": {  
> "type": "integer",  
> "index": "analyzed"  
> }  
> }  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/try\_test/type2/\_mapping](http://localhost:9200/try_test/type2/_mapping)' -d '{  
> "type2": {  
> "\_source": {  
> "enabled": true  
> },  
> "properties": {  
> "customId": {  
> "type": "integer",  
> "index": "analyzed"  
> },  
> "customValue": {  
> "type": "long",  
> "index": "analyzed"  
> }  
> }  
> }  
> }'
> 
> curl -XPOST '[http://localhost:9200/try\_test/type1/](http://localhost:9200/try_test/type1/)' -d '{  
> "customId": 2301,  
> "customValue": 67  
> }'
> 
> curl -XPOST '[http://localhost:9200/try\_test/type2/](http://localhost:9200/try_test/type2/)' -d '{  
> "customId": 2302,  
> "customValue": 678917349187249  
> }'
> 
> curl -XGET '[http://localhost:9200/try\_test/\_search?pretty=true](http://localhost:9200/try_test/_search?pretty=true)' -d '{  
> "query": {  
> "match\_all": {}  
> },  
> "from": 0,  
> "size": 0,  
> "facets": {  
> "facet1": {  
> "terms": {  
> "field": "customValue",  
> "size": 10  
> }  
> }  
> }  
> }'
> 
> # Failing, which is expected. Trying to facet simultaneously on two
> 
> different types can be illegal.
> 
> curl -XGET '[http://localhost:9200/try\_test/type1/\_search?pretty=true](http://localhost:9200/try_test/type1/_search?pretty=true)' -d  
> '{  
> "query": {  
> "match\_all": {}  
> },  
> "from": 0,  
> "size": 0,  
> "facets": {  
> "facet1": {  
> "terms": {  
> "field": "customValue",  
> "size": 10  
> }  
> }  
> }  
> }'
> 
> # Failing, why? It should give result, as does the next one.
> 
> curl -XGET '[http://localhost:9200/try\_test/type2/\_search?pretty=true](http://localhost:9200/try_test/type2/_search?pretty=true)' -d  
> '{  
> "query": {  
> "match\_all": {}  
> },  
> "from": 0,  
> "size": 0,  
> "facets": {  
> "facet1": {  
> "terms": {  
> "field": "customValue",  
> "size": 10  
> }  
> }  
> }  
> }'
> 
> # Working.
> 
> The exception is the following :
> 
> {  
> "error" : "SearchPhaseExecutionException[Failed to execute phase  
> [query\_fetch], total failure; shardFailures  
> {[h5W2XmgPTKS6pDylfkqBZQ][try\_test][0]:  
> QueryPhaseExecutionException[[try\_test][0]:  
> query[ConstantScore(NotDeleted(cache(\_type:type1)))],from[0],size[0]: Query  
> Failed [Failed to execute main query]]; nested:  
> NumberFormatException[Invalid shift value in prefixCoded string (is encoded  
> value really an INT?)]; }]",  
> "status" : 500  
> }
> 
> Any hint on how to resolve this? Making everything as long is one  
> solution, I know, but other than that? This is failing on both 0.19 and  
> 0.20 version.
> 
> Thanks in advance,  
> -- Sujoy.

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 18, 2013, 12:49pm UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406/3 "2013-01-18T12:49:59Z")

</div>

On Fri, 2013-01-18 at 04:38 -0800, btiernay wrote:

> I'm not sure this is relevant, but from  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/index.html:)
> 
> ```
> Field names with the same name across types are highly
> recommended to have the same type and same mapping
> characteristics (analysis settings for example). There is an
> effort to allow to explicitly “choose” which field to use by
> using type prefix (my_type.my_field), but it’s not complete,
> and there are places where it will never work (like faceting
> on the field).
> 
> ```

Hmm, that is interesting... I hadn't seen that comment before. I wonder  
if it is still true.

It certainly seems to work:

curl -XPOST '[http://127.0.0.1:9200/test/test?pretty=1](http://127.0.0.1:9200/test/test?pretty=1)' -d '  
{  
"bar" : {  
"name" : 3  
},  
"name" : "foo"  
}  
'  
curl -XGET  
'[http://127.0.0.1:9200/test/test/\_search?pretty=1&search\_type=count](http://127.0.0.1:9200/test/test/_search?pretty=1&search_type=count)' -d  
'  
{  
"facets" : {  
"test.name" : {  
"terms" : {  
"field" : "test.name"  
}  
},  
"test.bar.name" : {  
"terms" : {  
"field" : "test.bar.name"  
}  
},  
"name" : {  
"terms" : {  
"field" : "name"  
}  
},  
"bar.name" : {  
"terms" : {  
"field" : "bar.name"  
}  
}  
}  
}  
'

{  
"facets" : {  
"test.name" : {  
"other" : 0,  
"terms" : [  
{  
"count" : 1,  
"term" : "foo"  
}  
],  
"missing" : 0,  
"\_type" : "terms",  
"total" : 1  
},  
"test.bar.name" : {  
"other" : 0,  
"terms" : [  
{  
"count" : 1,  
"term" : 3  
}  
],  
"missing" : 0,  
"\_type" : "terms",  
"total" : 1  
},  
"bar.name" : {  
"other" : 0,  
"terms" : [  
{  
"count" : 1,  
"term" : 3  
}  
],  
"missing" : 0,  
"\_type" : "terms",  
"total" : 1  
},  
"name" : {  
"other" : 0,  
"terms" : [  
{  
"count" : 1,  
"term" : "foo"  
}  
],  
"missing" : 0,  
"\_type" : "terms",  
"total" : 1  
}  
}  
}

--

---

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [January 18, 2013, 2:30pm UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406/4 "2013-01-18T14:30:10Z")

</div>

Many thanks to both .....

Yes, I haven't noticed that comment too for mapping, but the problem can be  
too annoying sometimes.

We have similar documents under different types, with explicit mapping (say  
Integer). Somehow mapping for a type is not registered, then in absence of  
explicit mapping default mapping (and that is usually long) comes in, and  
that is where the problem starts.

Looks like more care has to be needed on mapping conflicts and failures.  
Thanks again.

-- Sujoy.

On Friday, January 18, 2013 6:19:59 PM UTC+5:30, Clinton Gormley wrote:

> On Fri, 2013-01-18 at 04:38 -0800, btiernay wrote:
> 
> > I'm not sure this is relevant, but from  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/index.html:)
> > 
> > ```
> > Field names with the same name across types are highly 
> > recommended to have the same type and same mapping 
> > characteristics (analysis settings for example). There is an 
> > effort to allow to explicitly “choose” which field to use by 
> > using type prefix (my_type.my_field), but it’s not complete, 
> > and there are places where it will never work (like faceting 
> > on the field). 
> > 
> > ```
> 
> Hmm, that is interesting... I hadn't seen that comment before. I wonder  
> if it is still true.
> 
> It certainly seems to work:
> 
> curl -XPOST '[http://127.0.0.1:9200/test/test?pretty=1](http://127.0.0.1:9200/test/test?pretty=1)' -d '  
> {  
> "bar" : {  
> "name" : 3  
> },  
> "name" : "foo"  
> }  
> '  
> curl -XGET  
> '[http://127.0.0.1:9200/test/test/\_search?pretty=1&search\_type=count](http://127.0.0.1:9200/test/test/_search?pretty=1&search_type=count)' -d  
> '  
> {  
> "facets" : {  
> "test.name" : {  
> "terms" : {  
> "field" : "test.name"  
> }  
> },  
> "test.bar.name" : {  
> "terms" : {  
> "field" : "test.bar.name"  
> }  
> },  
> "name" : {  
> "terms" : {  
> "field" : "name"  
> }  
> },  
> "bar.name" : {  
> "terms" : {  
> "field" : "bar.name"  
> }  
> }  
> }  
> }  
> '
> 
> {  
> "facets" : {  
> "test.name" : {  
> "other" : 0,  
> "terms" : [  
> {  
> "count" : 1,  
> "term" : "foo"  
> }  
> ],  
> "missing" : 0,  
> "\_type" : "terms",  
> "total" : 1  
> },  
> "test.bar.name" : {  
> "other" : 0,  
> "terms" : [  
> {  
> "count" : 1,  
> "term" : 3  
> }  
> ],  
> "missing" : 0,  
> "\_type" : "terms",  
> "total" : 1  
> },  
> "bar.name" : {  
> "other" : 0,  
> "terms" : [  
> {  
> "count" : 1,  
> "term" : 3  
> }  
> ],  
> "missing" : 0,  
> "\_type" : "terms",  
> "total" : 1  
> },  
> "name" : {  
> "other" : 0,  
> "terms" : [  
> {  
> "count" : 1,  
> "term" : "foo"  
> }  
> ],  
> "missing" : 0,  
> "\_type" : "terms",  
> "total" : 1  
> }  
> }  
> }

--

---

<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:55am UTC](https://discuss.elastic.co/t/conflict-between-fields-of-same-name-under-different-types/10406/5 "2017-07-06T02:55:46Z")

</div>


