# Filter on array entries?

**URL:** <https://discuss.elastic.co/t/filter-on-array-entries/19041>\
**Category:** Elasticsearch\
**Created:** [August 1, 2014, 11:31pm UTC](https://discuss.elastic.co/t/filter-on-array-entries/19041 "2014-08-01T23:31:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Woosley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben_woosley/32/1357_2.png) [@Ben\_Woosley](https://discuss.elastic.co/u/Ben_Woosley)\
**Post date:** [August 1, 2014, 11:31pm UTC](https://discuss.elastic.co/t/filter-on-array-entries/19041/1 "2014-08-01T23:31:27Z")

</div>

Hey Guys,

I have some articles that are associated with groups, and I want to select  
all articles that have a certain group id associated, but elasticsearch  
isn't returning the results in a query. I've tried a number of different  
approaches and I hope someone here can tell me what I'm doing wrong.

Here's the relevant part of the mapping (in standard elasticsearch-rails  
format)

has\_many :groups

mapping do  
indexes :group\_ids # this is just an array of ids  
end

def as\_indexed\_json(options={})  
as\_json(methods: [  
'group\_ids'  
])  
end

Here's are some filter queries that fail to select the articles associated  
with a certain group:

Article.search(  
filter: { term: { 'group\_ids' =\> '8c7664ac-9f0a-41b1-824b-d6a23170bb3e' }  
}  
)

Article.search(  
query: {  
filtered: {  
query: { match\_all: {} },  
filter: { term: { 'group\_ids' =\>  
'8c7664ac-9f0a-41b1-824b-d6a23170bb3e' } }  
}  
}  
)

And here's a query that does select them:

Article.search(  
query: {  
match: { 'group\_ids' =\> '8c7664ac-9f0a-41b1-824b-d6a23170bb3e' }  
}  
)

Can someone tell me why this is failing? I'm running against elasticsearch  
1.2.1 and elasticsearch-rails 0.1.4.

--  
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/dd7e2607-ef70-474f-85a8-fbc0c5ade5a1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dd7e2607-ef70-474f-85a8-fbc0c5ade5a1%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:11am UTC](https://discuss.elastic.co/t/filter-on-array-entries/19041/2 "2017-07-06T01:11:29Z")

</div>


