Finding a sentence in elasticsearch-php

I want to use elasticsearch to retrieve relevant documents. Assume I have, for example, below documents:

1- Is this a book?
2- This is the book.
3- That is a book.
4- They are books.
5- This is a book.

and suppose I want to find the exact sentence or similar to it from documents like "This is a book". I am interested that the results be in order 5, 1, 2, 3, 4 or 5, 2, 1, 3, 4. As we know, to find a sentence (or similar to it) inside documents, we should consider the order of words in the query as a high score. As well as, there may not be a few words in the results (e.g. (4)) but there is one word. Moreover, for this aim, we need to consider these words (to, be, of, ...) in the search.

There is some strategy for full-text search in the Elasticsearch. They are match, match_phrase, and query_string. But no one satisfies the above conditions. The match does not consider the order of words in the results. In the match_phrase, all words must exist in the result. Finally, the query_string that I think it is not appropriate for my goal. please help me with an example.

You probably need to combine different approach.
Have a look at this example:

At the end, I'm combining exact phrases, fuzzy queries, all terms, most terms...

1 Like

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