# Elastic Search matrix\_stats on both nested and non nested value

**URL:** <https://discuss.elastic.co/t/elastic-search-matrix-stats-on-both-nested-and-non-nested-value/311492>\
**Category:** Elasticsearch\
**Created:** [August 5, 2022, 8:53am UTC](https://discuss.elastic.co/t/elastic-search-matrix-stats-on-both-nested-and-non-nested-value/311492 "2022-08-05T08:53:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mspprasath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mspprasath/32/98161_2.png) [@Mspprasath](https://discuss.elastic.co/u/Mspprasath)\
**Post date:** [August 5, 2022, 8:53am UTC](https://discuss.elastic.co/t/elastic-search-matrix-stats-on-both-nested-and-non-nested-value/311492/1 "2022-08-05T08:53:48Z")

</div>

we have a doc structure

```auto
[{
  score: 10,
  list: [ // nested type
    {
      id : 3,
      value: 10
    },
    {
      id: 4
      value: 20
    },
    {
      id: 5,
      value: 15
    }
  ]
},
{
  score: 1,
  list: [
    {
      id : 3,
      value: 4
    },
    {
      id: 4
      value: 3
    },
    {
      id: 5,
      value: 2
    }
  ]
}...

```

we're trying to do matrix\_stats aggregation on field “score” and nested field “value” and considering only specific ids like 4,

we couldn't find a way to do matrix\_stats aggregation on both nested(list.value) and non nested(score) field

example, in 1st doc score is 10 and value of nested list matching id = 4 is 20 … likewise any possible ways to get the value by scripts or runtimeMapping etc….

or is there any way we can access parent field inside nested aggregation for matrix\_stats aggregation

---

<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 2, 2022, 8:54am UTC](https://discuss.elastic.co/t/elastic-search-matrix-stats-on-both-nested-and-non-nested-value/311492/2 "2022-09-02T08:54:16Z")

</div>

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