Search documents having multiple values of a field


I want to search docs with multiple values of a field?

eg. let's say I have job postings. Few of the jobs have multiple locations.
id: 1,
location: 'new york'
id: 2,
location: ['new york', 'london']
id: 3,
location: ['new york', 'london','melbourne]

Now how can I find jobs with 2 or more locations(2 & 3 in this case)?


Best thing to do is to index also the array size in a field so you can just do a range query on it.

Hi David,

Thanks for you reply. I found a solution. I'm using script query with the script "doc['location'].values.size() > 2".

I definitely not recommend that solution unless you don't care about speed.

In my case i don't this query often, so it should work. But to understand, do you mean, the script queries are slower?

and if so, it would be great if you could explain.

Yes. You have to run a script on every document matching the query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.