Filter on array entries?


(Ben Woosley) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/dd7e2607-ef70-474f-85a8-fbc0c5ade5a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2