diff --git a/lib/readers/elasticsearch_date_range/slicer.js b/lib/readers/elasticsearch_date_range/slicer.js index a96a7ca80c4..f157112468e 100644 --- a/lib/readers/elasticsearch_date_range/slicer.js +++ b/lib/readers/elasticsearch_date_range/slicer.js @@ -21,14 +21,6 @@ function newSlicer(context, opConfig, executionContext, retryData, logger, clien const elasticsearch = require('elasticsearch_api')(client, logger, opConfig); - function checkElasticsearch(esClient) { - if (esClient) { - return elasticsearch.version(); - } - - return Promise.reject('no client is available for slicer'); - } - function processInterval(str, esDates) { if (!moment(new Date(str)).isValid()) { // one or more digits, followed by one or more letters, case-insensitive @@ -115,7 +107,8 @@ function newSlicer(context, opConfig, executionContext, retryData, logger, clien .then((results) => { const data = _.get(results, 'hits.hits[0]._source', results[0]); if (data === undefined) { - return moment(); + logger.warn(`no data was found using query ${JSON.stringify(query)} for index: ${opConfig.index}`); + return null; } if (data[opConfig.date_field_name] === undefined) { @@ -507,7 +500,7 @@ function newSlicer(context, opConfig, executionContext, retryData, logger, clien return Promise.resolve(slicers); } - return checkElasticsearch(client) + return elasticsearch.version() .then(() => getDates() .then((esDates) => { // query with no results diff --git a/spec/readers/elasticsearch_reader-spec.js b/spec/readers/elasticsearch_reader-spec.js index 50b227a9e2c..3a9d5bcafbb 100644 --- a/spec/readers/elasticsearch_reader-spec.js +++ b/spec/readers/elasticsearch_reader-spec.js @@ -309,13 +309,13 @@ describe('elasticsearch_reader', () => { Promise.resolve(slicer()) .then((results) => { expect(results).toEqual(null); - done(); }) .catch((error) => { fail(error); - done(); }); - }); + }) + .catch(fail) + .finally(done); }); it('slicer can produce date slices', (done) => {