# Querying a LONG field

**URL:** <https://discuss.elastic.co/t/querying-a-long-field/4569>\
**Category:** Elasticsearch\
**Created:** [June 8, 2011, 2:04am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569 "2011-06-08T02:04:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Creeger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_creeger/32/3134_2.png) [@Adam\_Creeger](https://discuss.elastic.co/u/Adam_Creeger)\
**Post date:** [June 8, 2011, 2:04am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/1 "2011-06-08T02:04:45Z")

</div>

Hi,

Using 0.16.2, I have a type that contains a field of type long, but I am  
having difficulty writing a query against it. The field name is orgId, and  
always contains an integer, the following queries produce no results:

{  
"query": { "range": { "orgId": { "from": 123, "to": 123, "include\_lower":  
true, "include\_upper": true }}}  
}

{  
"query": { "term": { "orgId": "123" }}  
}

{  
"query": { "term": { "orgId": 123 }}  
}

{  
"query": { "field": { "orgId": "123" }}  
}

(and again without the quotes around 123).

I'm sure this is such an easy answer, but I can't quite figure it out. It  
looks similar to this gist: [https://gist.github.com/737631](https://gist.github.com/737631), but the  
solutions there don't work. If it isn't a simple problem, I'll try to gist a  
recreation tomorrow...

Thanks!

Adam

---

<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:** [June 8, 2011, 9:12am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/2 "2011-06-08T09:12:10Z")

</div>

This should work, a recreation would be great.

On Wednesday, June 8, 2011 at 5:04 AM, Adam Creeger wrote:

> Hi,
> 
> Using 0.16.2, I have a type that contains a field of type long, but I am having difficulty writing a query against it. The field name is orgId, and always contains an integer, the following queries produce no results:
> 
> {  
> "query": { "range": { "orgId": { "from": 123, "to": 123, "include\_lower": true, "include\_upper": true }}}  
> }
> 
> {  
> "query": { "term": { "orgId": "123" }}  
> }
> 
> {  
> "query": { "term": { "orgId": 123 }}  
> }
> 
> {  
> "query": { "field": { "orgId": "123" }}  
> }
> 
> (and again without the quotes around 123).
> 
> I'm sure this is such an easy answer, but I can't quite figure it out. It looks similar to this gist: [gist:737631 · GitHub](https://gist.github.com/737631), but the solutions there don't work. If it isn't a simple problem, I'll try to gist a recreation tomorrow...
> 
> Thanks!
> 
> Adam

---

<div class="post-metadata">

**Author:** ![Adam\_Creeger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_creeger/32/3134_2.png) [@Adam\_Creeger](https://discuss.elastic.co/u/Adam_Creeger)\
**Post date:** [June 9, 2011, 1:34am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/3 "2011-06-09T01:34:28Z")

</div>

Hi Shay,

This was being caused by the orgId field being mapped in one type as a  
string, and in another type (same index) as a long. Does that make sense?  
Would it be possible to prevent/warn when you attempt to have 2 different  
mappings for the same property in one index?

Thanks,

Adam

On 8 June 2011 02:12, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> This should work, a recreation would be great.
> 
> On Wednesday, June 8, 2011 at 5:04 AM, Adam Creeger wrote:
> 
> Hi,
> 
> Using 0.16.2, I have a type that contains a field of type long, but I am  
> having difficulty writing a query against it. The field name is orgId, and  
> always contains an integer, the following queries produce no results:
> 
> {  
> "query": { "range": { "orgId": { "from": 123, "to": 123, "include\_lower":  
> true, "include\_upper": true }}}  
> }
> 
> {  
> "query": { "term": { "orgId": "123" }}  
> }
> 
> {  
> "query": { "term": { "orgId": 123 }}  
> }
> 
> {  
> "query": { "field": { "orgId": "123" }}  
> }
> 
> (and again without the quotes around 123).
> 
> I'm sure this is such an easy answer, but I can't quite figure it out. It  
> looks similar to this gist: [https://gist.github.com/737631](https://gist.github.com/737631), but the  
> solutions there don't work. If it isn't a simple problem, I'll try to gist a  
> recreation tomorrow...
> 
> Thanks!
> 
> Adam

---

<div class="post-metadata">

**Author:** ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)\
**Post date:** [June 9, 2011, 8:53am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/4 "2011-06-09T08:53:32Z")

</div>

- deleted -

---

<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:** [June 9, 2011, 7:07pm UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/5 "2011-06-09T19:07:56Z")

</div>

Warning is a possible good idea. In general, you can work around it by explicitly saying which type field you want to search on (like type1.field1). Its similar to the problem mongodb has, where you can basically do whatever you want with types in documents, but you really don't want to mix it.

On Thursday, June 9, 2011 at 4:34 AM, Adam Creeger wrote:

> Hi Shay,
> 
> This was being caused by the orgId field being mapped in one type as a string, and in another type (same index) as a long. Does that make sense? Would it be possible to prevent/warn when you attempt to have 2 different mappings for the same property in one index?
> 
> Thanks,
> 
> Adam
> 
> On 8 June 2011 02:12, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > This should work, a recreation would be great.
> > 
> > On Wednesday, June 8, 2011 at 5:04 AM, Adam Creeger wrote:
> > 
> > > Hi,
> > > 
> > > Using 0.16.2, I have a type that contains a field of type long, but I am having difficulty writing a query against it. The field name is orgId, and always contains an integer, the following queries produce no results:
> > > 
> > > {  
> > > "query": { "range": { "orgId": { "from": 123, "to": 123, "include\_lower": true, "include\_upper": true }}}  
> > > }
> > > 
> > > {  
> > > "query": { "term": { "orgId": "123" }}  
> > > }
> > > 
> > > {  
> > > "query": { "term": { "orgId": 123 }}  
> > > }
> > > 
> > > {  
> > > "query": { "field": { "orgId": "123" }}  
> > > }
> > > 
> > > (and again without the quotes around 123).
> > > 
> > > I'm sure this is such an easy answer, but I can't quite figure it out. It looks similar to this gist: [gist:737631 · GitHub](https://gist.github.com/737631), but the solutions there don't work. If it isn't a simple problem, I'll try to gist a recreation tomorrow...
> > > 
> > > Thanks!
> > > 
> > > Adam

---

<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:04am UTC](https://discuss.elastic.co/t/querying-a-long-field/4569/6 "2017-07-06T04:04:12Z")

</div>


