Williamf
Williamf

Reputation: 575

ElasticSearch / Tire & Keywords. Right way to match "or" for a keyword list?

I've got an Entity model (in Mongoid) that I'm trying to search on its keywords field which is an array. I want to do a query where I pass in an array of potential search terms, and any entity that matches any of the terms will pass.

I don't have this working well yet.

But, why I'm asking this question, is that it's more complex. I also DONT want to return any entities that have been marked as "do not return" which I do via a "ignore_project_ids" parameter.

So, when I query, I get 0 results. I was using Bonsai.io. But, I've moved this to my own EC2 instance to reduce complexity/variables on solving the problem.

So, what am I doing wrong? Here are the relevant bits of code.

https://gist.github.com/3405763

Upvotes: 1

Views: 546

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84124

You want a terms query rather than a term query - a term query is only interested in equality, whereas a terms query requires that the field match any of the specified values.

Given that you don't seem to care about the query score (you're sorting by another attribute), you'll get faster queries by using a filtered query and expressing your conditions as filters

Upvotes: 1

Related Questions