Hi,
I'm wondering if the following is possible? I've tried to simplify my issue into a short example:
Given three items, each with an array of dates:
{ "title": "item 1", "dates": [ "2016-04-21T12:00:00.000Z", "2016-04-29T12:00:00.000Z", "2016-05-05T12:00:00.000Z" ] } { "title": "item 2", "dates": [ "2016-04-23T12:00:00.000Z", "2016-04-30T12:00:00.000Z", "2016-05-07T12:00:00.000Z" ] } { "title": "item 3", "dates": [ "2016-04-27T12:00:00.000Z", "2016-04-28T12:00:00.000Z", "2016-05-29T12:00:00.000Z" ] }
I can search for a range of dates:
"query": { "bool": { "must": [ { "range": { "dates": { "from": "2016-04-25T00:00:00.000Z", "to": "2016-04-30T00:00:00.000Z" } } } ] } }
Which correctly returns Item 1 and Item 3. However, within my date range, the next occurring date is actually in Item 3. (Date range is 25/04 to 30/04, Item 3 is on 28/04, Item 1 is on 29/04).
However, adding a sort
"sort": [ { "dates": { "order": "asc" } }
returns Item 1 first, presumably because the first date in that array is earlier.
Is there any way of doing this (without scripting)? Or is there another way of structuring my data that may allow it?
Thanks for any pointers!
Geoff