# Delete or update document without document\_id

**URL:** <https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375>\
**Category:** Logstash\
**Created:** [March 16, 2021, 1:20pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375 "2021-03-16T13:20:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lele15](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lele15](https://discuss.elastic.co/u/lele15)\
**Post date:** [March 16, 2021, 1:20pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/1 "2021-03-16T13:20:16Z")

</div>

Hi, i'm new on ES, i'am using logstash and csv to update or delete values into ES.  
I want to delete or update document based on different field not only with document\_id

like this:

```
input {
  stdin{}
}

filter {
  csv {
      separator => ","
      skip_header => "true"
      columns => ["productCode","productName","productLine","operation"]
  }
  
}

output {
       if [operation] == "delete" {
        elasticsearch {
                    action => "delete" 
                    delete by product code
                    index => "product"
                    hosts => ["127.0.0.1:9200"]
        }
        }if [operation] == "update" {
           elasticsearch {
                    action => "update" 
                   update by product code 
                    index => "product"
                    hosts => ["127.0.0.1:9200"]
        }
        }
        stdout { codec => rubydebug }
}

```

In this case, product code is not the document\_id. I don't have the document id in the csv, so i'am not able to find the specific document to delete or update, i have only product code or maybe other fields.  
Can i do something like this?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 16, 2021, 3:24pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/2 "2021-03-16T15:24:55Z")

</div>

> [@lele15](#):
>
> Can i do something like this?

The elasticsearch output in logstash can only delete by id. However, elasticsearch itself has [delete-by-query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) and [update-by-query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) APIs, which you may be able to use from a logstash http filter or http output plugin.

---

<div class="post-metadata">

**Author:** ![lele15](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lele15](https://discuss.elastic.co/u/lele15)\
**Post date:** [March 16, 2021, 3:38pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/3 "2021-03-16T15:38:37Z")

</div>

Can you give me an example?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 16, 2021, 3:46pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/4 "2021-03-16T15:46:12Z")

</div>

There is an example of connecting to elasticsearch using an http filter [here](https://discuss.elastic.co/t/remove-fields-from-documents-based-on-their-value/200270/7). It is an update rather than update-by-query, but the API documentation explains how to do the latter.

---

<div class="post-metadata">

**Author:** ![lele15](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lele15](https://discuss.elastic.co/u/lele15)\
**Post date:** [March 16, 2021, 4:13pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/5 "2021-03-16T16:13:53Z")

</div>

This is my filter and output code, but i have a problem to use "product code" inside the json

```
filter {
  csv {
      separator => ","
      skip_header => "true"
      columns => ["productCode","productName","productLine","operation"]
  }
  
}

output {
       if [operation] == "delete" {
       http {
        url => "http://localhost:9200/product/_delete_by_query"
        http_method => "post"
        body_format => "json"
        content_type => "application/json"
        body => '{
                "query": {
                    "match": {
                      "productCode": '[productCode]'
                              }
                        }
                    }'
      }
      }
      stdout { codec => rubydebug }
}
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 16, 2021, 4:18pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/6 "2021-03-16T16:18:25Z")

</div>

> [@lele15](#):
>
> `"productCode": '[productCode]'`

You should use a sprintf reference

```
"productCode": "%{productCode]}"

```

---

<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:** [April 13, 2021, 4:19pm UTC](https://discuss.elastic.co/t/delete-or-update-document-without-document-id/267375/7 "2021-04-13T16:19:08Z")

</div>

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