korjavin
(Ivan Korzhavin)
August 15, 2019, 4:05pm
1
My index has a field DateSeen
with the timestamp. .
I want to prevent rewriting of index documents if DateSeen is before one that stored.
I try to achieve this with a script like this:
POST _scripts/check_date
{"script":{"lang":"painless","source":"if(ctx._source.dateSeen == null || (Instant.parse(ctx._source.dateSeen)).isBefore(Instant.parse(params.dateSeen))) ctx._source.putAll(params)"}}
But it looks like not working solution.
Help me please find a way to achieve this behavior.
spinscale
(Alexander Reelsen)
August 16, 2019, 12:59pm
2
can you provide a fully fledged reproducible example including indexation of sample documents so one can reproduce?
Also the Elasticsearch version you are testing against would be good to know.
korjavin
(Ivan Korzhavin)
August 17, 2019, 8:37am
3
Yes, this is my experiment:
PUT /test_index
{
"aliases": {},
"mappings": {
"dynamic": "strict",
"properties": {
"dateSeen": {
"type": "date"
}
}
}
}
POST _scripts/test_last_script
{"script":{"lang":"painless","source":"if(ctx._source.dateSeen == null || (Instant.parse(ctx._source.dateSeen)).isBefore(Instant.parse(params.dateSeen))) ctx._source.putAll(params)"}}
put /test_index/_doc/1
{
"dateSeen": "2019-06-26T22:23:42Z"
}
put /test_index/_doc/1
{
"dateSeen": "2019-06-20T22:23:42Z"
}
GET test_index/_search
{
"query": {
"match_all": {}
}
}
spinscale
(Alexander Reelsen)
August 19, 2019, 6:56am
4
this is not a complete example (or maybe the issue). You are just storing a script, but the script is not executed during indexed. You may want to use a script processor before indexing that is running the above script.
system
(system)
Closed
September 16, 2019, 6:56am
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.