I have different indices with datetime fields:
"created_at": "2018-12-21 15:29:53",
"created_at": "2018-12-21 15:32:11",
"created_at": "2019-01-01 08:17:43",
The format of the field is this
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
How can I update many indexes so that only the day changes?
the result of the update would be like this
["created_at": "2018-12-22 15:29:53",]
["created_at": "2018-12-22 15:32:11",]
["created_at": "2019-01-02 08:17:43",]
Please note, that every time you change anything in a document the entire document has to be reindex. So, if you need to change a value of a field in every document in an index, the entire index will have to be reindexed. You can do it using Reindex API if only a small percent of documents needs to change - you can use Update By Query API.
This portion OffsetDateTime.parse(ctx._source['created_at']).DayOfMonth.getValue() returns you an integer. So, what your script is doing is like assigning 28 to an integers. What you wrote in painless is basically equivalent to
UPDATE users set DATEPART(day, created_at) = 28
To fix your example you need to assign the result back to ctx._source['created_at'] like this:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "cannot write xcontent for unknown value of type class java.time.OffsetDateTime"
}
],
"type": "illegal_argument_exception",
"reason": "cannot write xcontent for unknown value of type class java.time.OffsetDateTime"
},
"status": 400
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.