# Term query on long type failing

**URL:** <https://discuss.elastic.co/t/term-query-on-long-type-failing/20338>\
**Category:** Elasticsearch\
**Created:** [October 20, 2014, 11:40am UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338 "2014-10-20T11:40:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [October 20, 2014, 11:40am UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338/1 "2014-10-20T11:40:08Z")

</div>

Hi ,

I am extracting tweets from twitter and i found the following issue.  
On doing a terms facet on field retweet.id , i received some user ID's.  
Now on doing a term query on one of the value obtained , I am not getting  
any result.

The facet is as following -  
{  
"facets": {  
"terms": {  
"terms": {  
"field": "retweet.id",  
"size": 10,  
"order": "count",  
"exclude": []  
}  
}  
I received value 524145031945877919 using the faceting over field retweet.id  
as the top first.

facets: {

- terms: {
  - \_type: terms
  - missing: 1251
  - total: 1213
  - other: 984
  - terms: [
    - {
      - term: 524145031945877919
      - count: 53  
}

    - {

Now i executed the following -

{  
"query" : {  
"term" : {  
"retweet.id" : 524145031945877919  
}  
}  
}  
Its giving me 0 results.

Kindly point out , what is the issue.

Thanks  
Vineeth

--  
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/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.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:** [October 20, 2014, 12:20pm UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338/2 "2014-10-20T12:20:54Z")

</div>

Hi,

The term query aims at querying documents based on the raw bytes of a term.  
It is not aware of your field mappings while numeric terms are not encoded  
verbatim: they use a special binary encoding that allows the binary  
representation of the numbers to be sortable lexicographically. Switching  
to the match[1] query instead of term should fix the issue.

[1]

> **[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.

On Mon, Oct 20, 2014 at 1:40 PM, vineeth mohan [vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)  
wrote:

> Hi ,
> 
> I am extracting tweets from twitter and i found the following issue.  
> On doing a terms facet on field retweet.id , i received some user ID's.  
> Now on doing a term query on one of the value obtained , I am not getting  
> any result.
> 
> The facet is as following -  
> {  
> "facets": {  
> "terms": {  
> "terms": {  
> "field": "retweet.id",  
> "size": 10,  
> "order": "count",  
> "exclude":   
> }  
> }  
> I received value 524145031945877919 using the faceting over field  
> retweet.id as the top first.
> 
> facets: {
> 
> - terms: {
> - \_type: terms
> - missing: 1251
> - total: 1213
> - other: 984
> - terms: [
> - {
> - term: 524145031945877919
> - count: 53  
> }
> 
> - {
> 
> Now i executed the following -
> 
> {  
> "query" : {  
> "term" : {  
> "retweet.id" : 524145031945877919  
> }  
> }  
> }  
> Its giving me 0 results.
> 
> Kindly point out , what is the issue.
> 
> Thanks  
> Vineeth
> 
> --  
> 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/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.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/CAL6Z4j5KNUhw%2BGSP\_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [October 20, 2014, 12:54pm UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338/3 "2014-10-20T12:54:54Z")

</div>

Hello Adrien ,

Thanks for your reply.

But match query is also not working for me -

{  
"query": {  
"match": {  
"retweet.id": 524120494964535300  
}  
}  
}

Gives 0 results.

Thanks  
Vineeth

On Mon, Oct 20, 2014 at 5:50 PM, Adrien Grand \<  
[adrien.grand@elasticsearch.com](mailto:adrien.grand@elasticsearch.com)\> wrote:

> Hi,
> 
> The term query aims at querying documents based on the raw bytes of a  
> term. It is not aware of your field mappings while numeric terms are not  
> encoded verbatim: they use a special binary encoding that allows the binary  
> representation of the numbers to be sortable lexicographically. Switching  
> to the match[1] query instead of term should fix the issue.
> 
> [1]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
> 
> On Mon, Oct 20, 2014 at 1:40 PM, vineeth mohan [vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)  
> wrote:
> 
> > Hi ,
> > 
> > I am extracting tweets from twitter and i found the following issue.  
> > On doing a terms facet on field retweet.id , i received some user ID's.  
> > Now on doing a term query on one of the value obtained , I am not getting  
> > any result.
> > 
> > The facet is as following -  
> > {  
> > "facets": {  
> > "terms": {  
> > "terms": {  
> > "field": "retweet.id",  
> > "size": 10,  
> > "order": "count",  
> > "exclude":   
> > }  
> > }  
> > I received value 524145031945877919 using the faceting over field  
> > retweet.id as the top first.
> > 
> > facets: {
> > 
> > - terms: {
> > - \_type: terms
> > - missing: 1251
> > - total: 1213
> > - other: 984
> > - terms: [
> > - {
> > - term: 524145031945877919
> > - count: 53  
> > }
> > 
> > - {
> > 
> > Now i executed the following -
> > 
> > {  
> > "query" : {  
> > "term" : {  
> > "retweet.id" : 524145031945877919  
> > }  
> > }  
> > }  
> > Its giving me 0 results.
> > 
> > Kindly point out , what is the issue.
> > 
> > Thanks  
> > Vineeth
> > 
> > --  
> > 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/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.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/CAL6Z4j5KNUhw%2BGSP\_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP\_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ\_\_QWhf3AoRBotWrUg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ__QWhf3AoRBotWrUg%40mail.gmail.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:** [October 20, 2014, 1:08pm UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338/4 "2014-10-20T13:08:07Z")

</div>

Your retweet ids are close to the maximum double value. Can you check that  
your retweet ids are actually mapped as longs (not double) and try to  
reproduce from the command line with curl (instead of say from a browser or  
any programming language since some of them would store all numbers as  
doubles)?

On Mon, Oct 20, 2014 at 2:54 PM, vineeth mohan [vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)  
wrote:

> Hello Adrien ,
> 
> Thanks for your reply.
> 
> But match query is also not working for me -
> 
> {  
> "query": {  
> "match": {  
> "retweet.id": 524120494964535300  
> }  
> }  
> }
> 
> Gives 0 results.
> 
> Thanks  
> Vineeth
> 
> On Mon, Oct 20, 2014 at 5:50 PM, Adrien Grand \<  
> [adrien.grand@elasticsearch.com](mailto:adrien.grand@elasticsearch.com)\> wrote:
> 
> > Hi,
> > 
> > The term query aims at querying documents based on the raw bytes of a  
> > term. It is not aware of your field mappings while numeric terms are not  
> > encoded verbatim: they use a special binary encoding that allows the binary  
> > representation of the numbers to be sortable lexicographically. Switching  
> > to the match[1] query instead of term should fix the issue.
> > 
> > [1]  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
> > 
> > On Mon, Oct 20, 2014 at 1:40 PM, vineeth mohan \<[vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)
> > 
> > > wrote:
> > 
> > > Hi ,
> > > 
> > > I am extracting tweets from twitter and i found the following issue.  
> > > On doing a terms facet on field retweet.id , i received some user ID's.  
> > > Now on doing a term query on one of the value obtained , I am not  
> > > getting any result.
> > > 
> > > The facet is as following -  
> > > {  
> > > "facets": {  
> > > "terms": {  
> > > "terms": {  
> > > "field": "retweet.id",  
> > > "size": 10,  
> > > "order": "count",  
> > > "exclude":   
> > > }  
> > > }  
> > > I received value 524145031945877919 using the faceting over field  
> > > retweet.id as the top first.
> > > 
> > > facets: {
> > > 
> > > - terms: {
> > > - \_type: terms
> > > - missing: 1251
> > > - total: 1213
> > > - other: 984
> > > - terms: [
> > > - {
> > > - term: 524145031945877919
> > > - count: 53  
> > > }
> > > 
> > > - {
> > > 
> > > Now i executed the following -
> > > 
> > > {  
> > > "query" : {  
> > > "term" : {  
> > > "retweet.id" : 524145031945877919  
> > > }  
> > > }  
> > > }  
> > > Its giving me 0 results.
> > > 
> > > Kindly point out , what is the issue.
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > --  
> > > 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/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-\_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nnjxV-_DpVKg1Ewcuq7wxrDsg48fkdo5OA92jENy9d2Q%40mail.gmail.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/CAL6Z4j5KNUhw%2BGSP\_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP\_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5KNUhw%2BGSP_N1ZSWZWisGFHbmgTNz2YE10QMJDBXtq4Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ\_\_QWhf3AoRBotWrUg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ__QWhf3AoRBotWrUg%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ\_\_QWhf3AoRBotWrUg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nf6rSd5AJKDnhfS2mGu0tRQJUzQ__QWhf3AoRBotWrUg%40mail.gmail.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/CAL6Z4j5hQ984sr4q%2B0cPi5HkMfHZcZ1r%2BuBXO3wJ%2BiXQ-J854A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5hQ984sr4q%2B0cPi5HkMfHZcZ1r%2BuBXO3wJ%2BiXQ-J854A%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:55am UTC](https://discuss.elastic.co/t/term-query-on-long-type-failing/20338/5 "2017-07-06T00:55:03Z")

</div>


