Searching exact phrase inside long text

How can I configure a custom analyzer in order to search for an exact match of a phrase inside a long text?

For example, given the following text:

Lorem ipsum dolor sit amet. Aut libero dolorem qui quia nesciunt et pariatur officiis sed error architecto qui ipsum fuga sed placeat quia vel cupiditate architecto. Ea autem veritatis eum ipsa distinctio qui distinctio velit!

I want to have a match when searching “nesciunt et pariatur officiis”, but not when searching “ipsum amet” (since those two words appear in text and in that order, but not next to each other).

Hi @German_Medaglia , you should be able to achieve this by using a predefined analyzer (e.g. lucene.standard) in your index and the phrase operator in your query. Check out the docs here!

2 Likes

Hi @amyjian! Thanks a lot for your reply. I had already tried that, but when searching for example “this is a test”, I get as result one item having the text “Is this email displaying correctly?”. Besides the order of “this” and “is” being inverted, I also would like to return only results having the full input query (not only any of the words).

Can you share an example of the index definition and query that you are using?

Sorry, I think that the unwanted results were being returned as a match for other conditions in the aggregation pipeline. Thanks for your help! I will mark your first answer as solution.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.