Alex12
(AlexAlex)
November 6, 2020, 9:57am
1
Is it possible to delete list of documents by list of documents id?
i tryed like this but it does not work at all
deleteAllByIdIn(List<UUID> ids);
from ElasticsearchRepository
and it does not work at all please guid me, maybe providing a query impelemntation please?
dadoonet
(David Pilato)
November 6, 2020, 11:17am
2
Welcome!
This seems like a spring data related question and not really elasticsearch.
In elasticsearch, it's good to delete documents using the delete API or better the bulk API if you have a lot of them to delete.
1 Like
Alex12
(AlexAlex)
November 6, 2020, 11:27am
3
Thank you very much, could you please provide a solution of how to do it using bulk API?
this is how my data looks like
{
"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"
}
}
i need to delete all ids which its expirationDate before today`date are
dadoonet
(David Pilato)
November 6, 2020, 12:12pm
4
Then you don't want to provide a list of ids but a query, right?
And use this API?
dadoonet
(David Pilato)
November 6, 2020, 12:13pm
5
Better solution is to use time based indices and simply drop the older indices everyday.
Which can be automated with ILM:
Alex12
(AlexAlex)
November 6, 2020, 12:15pm
6
Thanks, but i need a code using spring and not sending bunch of queries, where can i find such a code example please ? using QueryBuilder, can you provide me a code example about my case please? using QueryBuilder in springboot
dadoonet
(David Pilato)
November 6, 2020, 12:33pm
7
Not sure it will answer your question but here is some code which uses Spring Boot (not Spring Data Elasticsearch) where I'm building
A BulkProcessor:
this.bulkProcessor = BulkProcessor.builder(
(request, bulkListener) -> esClient.bulkAsync(request, RequestOptions.DEFAULT, bulkListener),
new BulkProcessor.Listener() {
@Override
public void beforeBulk(long executionId, BulkRequest request) {
logger.debug("going to execute bulk of {} requests", request.numberOfActions());
}
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
logger.debug("bulk executed {} failures", response.hasFailures() ? "with" : "without");
}
@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
logger.warn("error while executing bulk", failure);
}
})
.setBulkActions(10000)
.setFlushInterval(TimeValue.timeValueSeconds(5))
.build();
Delete documents by id:
system
(system)
Closed
December 8, 2020, 10:00pm
9
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.