From 8ebd980c76c72f3744ede6f65627ca287a9ea67e Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 5 Apr 2018 16:41:12 +0000 Subject: [PATCH] fix time handling in ES --- pygeoapi/provider/elasticsearch_.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pygeoapi/provider/elasticsearch_.py b/pygeoapi/provider/elasticsearch_.py index d5e765d..bb10084 100644 --- a/pygeoapi/provider/elasticsearch_.py +++ b/pygeoapi/provider/elasticsearch_.py @@ -116,18 +116,25 @@ class ElasticsearchProvider(BaseProvider): time_field = 'properties.{}'.format(self.time_field) if '/' in time: # envelope - range_ = {'range': time_field} + LOGGER.debug('detected time range') time_begin, time_end = time.split('/') - if time_begin == '': # until - range_['range'][time_field]['lte'] = time_end - if time_end == '': # from - range_['range'][time_field]['gte'] = time_begin + range_ = { + 'range': { + time_field: { + 'gte': time_begin, + 'lte': time_end, + } + } + } + filter_.append(range_) else: # time instant + LOGGER.debug('detected time instant') filter_.append({'match': {time_field: time}}) + LOGGER.debug(filter_) query['query']['bool']['filter'].append(filter_) try: