# Delete and Insert documents in elasticsearch from logstash

**URL:** https://discuss.elastic.co/t/delete-and-insert-documents-in-elasticsearch-from-logstash/243614
**Category:** Logstash
**Created:** [August 3, 2020, 6:35pm UTC](https://discuss.elastic.co/t/delete-and-insert-documents-in-elasticsearch-from-logstash/243614 "2020-08-03T18:35:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Gabriel\_Mare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_mare/32/73265_2.png) [@Gabriel\_Mare](https://discuss.elastic.co/u/Gabriel_Mare)
#### Post date: [August 3, 2020, 6:35pm UTC](https://discuss.elastic.co/t/delete-and-insert-documents-in-elasticsearch-from-logstash/243614/1 "2020-08-03T18:35:09Z")

</div>

Hi,

I need to delete all documents and then add documents from logstash, in the same query.

Is this possible?  
How can I do?

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [August 3, 2020, 6:53pm UTC](https://discuss.elastic.co/t/delete-and-insert-documents-in-elasticsearch-from-logstash/243614/2 "2020-08-03T18:53:49Z")

</div>

What you are looking for is not possible via logstash.

I have same requirement hence this is what I do. but in my case record count is small and that is why it works.

I run a bash cron script at 08:01 which deletes all record from index.  
and logstash runs at 08:02 which pulls new data and insert in same index

inside bash script this is what I do

sleep 50  
curl -u {elk\_user}:{elk\_user\_password} -X POST "localhost:9200/myidex-2020/\_delete\_by\_query" -H "Content-Type: application/json" -d"  
{ "query": { "match\_all": {} } } "

this means all data is unavailable for only 10 to 20 second. as delete works at 08:01:50 and new data gets pull at 08:02:00

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 31, 2020, 6:53pm UTC](https://discuss.elastic.co/t/delete-and-insert-documents-in-elasticsearch-from-logstash/243614/3 "2020-08-31T18:53:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
