# .NET Client - include max\_children property in nested sorting

**URL:** <https://discuss.elastic.co/t/net-client-include-max-children-property-in-nested-sorting/161472>\
**Category:** Elasticsearch\
**Created:** [December 19, 2018, 8:33am UTC](https://discuss.elastic.co/t/net-client-include-max-children-property-in-nested-sorting/161472 "2018-12-19T08:33:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyk](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@pyk](https://discuss.elastic.co/u/pyk)\
**Post date:** [December 19, 2018, 8:33am UTC](https://discuss.elastic.co/t/net-client-include-max-children-property-in-nested-sorting/161472/1 "2018-12-19T08:33:20Z")

</div>

Hi, based on documentation and 6.5 release notes, we've new property in sorting by nested, named max\_children. How to pass this property in .net client?

Here's my sort descriptor:

> SortDescriptor.Field(x =\> x.Field(y =\> y.Variants[0].GrossPrice).Order(SortOrder.Ascending).Nested(n =\> n.Path(p =\> p.Variants).Filter(f =\> filerContainer)))

and the sort part of json output

> "variants.gross\_price": {  
> "order": "asc",  
> "nested": {  
> "path": "variants",  
> **"max\_children": 1,**  
> "filter": {  
> [...]

Max\_children is the property i want to pass in. Currently it isn't there. It seems to me it should look like:

> SortDescriptor.Field(x =\> x.Field(y =\> y.Variants[0].GrossPrice).Order(SortOrder.Ascending).Nested(n =\> n.Path(p =\> p.Variants).MaxChildren(1).Filter(f =\> filerContainer)))

but there's an error: "NestedSortDescriptor doest not contain a definition for MaxChildren.."

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [December 28, 2018, 12:50am UTC](https://discuss.elastic.co/t/net-client-include-max-children-property-in-nested-sorting/161472/2 "2018-12-28T00:50:07Z")

</div>

I answered your [same question on stackoverflow](https://stackoverflow.com/a/53952473/1831), but will add here for completeness.

`max_children` on nested sort will be implemented in the client in the next release. In the meantime, it can be implemented by deriving from `NestedSort`

```auto
    public class MyNestedSort : Nest.NestedSort
    {
        [PropertyName("max_children")]
        public int? MaxChildren { get; set; }
    }

```

and then used

```auto
    var client = new ElasticClient();

    var searchResponse = client.Search<MyDocument>(s => s
        .Query(q => q
            .MatchAll()
        )
        .Sort(so => so
            .Field(f => 
                new SortField
                {
                    Field = Infer.Field<MyDocument>(ff => ff.Variants[0].GrossPrice),
                    Order = Nest.SortOrder.Ascending,
                    Nested = new MyNestedSort
                    {
                        Path = Infer.Field<MyDocument>(ff => ff.Variants),
                        MaxChildren = 1,
                        Filter = new MatchAllQuery()
                    }
                }
            )
        )
    );   

```

which yields

```json
    {
      "query": {
        "match_all": {}
      },
      "sort": [
        {
          "variants.grossPrice": {
            "nested": {
              "max_children": 1,
              "filter": {
                "match_all": {}
              },
              "path": "variants"
            },
            "order": "asc"
          }
        }
      ]
    }

```

---

<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 25, 2019, 12:50am UTC](https://discuss.elastic.co/t/net-client-include-max-children-property-in-nested-sorting/161472/3 "2019-01-25T00:50:17Z")

</div>

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