# How to get nested field value equal to keyword field value

**URL:** <https://discuss.elastic.co/t/how-to-get-nested-field-value-equal-to-keyword-field-value/317360>\
**Category:** Elasticsearch\
**Created:** [October 25, 2022, 2:58am UTC](https://discuss.elastic.co/t/how-to-get-nested-field-value-equal-to-keyword-field-value/317360 "2022-10-25T02:58:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casterQ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casterq/32/93257_2.png) [@casterQ](https://discuss.elastic.co/u/casterQ)\
**Post date:** [October 25, 2022, 2:58am UTC](https://discuss.elastic.co/t/how-to-get-nested-field-value-equal-to-keyword-field-value/317360/1 "2022-10-25T02:58:31Z")

</div>

can i get b value in nested script query?

```auto
PUT test
{
  "mappings": {
    "properties": {
      "b": {
        "type": "keyword"
      },
      "nested": {
        "type": "nested",
        "properties": {
          "a": {
            "type": "keyword"
          }
        }
      }
    }
  }
}
POST test/_search
{
  "query": {
    "nested": {
      "path": "nested",
      "query": {
        "script": {
          "script": """
              doc['nested.a'].value == doc['b'].value
            """
        }
      }
    }
  }
}

```

---

<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:** [November 22, 2022, 2:59am UTC](https://discuss.elastic.co/t/how-to-get-nested-field-value-equal-to-keyword-field-value/317360/2 "2022-11-22T02:59:20Z")

</div>

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