.NET Client - include max_children property in nested sorting

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.."

I answered your same question on stackoverflow, 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

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

and then used

    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

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

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