diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index 94b5782a22c..cf41ad8ec1d 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -146,9 +146,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust this.mapperService = new MapperService(indexSettings, registry.build(indexSettings), xContentRegistry, similarityService, mapperRegistry, // we parse all percolator queries as they would be parsed on shard 0 - () -> newQueryShardContext(0, null, () -> { - throw new IllegalArgumentException("Percolator queries are not allowed to use the current timestamp"); - })); + () -> newQueryShardContext(0, null, System::currentTimeMillis)); this.indexFieldData = new IndexFieldDataService(indexSettings, indicesFieldDataCache, circuitBreakerService, mapperService); if (indexSettings.getIndexSortConfig().hasIndexSort()) { // we delay the actual creation of the sort order for this index because the mapping has not been merged yet. diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java index 40dee843e93..21775d2a53a 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java @@ -161,7 +161,8 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorRangeQueries() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=long", "field2", "type=double", "field3", "type=ip", "query", "type=percolator") + .addMapping("type", "field1", "type=long", "field2", "type=double", "field3", "type=ip", "field4", "type=date", + "query", "type=percolator") ); client().prepareIndex("test", "type", "1") @@ -203,6 +204,11 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .must(rangeQuery("field3").from("192.168.1.0").to("192.168.1.5")) .must(rangeQuery("field3").from("192.168.1.5").to("192.168.1.10")) ).endObject()).get(); + client().prepareIndex("test", "type", "10") + .setSource(jsonBuilder().startObject().field("query", boolQuery() + .must(rangeQuery("field4").from("2010-01-01").to("2018-01-01")) + .must(rangeQuery("field4").from("2010-01-01").to("now")) + ).endObject()).get(); client().admin().indices().prepareRefresh().get(); // Test long range: @@ -252,6 +258,14 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("7")); + + // Test date range: + source = jsonBuilder().startObject().field("field4", "2016-05-15").endObject().bytes(); + response = client().prepareSearch() + .setQuery(new PercolateQueryBuilder("query", "type", source, XContentType.JSON)) + .get(); + assertHitCount(response, 1); + assertThat(response.getHits().getAt(0).getId(), equalTo("10")); } public void testPercolatorQueryExistingDocument() throws Exception {