# Term filter on field mapped to "integer" fails - a bug?

**URL:** <https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930>\
**Category:** Elasticsearch\
**Created:** [January 30, 2015, 6:31pm UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930 "2015-01-30T18:31:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![msbreuer](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@msbreuer](https://discuss.elastic.co/u/msbreuer)\
**Post date:** [January 30, 2015, 6:31pm UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930/1 "2015-01-30T18:31:43Z")

</div>

There seems to be a bug on term-filter when using it on "integer"-mapped  
fields. The field "position" is mapped to "integer" and does not match to  
term-filter. This is the mapping:

"position" : {  
"type": "integer"  
}

And this the the search request:

{  
"from": 0,  
"size": 10,  
"sort": [  
{}  
],  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"bool": {  
"should": [  
{  
"term": {  
"position": "1"  
}  
}  
]  
}  
},  
{  
"type": {  
"value": "my-test-type"  
}  
}  
]  
}  
}  
}  
}  
}

Also there is no difference when using this expression:

...  
"term": {  
"position": 1  
}  
...

Curisously the same query on a "long" field does perfectly match. Seems ES  
cannot detect "long" for a value of "1"!?

Is this an elasticsearch bug? Where is the error?

regards,  
markus

--  
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/92c8d00b-ab67-4a58-aabf-9ee1d42d3290%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92c8d00b-ab67-4a58-aabf-9ee1d42d3290%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![msbreuer](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@msbreuer](https://discuss.elastic.co/u/msbreuer)\
**Post date:** [January 31, 2015, 8:36am UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930/2 "2015-01-31T08:36:14Z")

</div>

I replaced the "bool" filter with "and" filter, but the result is the same.  
The same data was written to a different type within the ES index, but with  
mapping of "string" instead of "integer". "string" and "long" always work  
as expected, but the field mapped to "integer" never matches the term  
query. There is no hint of such behavior in the ES manuals.

Any idea?

{  
"from": 0,  
"size": 10,  
"sort": [  
{}  
],  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": [  
{  
"term": {  
"position": "1"  
}  
},  
{  
"type": {  
"value": "my-test-type"  
}  
}  
]  
}  
}  
}  
}

--  
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/9d069565-b96c-4558-b573-0551a9450479%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9d069565-b96c-4558-b573-0551a9450479%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![msbreuer](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@msbreuer](https://discuss.elastic.co/u/msbreuer)\
**Post date:** [February 3, 2015, 6:23am UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930/3 "2015-02-03T06:23:01Z")

</div>

The affected "integer" fields take no effect for sorting. It looks like  
store only, the result document contains values. But the field itself is  
not searchable.

When creating index with mapping to "long" al lis fine. Does any one have  
an idea?

--  
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/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [February 3, 2015, 9:08am UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930/4 "2015-02-03T09:08:19Z")

</div>

> The same data was written to a different type within the ES index, but  
> with mapping of "string" instead of "integer".

This is probably the source of the bug, Elasticsearch is still aware of  
this mapping and tries to search your field as if it was a string field,  
while it's actually encoded as an integer field. In general you should  
avoid having the same field name mapped to different types in the same  
index, this is something that does not work well.

On Tue, Feb 3, 2015 at 7:23 AM, [msbreuer@gmail.com](mailto:msbreuer@gmail.com) wrote:

> The affected "integer" fields take no effect for sorting. It looks like  
> store only, the result document contains values. But the field itself is  
> not searchable.
> 
> When creating index with mapping to "long" al lis fine. Does any one have  
> an idea?
> 
> --  
> 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/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/7096839c-2baa-42e9-91da-b47c634f2c7a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j5vmwJfNpqYnk%3D%3DFVso8n\_ppo7oiMw0Hm8U9r7uqGGvyQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5vmwJfNpqYnk%3D%3DFVso8n_ppo7oiMw0Hm8U9r7uqGGvyQ%40mail.gmail.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, 12:35am UTC](https://discuss.elastic.co/t/term-filter-on-field-mapped-to-integer-fails-a-bug/21930/5 "2017-07-06T00:35:14Z")

</div>


