Minimum_should_match don´t return correctly

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:

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:

{
  "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
            }
          }
        }
      ]
    }
  }
}

I think it should be something like this instead:

{
  "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
            }
          }
        }
      ]
    }
  }
}

@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.

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

1 Like

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

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