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:
parent
b27f23a80d
commit
4d849f0948
|
@ -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"}}}}}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue