# Searching on arrays of strings works, but on arrays of integers fails

**URL:** <https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567>\
**Category:** Elasticsearch\
**Created:** [October 11, 2011, 9:54pm UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567 "2011-10-11T21:54:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug\_livesey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_livesey/32/2114_2.png) [@doug\_livesey](https://discuss.elastic.co/u/doug_livesey)\
**Post date:** [October 11, 2011, 9:54pm UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/1 "2011-10-11T21:54:51Z")

</div>

Hi -- if I have this object indexed like so:  
$ curl -XPUT "[http://localhost:9200/items\_test/items](http://localhost:9200/items_test/items)" '{ "id": 999,  
"colours": ["red", "blue"], "colour\_ids": [4, 9], "status": "forsale" }'

When I do a search on the "colours" array like this:  
$ curl -XGET "[http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
-d '{ "query": { "term": { "colours": "red" } } }'  
It returns the object in the results as I would expect.

However, when I try to search on "colour\_ids" like this:  
$ curl -XGET "[http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
-d '{ "query": { "term": { "colour\_ids": 4 } } }'  
It returns nothing.

Could someone advise me on how I can modify my second search so that it can  
search for items dependent on the "colour\_ids" array of integers?  
Thankyou for any & all assistance,  
Doug.

---

<div class="post-metadata">

**Author:** ![doug\_livesey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_livesey/32/2114_2.png) [@doug\_livesey](https://discuss.elastic.co/u/doug_livesey)\
**Post date:** [October 12, 2011, 9:38am UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/2 "2011-10-12T09:38:27Z")

</div>

Okay, for now I'll just use strings for the ids (which does work), but  
if anyone can suggest a better way, I'd be really grateful.  
Thanks,  
Doug.

On Oct 11, 10:54 pm, doug livesey [biot...@gmail.com](mailto:biot...@gmail.com) wrote:

> Hi -- if I have this object indexed like so:  
> $ curl -XPUT "[http://localhost:9200/items\_test/items](http://localhost:9200/items_test/items)" '{ "id": 999,  
> "colours": ["red", "blue"], "colour\_ids": [4, 9], "status": "forsale" }'
> 
> When I do a search on the "colours" array like this:  
> $ curl -XGET "[http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> -d '{ "query": { "term": { "colours": "red" } } }'  
> It returns the object in the results as I would expect.
> 
> However, when I try to search on "colour\_ids" like this:  
> $ curl -XGET "[http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> -d '{ "query": { "term": { "colour\_ids": 4 } } }'  
> It returns nothing.
> 
> Could someone advise me on how I can modify my second search so that it can  
> search for items dependent on the "colour\_ids" array of integers?  
> Thankyou for any & all assistance,  
> Doug.

---

<div class="post-metadata">

**Author:** ![doug\_livesey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_livesey/32/2114_2.png) [@doug\_livesey](https://discuss.elastic.co/u/doug_livesey)\
**Post date:** [October 12, 2011, 10:15am UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/3 "2011-10-12T10:15:24Z")

</div>

Huh.  
It started working this morning.  
Which is worrying, but I'll start a new thread for that particular worry.

On 12 October 2011 10:38, biot023 [biot023@gmail.com](mailto:biot023@gmail.com) wrote:

> Okay, for now I'll just use strings for the ids (which does work), but  
> if anyone can suggest a better way, I'd be really grateful.  
> Thanks,  
> Doug.
> 
> On Oct 11, 10:54 pm, doug livesey [biot...@gmail.com](mailto:biot...@gmail.com) wrote:
> 
> > Hi -- if I have this object indexed like so:  
> > $ curl -XPUT "[http://localhost:9200/items\_test/items](http://localhost:9200/items_test/items)" '{ "id": 999,  
> > "colours": ["red", "blue"], "colour\_ids": [4, 9], "status": "forsale"  
> > }'
> > 
> > When I do a search on the "colours" array like this:  
> > $ curl -XGET "  
> > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > -d '{ "query": { "term": { "colours": "red" } } }'  
> > It returns the object in the results as I would expect.
> > 
> > However, when I try to search on "colour\_ids" like this:  
> > $ curl -XGET "  
> > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > -d '{ "query": { "term": { "colour\_ids": 4 } } }'  
> > It returns nothing.
> > 
> > Could someone advise me on how I can modify my second search so that it  
> > can  
> > search for items dependent on the "colour\_ids" array of integers?  
> > Thankyou for any & all assistance,  
> > Doug.

---

<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:** [October 12, 2011, 9:16pm UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/4 "2011-10-12T21:16:34Z")

</div>

If you can recreate when it did not work, it would be great.

On Wed, Oct 12, 2011 at 12:15 PM, doug livesey [biot023@gmail.com](mailto:biot023@gmail.com) wrote:

> Huh.  
> It started working this morning.  
> Which is worrying, but I'll start a new thread for that particular worry.
> 
> On 12 October 2011 10:38, biot023 [biot023@gmail.com](mailto:biot023@gmail.com) wrote:
> 
> > Okay, for now I'll just use strings for the ids (which does work), but  
> > if anyone can suggest a better way, I'd be really grateful.  
> > Thanks,  
> > Doug.
> > 
> > On Oct 11, 10:54 pm, doug livesey [biot...@gmail.com](mailto:biot...@gmail.com) wrote:
> > 
> > > Hi -- if I have this object indexed like so:  
> > > $ curl -XPUT "[http://localhost:9200/items\_test/items](http://localhost:9200/items_test/items)" '{ "id": 999,  
> > > "colours": ["red", "blue"], "colour\_ids": [4, 9], "status":  
> > > "forsale" }'
> > > 
> > > When I do a search on the "colours" array like this:  
> > > $ curl -XGET "  
> > > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > > -d '{ "query": { "term": { "colours": "red" } } }'  
> > > It returns the object in the results as I would expect.
> > > 
> > > However, when I try to search on "colour\_ids" like this:  
> > > $ curl -XGET "  
> > > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > > -d '{ "query": { "term": { "colour\_ids": 4 } } }'  
> > > It returns nothing.
> > > 
> > > Could someone advise me on how I can modify my second search so that it  
> > > can  
> > > search for items dependent on the "colour\_ids" array of integers?  
> > > Thankyou for any & all assistance,  
> > > Doug.

---

<div class="post-metadata">

**Author:** ![doug\_livesey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_livesey/32/2114_2.png) [@doug\_livesey](https://discuss.elastic.co/u/doug_livesey)\
**Post date:** [October 13, 2011, 8:49am UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/5 "2011-10-13T08:49:59Z")

</div>

I haven't been able to yet, sorry -- I will try again, but I suspect that  
this was just some weird, anomalous behaviour.

On 12 October 2011 22:16, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> If you can recreate when it did not work, it would be great.
> 
> On Wed, Oct 12, 2011 at 12:15 PM, doug livesey [biot023@gmail.com](mailto:biot023@gmail.com) wrote:
> 
> > Huh.  
> > It started working this morning.  
> > Which is worrying, but I'll start a new thread for that particular worry.
> > 
> > On 12 October 2011 10:38, biot023 [biot023@gmail.com](mailto:biot023@gmail.com) wrote:
> > 
> > > Okay, for now I'll just use strings for the ids (which does work), but  
> > > if anyone can suggest a better way, I'd be really grateful.  
> > > Thanks,  
> > > Doug.
> > > 
> > > On Oct 11, 10:54 pm, doug livesey [biot...@gmail.com](mailto:biot...@gmail.com) wrote:
> > > 
> > > > Hi -- if I have this object indexed like so:  
> > > > $ curl -XPUT "[http://localhost:9200/items\_test/items](http://localhost:9200/items_test/items)" '{ "id": 999,  
> > > > "colours": ["red", "blue"], "colour\_ids": [4, 9], "status":  
> > > > "forsale" }'
> > > > 
> > > > When I do a search on the "colours" array like this:  
> > > > $ curl -XGET "  
> > > > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > > > -d '{ "query": { "term": { "colours": "red" } } }'  
> > > > It returns the object in the results as I would expect.
> > > > 
> > > > However, when I try to search on "colour\_ids" like this:  
> > > > $ curl -XGET "  
> > > > [http://localhost:9200/items\_test/items/\_search?pretty=true](http://localhost:9200/items_test/items/_search?pretty=true)"  
> > > > -d '{ "query": { "term": { "colour\_ids": 4 } } }'  
> > > > It returns nothing.
> > > > 
> > > > Could someone advise me on how I can modify my second search so that it  
> > > > can  
> > > > search for items dependent on the "colour\_ids" array of integers?  
> > > > Thankyou for any & all assistance,  
> > > > Doug.

---

<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, 3:52am UTC](https://discuss.elastic.co/t/searching-on-arrays-of-strings-works-but-on-arrays-of-integers-fails/5567/6 "2017-07-06T03:52:07Z")

</div>


