# Apply "doesn't equal" with nested query

**URL:** <https://discuss.elastic.co/t/apply-doesnt-equal-with-nested-query/311821>\
**Category:** Elasticsearch\
**Created:** [August 10, 2022, 11:16am UTC](https://discuss.elastic.co/t/apply-doesnt-equal-with-nested-query/311821 "2022-08-10T11:16:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anh\_Le](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anh_le/32/109473_2.png) [@Anh\_Le](https://discuss.elastic.co/u/Anh_Le)\
**Post date:** [August 10, 2022, 11:16am UTC](https://discuss.elastic.co/t/apply-doesnt-equal-with-nested-query/311821/1 "2022-08-10T11:16:42Z")

</div>

Hi there!

Please help to suggest queries to get data. How to get documents that don't have FilterFields. ContentFieldUseID = 20 and FilterFields.ContentFieldValues = "[aaaa@gmail.com](mailto:aaaa@gmail.com)".

Expected result: I want to get two documents that have IDProperty : "15-118", "15-119".

Thanks for your help

```auto
{
          "IDProperty" : "15-117",
          "ContentTitle" : "Anh Le",
          "ContentSummary" : "",
          "FilterFields" : [
            {
              "ContentFieldUseID" : 20,
              "ContentFieldValues" : [
                "aaaa@gmail.com"
              ]
            },
            {
              "ContentFieldUseID" : 21,
              "ContentFieldValues" : [
                "anh le"
              ]
            }
},
{
          "IDProperty" : "15-118",
          "ContentTitle" : "Anh Le 2",
          "ContentSummary" : "",
          "FilterFields" : [
            {
              "ContentFieldUseID" : 20,
              "ContentFieldValues" : [
                "yyyy@gmail.com"
              ]
            },
            {
              "ContentFieldUseID" : 21,
              "ContentFieldValues" : [
                "anh le 2"
              ]
            }
},
{
          "IDProperty" : "15-119",
          "ContentTitle" : "Anh Le 3",
          "ContentSummary" : "",
          "FilterFields" : [
            {
              "ContentFieldUseID" : 21,
              "ContentFieldValues" : [
                "anh le 3"
              ]
           }
}

```

---

<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:** [August 10, 2022, 9:13pm UTC](https://discuss.elastic.co/t/apply-doesnt-equal-with-nested-query/311821/2 "2022-08-10T21:13:56Z")

</div>

Hi @Anh_Le

Try this query:

```auto
{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "FilterFields",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "FilterFields.ContentFieldUseID": {
                        "value": 20
                      }
                    }
                  },
                  {
                    "term": {
                      "FilterFields.ContentFieldValues": {
                        "value": "aaaa@gmail.com"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

```

I used this mapping:

```auto
PUT test
{
  "mappings": {
    "properties": {
      "FilterFields": {
        "type": "nested",
        "properties": {
          "ContentFieldValues": {
            "type": "keyword"
          },
          "ContentFieldUseID": {
            "type": "integer"
          }
        }
      }
    }
  }
}

```

---

<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:** [September 7, 2022, 9:14pm UTC](https://discuss.elastic.co/t/apply-doesnt-equal-with-nested-query/311821/3 "2022-09-07T21:14:04Z")

</div>

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