I tested some and found a TRICK. (Remember it is just a trick.)
Here is the setting.
PUT /test_unique_key/
{
"mappings": {
"properties": {
"id":{"type":"keyword"},
"date":{"type":"date"}
}
}
}
POST /test_unique_key/_bulk
{"index":{}}
{"id":1,"date":"2011-10-10T00:00:00.000Z"}
{"index":{}}
{"id":1,"date":"2020-10-10T00:00:00.000Z"}
If you set "timestamp" ("date" here) explicitly
GET /_transform/_preview?filter_path=preview
{
"latest":{
"sort":"date",
"unique_key": ["*","date"]
},
"dest": "test_dest",
"source":{
"index":"test_unique_key"
}
}
Two documents are distinguished.
{
"preview" : [
{
"date" : "2011-10-10T00:00:00.000Z",
"id" : 1
},
{
"date" : "2020-10-10T00:00:00.000Z",
"id" : 1
}
]
}
If you set wildcard containing "timestamp",:
GET /_transform/_preview?filter_path=preview
{
"latest":{
"sort":"date",
"unique_key": ["*"]
},
"dest": "test_dest",
"source":{
"index":"test_unique_key"
}
}
The difference between "timestamp" fields are ignored and there are only one document.
{
"preview" : [
{
"date" : "2020-10-10T00:00:00.000Z",
"id" : 1
}
]
}
This could be a solution. As this behavior is not explained in the official document, however, I'm not sure this is just for this specific case, for example it is not likely but it could work only with "date" field name..., or works for general situations. And also it could dissapear or change suddenly without any notion.
If you want to use this, please do thorough testing and use with extreme caution.