Hi, I have the problem, try to search multiple phrases in one query. I want to match all documents that contain one of phrases exactly as entered.
Comment.search(["first phrase", "second phrase", "third phrase"], fields: [{body: :phrase}], operator: :or)
I tried to do something like this, but it's, obviously, doesn't work.
Can you help me?
Hey @kholtobin, you'll need to use the Elasticsearch DSL directly for this: https://github.com/ankane/searchkick#advanced
Thanks for the reply @ankane, but I just discovered that can do this:
Comment.search({ fields: [{body: :phrase}], where: {body: /.*(first phrase|second phrase|third phrase).*/}})
Regular expression queries can be pretty slow, but should work fine for a small data set.
@ankane you mean that for better performance i should use Elasticsearch DSL, not a regullar experssions?
In my case i parse comments (around 1 million)
Yes, a match_phrase query will be more performant.
Most helpful comment
Yes, a
match_phrasequery will be more performant.