title: Elasticsearch sorting by nested field in nested array
body: <p>I'm using ElasticSearch 7.2.1 and NEST 7.2.1</p>
  <p>My data structure is following</p>
  <pre><code>{
    id: &quot;some_id&quot;,
    &quot;roles&quot; : [
    {
      &quot;name&quot; : &quot;role_one_name&quot;,
      &quot;members&quot; : [
      {
        &quot;id&quot; : &quot;member_one_id&quot;,
        &quot;name&quot; : &quot;member_one_name&quot;,
      }
      ]
    },
    {
      &quot;name&quot; : &quot;role_two_name&quot;,
      &quot;members&quot; : [
      {
        &quot;id&quot; : &quot;member_two_id&quot;,
        &quot;name&quot; : &quot;member_two_name&quot;,
      }
      ]
    ]
  }
  </code></pre>
  <p>The idea is that I need to implement sorting by given role name (e.g. <strong>role_one_name</strong>).
  Sorting should be performed on members.name (e.g. <strong>members[0].name</strong>). In my case members array will always contain one element, but for some roles (omitted in the example) it contains more that one element, so I can't get rid of nested array.</p>
  <p>In my head I have an algorithm:</p>
  <ol>
  <li>Get needed role by name.</li>
  <li>Specify path to the first element in members array.</li>
  <li>Point to the name property to sort on.</li>
  </ol>
  <p>I'm a newbie in elasticsearch world, and after few days of trying I got a following query (which does not work).</p>
  <pre><code>var sortFilters = new List&lt;Func&lt;FieldSortDescriptor&lt;T&gt;, FieldSortDescriptor&lt;T&gt;&gt;&gt;(); 
  var sortFieldValue = &quot;role_two_name&quot;;
  ...
  
  sortFilters.Add(o =&gt; o.Nested(n =&gt; n
      .Path(p =&gt; p.Roles)
      .Filter(f =&gt; f
          .Term(t =&gt; t
              .Field(c =&gt; c.Roles.First().Name)
              .Value(sortFieldValue)) &amp;&amp; f
          .Nested(n =&gt; n
              .Path(p =&gt; p.Roles.First().Members)
              .Query(q =&gt; q
                  .Term(t =&gt; t
                      .Field(f =&gt; f.Roles.First().Members.First().Name)))))));
  </code></pre>
  <p>What am I doing wrong?</p>