# How in elasticsearch do a search for several words working in case the words stand not together?

**URL:** <https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595>\
**Category:** Elasticsearch\
**Created:** [September 6, 2017, 2:18pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595 "2017-09-06T14:18:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergei\_kurbako](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@sergei\_kurbako](https://discuss.elastic.co/u/sergei_kurbako)\
**Post date:** [September 6, 2017, 2:18pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595/1 "2017-09-06T14:18:15Z")

</div>

How in elasticsearch do a search for several words working in case the words stand not together?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 6, 2017, 4:18pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595/2 "2017-09-06T16:18:59Z")

</div>

Sorry I don't understand the question, can you explain a bit more what you want to know?

---

<div class="post-metadata">

**Author:** ![sergei\_kurbako](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@sergei\_kurbako](https://discuss.elastic.co/u/sergei_kurbako)\
**Post date:** [September 6, 2017, 4:39pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595/3 "2017-09-06T16:39:53Z")

</div>

I have bad English, sorry 🙂 . I will explain with an example:

In the elastic there are three records:  
query 1: Simple Token Coin  
query 2: Token Simple Coin  
query 3: Coin Token Simple

serch request:  
Simple Token

I have to send a request and get these three lines

My php code with the following parameters does not work:

> ```
> $params = [
> 'index' => 'myapp',
> 'type' => 'post',
> 'size' => 10,
> 'from' => 10,
> 'body' => $json
> 'body' => [
> 'query' => [
> 'match_phrase_prefix' => [
> 'post_title' => [
> "query" => $_POST['test'],
> 'analyzer' => 'russian',
> ]
> ]
> ],
> 'sort' => [
> 'post_title' => [
> 'order' => 'DESC'
> ]
> ]
> ]
> ];
> 
> ```

I need the right options 🙂 or correct actions ...  
Maybe I need an analyzer, but I do not understand how to create and apply it

---

<div class="post-metadata">

**Author:** ![Cameron\_Eby](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@Cameron\_Eby](https://discuss.elastic.co/u/Cameron_Eby)\
**Post date:** [September 15, 2017, 10:36pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595/4 "2017-09-15T22:36:23Z")

</div>

You want to use the queryString query method and set the phrase slop to a value high enough to accommodate all groups of characters(words) that are stored in that field. Quick Red Fox, has 3 positions, right, set slop to 1 would ensure that someone doing a search for 'quick fox' gets a hit. The slop is the number of positions that words need to 'move' to be adjacent to any other. That's how I picture it anyway. 'Quick red' would match with a slop of 0 (default) because the words are already adjacent. In my case I have fields that could consist of 8-10 "words" so I set my slop to high enough for worst case scenarios where the queried string happens to be the first word and the last word in the field. If a field had the value 'The quick red fox jumps over the lazy men.' If the search string was "quick lazy" the slop would need to be set to at least 6 because 'quick' would have to move 6 positions in order to be adjacent to 'lazy.'

---

<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:** [October 13, 2017, 10:37pm UTC](https://discuss.elastic.co/t/how-in-elasticsearch-do-a-search-for-several-words-working-in-case-the-words-stand-not-together/99595/5 "2017-10-13T22:37:06Z")

</div>

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