percolator: Fix range queries with date range based on current time.
Range queries with now based date ranges were previously not allowed, but since #23921 these queries were allowed. This change should really fix range queries with now based date ranges.
This commit is contained in:
parent
8c6b5a953e
commit
f6e19dcedc
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue