# Minimum\_should\_match don´t return correctly

**URL:** <https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967>\
**Category:** Elasticsearch\
**Created:** [May 30, 2022, 2:20pm UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967 "2022-05-30T14:20:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardohmferreira](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@eduardohmferreira](https://discuss.elastic.co/u/eduardohmferreira)\
**Post date:** [May 30, 2022, 2:20pm UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/1 "2022-05-30T14:20:07Z")

</div>

Hy everyone!

I'm new to the elastic universe and I have a question about a query. I'll try to describe it here:

I have a document called 'store' with several stores registered and within each store item a list of customers:

```auto
loja {
  nome,
  telefone,
  email,
  clientes : [
   {
      nomeCliente,
      telefone,
      email
   }
  ]
}

```

I need a query where I would have to return at least 1 pair of customers from the same registered store

For example:  
I research 'Ana Maria', 'Sandra Maria' and 'Alberto Braz', where I would need to return the stores that have [Ana Maria and Sandra Maria] or [Ana Maria and Alberto Braz] or [Sandra Maria and Alberto Braz].  
I did the search according to the dsl below, but the minimum\_should\_match clause is not respecting the limit of 2 m and returning results with only 1 record found.  
Am I doing something wrong in the query?  
Could you help me out on this one?

Query:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "bool":{
                "should": {
                    "match": {
                        "clientes.nomeCliente" : {
                          "query" : "ANA MARIA",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    }
                },
                "should": {
                    "match":{
                        "clientes.nomeCliente" : {
                          "query" : "SANDRA MARIA",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    }
                },
                "should": {
                    "match":{
                        "clientes.nomeCliente" : {
                          "query" : "ALBERTO BRAZ",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    }
                }
              },"minimum_should_match": 2
            },
            "path": "clientes",
            "inner_hits" : {
                "size" : 10
            }
          }
        }
      ]
    }
  }
}

```

---

<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:** [May 30, 2022, 2:33pm UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/2 "2022-05-30T14:33:56Z")

</div>

I think it should be something like this instead:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "bool":{
                "should": [
                    "match": {
                        "clientes.nomeCliente" : {
                          "query" : "ANA MARIA",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    },
                    "match":{
                        "clientes.nomeCliente" : {
                          "query" : "SANDRA MARIA",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    },
                    "match":{
                        "clientes.nomeCliente" : {
                          "query" : "ALBERTO BRAZ",
                          "type" : "phrase",
                          "operator": "and",
                          "slop" : 40
                        }
                    }
                ]
              },"minimum_should_match": 2
            },
            "path": "clientes",
            "inner_hits" : {
                "size" : 10
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![eduardohmferreira](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@eduardohmferreira](https://discuss.elastic.co/u/eduardohmferreira)\
**Post date:** [May 30, 2022, 5:31pm UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/3 "2022-05-30T17:31:52Z")

</div>

@dadoonet , thank you very much for the feedback. I made your suggestion, but this one didn't return any records.  
I believe that the minimum does not deal with this type of situation.  
Again, thank you very much for your attention.

---

<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:** [May 31, 2022, 2:30am UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/4 "2022-05-31T02:30:47Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![eduardohmferreira](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@eduardohmferreira](https://discuss.elastic.co/u/eduardohmferreira)\
**Post date:** [May 31, 2022, 11:24am UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/5 "2022-05-31T11:24:39Z")

</div>

@dadoonet , I'll be collecting this data and I'll pass it on to you.

---

<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:** [June 28, 2022, 11:25am UTC](https://discuss.elastic.co/t/minimum-should-match-don-t-return-correctly/305967/6 "2022-06-28T11:25:30Z")

</div>

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