jeremywoertink
jeremywoertink

Reputation: 2341

understanding Elasticsearch query with elasticsearch-model ruby gem

I have a search form where I want someone to choose to enter in a query or not, then optionally enter in some sort of filter to get a result. So, dealing with 2 fields name and city, let's say someone searches "billy", and "Las Vegas". The user searching knows there is a name that has "billy" in it, but don't know if it's a first, middle, or last, or maybe it was a street name... The one thing the user knows for sure is that the record is in the city "Las Vegas".

Here is my query hash that gives me 0 results.

{
  query: {
    query_string: {
      query: 'billy'
    }
  },
  filter: {
   and: [
    {term: {city: 'Las Vegas'}}
   ]
 }
}

What am I missing here?

Upvotes: 2

Views: 204

Answers (1)

jeremywoertink
jeremywoertink

Reputation: 2341

Just came across this. Instead of using the elasticsearch-model gem, use the searchkick gem. Tons easier to integrate and query.

Person.search("billy", where: {city: 'Las Vegas'})

This still uses elasticsearch, and returns the exact results I was looking for!

Upvotes: 1

Related Questions