# Finding a sentence in elasticsearch-php

**URL:** <https://discuss.elastic.co/t/finding-a-sentence-in-elasticsearch-php/142891>\
**Category:** Elasticsearch\
**Created:** [August 3, 2018, 10:22am UTC](https://discuss.elastic.co/t/finding-a-sentence-in-elasticsearch-php/142891 "2018-08-03T10:22:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farrokh\_Yousefi](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@Farrokh\_Yousefi](https://discuss.elastic.co/u/Farrokh_Yousefi)\
**Post date:** [August 3, 2018, 10:22am UTC](https://discuss.elastic.co/t/finding-a-sentence-in-elasticsearch-php/142891/1 "2018-08-03T10:22:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 3, 2018, 10:34am UTC](https://discuss.elastic.co/t/finding-a-sentence-in-elasticsearch-php/142891/2 "2018-08-03T10:34:39Z")

</div>

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

> <https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 31, 2018, 10:34am UTC](https://discuss.elastic.co/t/finding-a-sentence-in-elasticsearch-php/142891/3 "2018-08-31T10:34:40Z")

</div>

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