# Search elements inside nested fields

**URL:** <https://discuss.elastic.co/t/search-elements-inside-nested-fields/260056>\
**Category:** Elasticsearch\
**Created:** [January 4, 2021, 6:28am UTC](https://discuss.elastic.co/t/search-elements-inside-nested-fields/260056 "2021-01-04T06:28:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asheesh\_Bhuria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asheesh_bhuria/32/78248_2.png) [@Asheesh\_Bhuria](https://discuss.elastic.co/u/Asheesh_Bhuria)\
**Post date:** [January 4, 2021, 6:28am UTC](https://discuss.elastic.co/t/search-elements-inside-nested-fields/260056/1 "2021-01-04T06:28:16Z")

</div>

Hi,

I have field which stores an array of objects. Each object contains a key on the basis of which we need to perform search operation and get the list of the matched terms only. We have achieved this using a combination of Nested and Filter Aggregation.

But we are unable to sort the results on the basis of their "matching score".

Is there a way we can achieve this?

Here's the query we are using:-

```auto
    {
   "size": 0,
    "aggs": {
        "concepts": {
            "nested": {
                "path": "nestedField"
            },
            "aggs": {
                "concepts": {
                    "filter": {
                        "match": {
                            "nestedField.key": "Search Term"
                        }
                    },
                    "aggs": {
                        "concepts": {
                            "terms": {
                                "field": "nestedField.key",
                                "size": 1000
                            }
                        }
                    }
                }
            }
        }
    }
    }  

```

---

<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:** [February 1, 2021, 6:28am UTC](https://discuss.elastic.co/t/search-elements-inside-nested-fields/260056/2 "2021-02-01T06:28:27Z")

</div>

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