Fix creating filtered alias using now in a date_nanos range query failed (#54785) (#55329)

Modify the value of nowInMillis in queryShardContext to current timestamp, because the
value will be used lately when validating the filtered alias which uses now in a date_nanos
range query.
This commit is contained in:
Christoph Büscher 2020-04-16 19:47:53 +02:00 committed by GitHub
parent b27f23a80d
commit 4d849f0948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -80,3 +80,30 @@
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: { 'is_write_index': true }}
---
"Can create filtered alias with a date_nanos range query":
- skip:
version: " - 7.7.99"
reason: "Fix was introduced in 7.8.0"
- do:
indices.create:
index: test_index
body:
mappings:
properties:
date_nanos_field:
type: date_nanos
- do:
indices.put_alias:
index: test_index
name: test_alias
body: {"filter": {"range": {"date_nanos_field": {"gt": "now-7d/d"}}}}
- do:
indices.get_alias:
index: test_index
name: test_alias
- match: {test_index.aliases.test_alias: {"filter": {"range": {"date_nanos_field": {"gt": "now-7d/d"}}}}}

View File

@ -149,10 +149,10 @@ public class MetadataIndexAliasesService {
}
indices.put(action.getIndex(), indexService);
}
// the context is only used for validation so it's fine to pass fake values for the shard id and the current
// timestamp
aliasValidator.validateAliasFilter(alias, filter, indexService.newQueryShardContext(0, null, () -> 0L, null),
xContentRegistry);
// the context is only used for validation so it's fine to pass fake values for the shard id,
// but the current timestamp should be set to real value as we may use `now` in a filtered alias
aliasValidator.validateAliasFilter(alias, filter, indexService.newQueryShardContext(0, null,
() -> System.currentTimeMillis(), null), xContentRegistry);
}
};
if (action.apply(newAliasValidator, metadata, index)) {