spring-data-examples icon indicating copy to clipboard operation
spring-data-examples copied to clipboard

Updating elasticsearch entities

Open alex1232212 opened this issue 5 years ago • 0 comments

I have this database data as below (ES 7.xx) version

{
 "id":"1234",
 "expirationDate":"17343234234",
 "paths":"http:localhost:9090",
 "work":"software dev",
 "family":{
    "baba":"jams",
    "mother":"ela"
 }
},
{
 "id":"00021",
 "expirationDate":"0123234",
 "paths":"http:localhost:8080",
 "work":"software engi",
 "family":{
    "baba":"stev",
    "mother":"hela"
 }
}

how can i update the entity which its expirationDate smaller than current Time? to be the current time for example:

the id 00021 is expired because its expiration date is smaller than today then it should updated to current time.

something like void updateExpiredEntity(List ids,Long currentTime) suing void bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index);

Please provide me some code implementation

my try, but i know its not all correct

   public void update(UUID id,Long currentDate) {
            UpdateQuery updateQuery = UpdateQuery.builder(id.toString()).withRouting("expirationDate=currentDate")
                .build();
            elasticsearchTemplate.bulkUpdate(List.of(updateQuery), IndexCoordinates.of("index"));
        }
    }

alex1232212 avatar Nov 10 '20 22:11 alex1232212