# Get data in daterange plus first date before and after this daterange

**URL:** <https://discuss.elastic.co/t/get-data-in-daterange-plus-first-date-before-and-after-this-daterange/78097>\
**Category:** Elasticsearch\
**Created:** [March 10, 2017, 6:39am UTC](https://discuss.elastic.co/t/get-data-in-daterange-plus-first-date-before-and-after-this-daterange/78097 "2017-03-10T06:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_K](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@M\_K](https://discuss.elastic.co/u/M_K)\
**Post date:** [March 10, 2017, 6:39am UTC](https://discuss.elastic.co/t/get-data-in-daterange-plus-first-date-before-and-after-this-daterange/78097/1 "2017-03-10T06:39:33Z")

</div>

I am quite new to elasticsearch and I am impressed by all the functionality it offers. Now I have a special case, where I am not sure if elasticsearch will be able to handle it.

Overall I am searching for a type within a daterange. But in addition I need the first date before and after this daterange as well. I do not know how far these dates are away, so I can not just add a specific amount of days to the daterange.

I know this would be possible with 3 different queries, but would it be possible in just one query as well?

Here is a small example what I would like to achieve

[uuid1] = [  
['id' =\> 1, 'date' =\> '1970/01/01 12:00:00', 'val' =\> 'ages ago'],  
['id' =\> 2, 'date' =\> '2010/01/01 12:00:00', 'val' =\> 'randomValueSomewhereInThePast'],  
['id' =\> 3, 'date' =\> '2017/01/03 12:00:00', 'val' =\> 'valueInTimeRange3'],  
['id' =\> 4, 'date' =\> '2017/01/04 12:00:00', 'val' =\> 'valueInTimeRange4'],  
['id' =\> 5, 'date' =\> '2017/01/05 12:00:00', 'val' =\> 'valueInTimeRange5'],  
['id' =\> 6, 'date' =\> '2017/01/06 12:00:00', 'val' =\> 'valueInTimeRange6'],  
['id' =\> 7, 'date' =\> '2020/01/05 12:00:00', 'val' =\> 'randomValueSomewhereInTheFuture']  
['id' =\> 8, 'date' =\> '9999/01/05 12:00:00', 'val' =\> 'wayTooFarAway']  
]

As you can see I got several dates. Now I have a given DateRange from

So a simple request with range would return me values 3,4,5,6. But I need values 2 & 7 aswell. These are the dates right before and right after my range. I do not know when they are so I can not just adjust the rang.

Is this possible in elasticsearch with just one query?

Thank you!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2017, 10:02pm UTC](https://discuss.elastic.co/t/get-data-in-daterange-plus-first-date-before-and-after-this-daterange/78097/2 "2017-03-13T22:02:18Z")

</div>

Hey,

you should go with three queries here. Just use the [multi search API](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-multi-search.html)

--Alex

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 10, 2017, 10:02pm UTC](https://discuss.elastic.co/t/get-data-in-daterange-plus-first-date-before-and-after-this-daterange/78097/3 "2017-04-10T22:02:22Z")

</div>

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