Searchkick: executing a multi-“match-phrase” query in searchkick with `or` opeator

Created on 10 Jan 2018  ·  5Comments  ·  Source: ankane/searchkick

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?

awaiting response

Most helpful comment

Yes, a match_phrase query will be more performant.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings