# Phrase\_slop does not affect query\_string

**URL:** <https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345>\
**Category:** Elasticsearch\
**Created:** [November 7, 2022, 3:04pm UTC](https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345 "2022-11-07T15:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MultiheadAttention](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@MultiheadAttention](https://discuss.elastic.co/u/MultiheadAttention)\
**Post date:** [November 7, 2022, 3:04pm UTC](https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345/1 "2022-11-07T15:04:04Z")

</div>

My search query

```auto
{
    "query_string": {"query": 'foo bar',
                                 "phrase_slop": 1,
                                 "default_operator": "AND"}
}

```

returns the following results:

1. 'foo bar'
2. 'foo baz bar'
3. 'foo bip bop bip bop bip bop bar'
4. 'foo baz bip bop bip bop bip bop bar baz'

1 and 2 are matched because the slop is 1, so I'm allowing one token between 'foo' and 'bar'.  
I'm expecting 3 and 4 not to match, because there are more than one token between 'foo' and 'bar'.

What I'm missing?  
How to make it work as I intended?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 7, 2022, 3:11pm UTC](https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345/2 "2022-11-07T15:11:45Z")

</div>

Hi @MultiheadAttention

Documentation Query String query

> Returns documents based on a provided query string, using a parser with a strict syntax.
> 
> This query uses a [syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax) to parse and split the provided query string based on operators, such as `AND` or `NOT`. The query then [analyzes](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html) each split text independently before returning matching documents.

Try use [match\_phrase](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html)

```auto
{
  "query": {
    "match_phrase": {
      "text": {
        "query": "foo bar",
        "slop": 1
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![MultiheadAttention](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@MultiheadAttention](https://discuss.elastic.co/u/MultiheadAttention)\
**Post date:** [November 7, 2022, 3:21pm UTC](https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345/3 "2022-11-07T15:21:51Z")

</div>

Thanks for your reply.

'query\_string' documentation also says:

```auto
phrase_slop

(Optional, integer) Maximum number of positions allowed between matching tokens for phrases.

Defaults to 0. If 0, exact phrase matches are required. Transposed terms have a slop of 2.

```

And I'd like to make it work in 'query\_string'.

I've tried to work with 'match\_phrase' query and the 'slop' parameter works perfectly. The thing is that I also want to use logic operators, especially NOT in my query, and I'm not sure if it's possible in 'match\_phrase' query.

---

<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:** [December 5, 2022, 3:22pm UTC](https://discuss.elastic.co/t/phrase-slop-does-not-affect-query-string/318345/4 "2022-12-05T15:22:03Z")

</div>

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