# How to use slop and minimum\_should\_match together in some query?

**URL:** https://discuss.elastic.co/t/how-to-use-slop-and-minimum-should-match-together-in-some-query/190352
**Category:** Elasticsearch
**Created:** [July 13, 2019, 3:34pm UTC](https://discuss.elastic.co/t/how-to-use-slop-and-minimum-should-match-together-in-some-query/190352 "2019-07-13T15:34:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![princesahu04](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/princesahu04/32/47235_2.png) [@princesahu04](https://discuss.elastic.co/u/princesahu04)
#### Post date: [July 13, 2019, 3:34pm UTC](https://discuss.elastic.co/t/how-to-use-slop-and-minimum-should-match-together-in-some-query/190352/1 "2019-07-13T15:34:21Z")

</div>

Basically, my objective is to search for some sentences with slope and also with minimum\_should\_match.  
For example:

```
> GET my_index/_search
> {
> "query": {
> "field": "provided that immediately after giving effect to any such incurrence",
> "minimum_should_match": 7
> }
> "slop": 3
> }

```

This code is wrong but I want something like this. If I search for some sentence then I can tune it with minimum\_should\_match and also with slop.  
If this objective can be sort by some other query then feel free to comment

---

<div class="post-metadata">

### Author: ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)
#### Post date: [July 20, 2019, 8:40pm UTC](https://discuss.elastic.co/t/how-to-use-slop-and-minimum-should-match-together-in-some-query/190352/2 "2019-07-20T20:40:28Z")

</div>

Hi @princesahu04,

I'm not sure I fully understand but you could combine a `match_phrase` to declare the slop and a `match` query to declare the minimum should match.

```auto
PUT test/_doc/1
{
  "project": "token1 token2 token3 token4 token5"
}

```

The following query will return results:

```auto
GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "project": {
              "query": "token1 token4 token5",
              "slop": 3
            }
          }
        },
        {
          "match": {
            "project": {
              "query": "token1 token4 token5",
              "minimum_should_match": 3
            }
          }
        }
      ]
    }
  }
}

```

Results:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.5617933,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 2.5617933,
        "_source" : {
          "project" : "token1 token2 token3 token4 token5"
        }
      }
    ]
  }
}

```

But if the query contains only 2 terms it won't return results because it doesn't have the minimum should match terms:

```auto
GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "project": {
              "query": "token1 token5",
              "slop": 3
            }
          }
        },
        {
          "match": {
            "project": {
              "query": "token1 token5",
              "minimum_should_match": 3
            }
          }
        }
      ]
    }
  }
}

```

Results:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

I hope it helps!

---

<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 17, 2019, 8:40pm UTC](https://discuss.elastic.co/t/how-to-use-slop-and-minimum-should-match-together-in-some-query/190352/3 "2019-08-17T20:40:31Z")

</div>

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