ElasticSearch. Select by date range in array of dates and sort by matching dates

Here is the solution: https://stackoverflow.com/a/64010705/518704

Your docs are slightly malformed. If you want proper nested-ness, you'll need to refactor them like so:

{
  "dtmSent":[
    {
      "dtmSent":"1990-01-01"
    },
    {
      "dtmSent":"2000-05-01"
    },
    {
      "dtmSent":"2020-01-01"
    }
  ]
}

instead of the array-of-strings.

The index mapping can stay the same, the query too as well as the sorting part. After that, the order will work as you expect 1 -> 3 -> 2.

After you drop the index, here's the _bulk command to get you started (only after setting the mapping of course):

POST _bulk
{"index":{"_index":"my-index-000001","_type":"_doc","_id":1}}
{"dtmSent":[{"dtmSent":"1990-01-01"},{"dtmSent":"2000-01-01"},{"dtmSent":"2000-01-02"},{"dtmSent":"2020-01-01"}]}
{"index":{"_index":"my-index-000001","_type":"_doc","_id":2}}
{"dtmSent":[{"dtmSent":"1990-01-01"},{"dtmSent":"2000-05-01"},{"dtmSent":"2020-01-01"}]}
{"index":{"_index":"my-index-000001","_type":"_doc","_id":3}}
{"dtmSent":[{"dtmSent":"1990-01-01"},{"dtmSent":"2000-03-01"},{"dtmSent":"2020-01-01"}]}
{"index":{"_index":"my-index-000001","_type":"_doc","_id":4}}
{"dtmSent":[{"dtmSent":"1990-01-01"},{"dtmSent":"2002-03-01"},{"dtmSent":"2020-01-01"}]}