# "term" query fails to match exact long integer; instead matches nearby long integer

**URL:** <https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209>\
**Category:** Elasticsearch\
**Created:** [March 6, 2014, 9:29pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209 "2014-03-06T21:29:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Freeman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_freeman/32/1756_2.png) [@John\_Freeman](https://discuss.elastic.co/u/John_Freeman)\
**Post date:** [March 6, 2014, 9:29pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/1 "2014-03-06T21:29:53Z")

</div>

I've got a document with a long integer identifier:

{  
"id": -6001495857799773000  
}

Trying to filter based on this identifier returns nothing:

{  
"query": {  
"filtered": {  
"filter": {  
"term": {"id": -6001495857799773000}  
}  
}  
}  
}

I switched to a range query and expanded the range to 1000 numbers on each  
side. I hit the document I expected. Through narrowing the range, I found a  
number that the term query will exactly match against the document:

{  
"query": {  
"filtered": {  
"filter": {  
"term": {"metric.batchId": -6001495857799773137}  
}  
}  
}  
}

You can see this number is 137 less than the actual number returned in the  
document. This number works for both range (with lte and gte both set to  
this number) and term queries. What is going on here?

--  
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/fba1325b-91aa-443c-a9d9-8e0c081419ce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fba1325b-91aa-443c-a9d9-8e0c081419ce%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![John\_Freeman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_freeman/32/1756_2.png) [@John\_Freeman](https://discuss.elastic.co/u/John_Freeman)\
**Post date:** [March 6, 2014, 9:31pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/2 "2014-03-06T21:31:16Z")

</div>

For the purposes of the example, "metric.batchId" should be just "id".

--  
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/24ce4b1c-7410-4931-939d-875b8c092cb8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/24ce4b1c-7410-4931-939d-875b8c092cb8%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![John\_Freeman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_freeman/32/1756_2.png) [@John\_Freeman](https://discuss.elastic.co/u/John_Freeman)\
**Post date:** [March 6, 2014, 10:00pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/3 "2014-03-06T22:00:59Z")

</div>

So ES is storing the exact integer and matching against it, but does not  
show the exact integer in the returned document. How can I get that?

--  
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/d5bc77c8-a36f-45dd-bddd-c6fbeae44e35%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d5bc77c8-a36f-45dd-bddd-c6fbeae44e35%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 6, 2014, 10:59pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/4 "2014-03-06T22:59:12Z")

</div>

I'm curious about the exact environment you are running these commands  
from. I tested it quickly (ES 1.0.1) and it works fine for me from the curl  
command-line (i.e. I index the value, it mapped automatically to long, and  
queried it back it gave the same value).

I've heard cases where some people executing this in a browser script  
environment where big (or small) numbers were not working quite right due  
to browser limitations.

I'd double check from the command line to verify if indeed this is the case  
for you.

--  
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/7e504e5c-d1c9-4ad7-9890-68e01ff9a48e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7e504e5c-d1c9-4ad7-9890-68e01ff9a48e%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![John\_Freeman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_freeman/32/1756_2.png) [@John\_Freeman](https://discuss.elastic.co/u/John_Freeman)\
**Post date:** [March 6, 2014, 11:07pm UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/5 "2014-03-06T23:07:14Z")

</div>

I am using 1.0.0.Beta2, with an explicit mapping, and ran this in the Sense  
plugin. I will try from command line.

--  
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/044f44c6-dc0c-4765-a786-f2fc917e258b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/044f44c6-dc0c-4765-a786-f2fc917e258b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![John\_Freeman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_freeman/32/1756_2.png) [@John\_Freeman](https://discuss.elastic.co/u/John_Freeman)\
**Post date:** [March 7, 2014, 12:05am UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/6 "2014-03-07T00:05:49Z")

</div>

The hit from the command line has the same wrong integer, but I cannot  
repeat this problem using a new index. Could it be corruption? Some of my  
other indices were corrupted because of node thrashing: new nodes kept  
being started after updating to 1.0.1 because I didn't know the command  
line options and default behavior were changed (!!!).

--  
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/d0465fc9-ce73-4ff5-9154-568619a5565e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d0465fc9-ce73-4ff5-9154-568619a5565e%40googlegroups.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, 1:45am UTC](https://discuss.elastic.co/t/term-query-fails-to-match-exact-long-integer-instead-matches-nearby-long-integer/16209/7 "2017-07-06T01:45:11Z")

</div>


