# How to replace "and" operator inside "must\_not" to group clauses. Query migration to ES 7.6.1

**URL:** <https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706>\
**Category:** Elasticsearch\
**Created:** [December 21, 2022, 12:08am UTC](https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706 "2022-12-21T00:08:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aanaya](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aanaya](https://discuss.elastic.co/u/aanaya)\
**Post date:** [December 21, 2022, 12:08am UTC](https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706/1 "2022-12-21T00:08:40Z")

</div>

Hi guys, I'm trying to migrate following query to ES 7.6.1, but not sure how to replace "and" functionality cause it looks like it's not longer supported in ES 7.6.1.

```auto
...
  "must_not": [
    {
      "and": [
        {
          "term": {
            "status": "complete"
          }
        },
        {
          "range": {
            "startDate": {
              "lte": "2021-12-19"
            }
          }
        }
      ]
    },
    {
      "and": [
        {
          "term": {
            "status": "complete"
          }
        },
        {
          "range": {
            "updatedTs": {
              "lte": 1670881333350
            }
          }
        }
      ]
    }
  ]
...

```

---

<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:** [December 21, 2022, 12:51am UTC](https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706/2 "2022-12-21T00:51:15Z")

</div>

Hi @aanaya

If you and AND behavior try use bool + must

```auto
{
  "query": {
    "bool": {
      "must_not": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "status": "complete"
                }
              },
              {
                "range": {
                  "startDate": {
                    "lte": "2021-12-19"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "term": {
                  "status": "complete"
                }
              },
              {
                "range": {
                  "updatedTs": {
                    "lte": 1670881333350
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 21, 2022, 12:51am UTC](https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706/3 "2022-12-21T00:51:31Z")

</div>

FWIW 7.6 is [EOL](https://www.elastic.co/support/eol) and no longer supported, you should be upgrading to 7.17 at the very latest.

---

<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:** [January 18, 2023, 12:51am UTC](https://discuss.elastic.co/t/how-to-replace-and-operator-inside-must-not-to-group-clauses-query-migration-to-es-7-6-1/321706/4 "2023-01-18T00:51:38Z")

</div>

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