user2677503
user2677503

Reputation: 1

elasticsearch tire gem exact match

I'm currently using Tire to access my ES data however I've not been able to get it to do an exact match, for instance

User.search :per_page => 10 do 
 query do
    boolean do
       must { match :first_name, 'tom'}
       must { match :last_name, 'smith'}
       end
   end
end

However that returns firstnames that are tom, tomas, tommy and tomiena.. when I'd like it to only match tom.

Upvotes: 0

Views: 796

Answers (2)

Vamsi Krishna
Vamsi Krishna

Reputation: 3792

Try the match_phrase query,

User.search :per_page => 10 do 
 query do
    boolean do
       must { match :first_name, 'tom', :type => :phrase}
       must { match :last_name, 'smith', :type => :phrase}
       end
   end
end

Upvotes: 1

user874647
user874647

Reputation: 49

You can try with a query_string query :

User.search :per_page => 10 do 
 query do
    boolean do
       must { string 'first_name:tom'}
       must { string 'last_name:smith'}
       end
   end
end

If that doesn't work it means that you'd have to check on your analyser.

Upvotes: 0

Related Questions