title: Query and sort inside nested object
body: <p>I am trying to sort my search results based on a field inside a nested object. The mapping of the nested object looks like this:</p>
  <pre><code>{
    &quot;metaDates&quot;: {
      &quot;type&quot;: &quot;nested&quot;,
      &quot;properties&quot;: {
        &quot;name&quot;: {
          &quot;type&quot;: &quot;text&quot;,
          &quot;fields&quot;: {
            &quot;keyword&quot;: {
              &quot;type&quot;: &quot;keyword&quot;,
              &quot;ignore_above&quot;: 256
            }
          }
        },
        &quot;qualifiers&quot;: {
          &quot;type&quot;: &quot;text&quot;,
          &quot;fields&quot;: {
            &quot;keyword&quot;: {
              &quot;type&quot;: &quot;keyword&quot;,
              &quot;ignore_above&quot;: 256
            }
          }
        },
        &quot;value&quot;: {
          &quot;type&quot;: &quot;date&quot;,
          &quot;format&quot;: &quot;date_optional_time&quot;
        }
      }
    }
  }
  </code></pre>
  <p>So there can be many metaDates objects inside one document. Those will typically look like this:</p>
  <pre><code>{
    &quot;metaDates&quot;: [
      {
        &quot;name&quot;: &quot;create-time&quot;,
        &quot;value&quot;: &quot;2020-06-03T13:14:11.556Z&quot;,
        &quot;qualifiers&quot;: [
          &quot;*&quot;
        ]
      },
      {
        &quot;name&quot;: &quot;update-time&quot;,
        &quot;value&quot;: &quot;2020-06-03T13:14:11.556Z&quot;,
        &quot;qualifiers&quot;: [
          &quot;*&quot;
        ]
      }
    ]
  }
  </code></pre>
  <p>What I want to achieve is to order the results based on either create-time or update-time. Ascending and/or descending.</p>
  <p>I can't make this to fully work. As it currently stands I can't enforce it to only look at the given date, it seems to me as it validates all metaDates values instead of just the one I'm interested in when ordering. (setting sort mode affects the results, that's why I think that is the case)</p>
  <p>Sample data:</p>
  <pre><code>{
    &quot;_index&quot;: &quot;index-someitem-1630649750000&quot;,
    &quot;_type&quot;: &quot;_doc&quot;,
    &quot;_id&quot;: &quot;17&quot;,
    &quot;_score&quot;: null,
    &quot;_source&quot;: {
      &quot;id&quot;: 17,
      &quot;title&quot;: &quot;test&quot;,
      &quot;metaTexts&quot;: [
        {
          &quot;name&quot;: &quot;title&quot;,
          &quot;value&quot;: &quot;test&quot;,
          &quot;qualifiers&quot;: [
            &quot;en_US&quot;
          ]
        }
      ],
      &quot;metaDates&quot;: [
        {
          &quot;name&quot;: &quot;create-time&quot;,
          &quot;value&quot;: &quot;2020-06-03T13:14:24.502Z&quot;,
          &quot;qualifiers&quot;: [
            &quot;*&quot;
          ]
        },
        {
          &quot;name&quot;: &quot;update-time&quot;,
          &quot;value&quot;: &quot;2020-06-03T13:14:29.140Z&quot;,
          &quot;qualifiers&quot;: [
            &quot;*&quot;
          ]
        }
      ]
    },
    &quot;sort&quot;: [
      1591190064502
    ]
  }
  </code></pre>
  <p>I want the resulting documents to be sorted based on the either create-time or update-time (inside nested object)</p>
  <p>Any help is much appreciated! Thank you</p>