# Logstash Insert or Update if exists

**URL:** <https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083>\
**Category:** Logstash\
**Created:** [October 31, 2019, 4:46pm UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083 "2019-10-31T16:46:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haythem](https://avatars.discourse-cdn.com/v4/letter/h/45deac/32.png) [@haythem](https://discuss.elastic.co/u/haythem)\
**Post date:** [October 31, 2019, 4:46pm UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083/1 "2019-10-31T16:46:00Z")

</div>

hello guys , so lately i've trying to insert some data from txt file into elasticsearch index , but i'm having a problem in updating my index , when i run the logstach conf file it's not updating the data or inserting the new ones , it is adding the data again, here is my logstash conf :  
input {

```
file {
path => "C:/Elastic/Rapport_finale.txt"
start_position => "beginning"

}

}
 filter {
    
      csv {
	  separator => ";"
		 columns =>["ID","DATE_SITUATION","HEURE","COMPANY","NOM_COMPANY","DATE_SIT","NBRE_OPERATION_TOTAL","OPERATION_CAISSE","LR_LATITUDE","LR_LONGITUDE","SOMME","LIB_REGION","LIB_ZONE","LIB_AGENCE","DATE_UNIQ"]
		 
      } 
	  	
	  
	  date {
  match => ["DATE_SIT", "ISO8601", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss.ZZZ"]
  target => "DATE"
  locale => "en"
}
	  mutate {
    convert => {"NBRE_OPERATION_TOTAL" => "integer"}
    convert => {"OPERATION_CAISSE" => "integer"}
	convert => {"SOMME" => "integer"}
   }
	
	  mutate {
   add_field => { "[location][lat]" => "%{LR_LONGITUDE}" }
   add_field => { "[location][lon]" => "%{LR_LATITUDE}" }
  }
   mutate {
    convert => {"[location][lat]" => "float"}
    convert => {"[location][lon]" => "float"}
   }
}
 

output{

  elasticsearch {
  hosts => "*.*.*.*:9200"
  index => "rapport_index_dg_finale_test"
  #document_type => "my_type"
  action => "update"
  doc_as_upsert => true
  document_id => "%{ID}"
  user => "logstash_admin"
  password => " *******"
 }

 }

```

any idea what am i doing wrong ?

thanks.

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [October 31, 2019, 5:43pm UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083/2 "2019-10-31T17:43:30Z")

</div>

> [@haythem](#):
>
> doc\_as\_upsert =\> true

Remove this 🙂

---

<div class="post-metadata">

**Author:** ![haythem](https://avatars.discourse-cdn.com/v4/letter/h/45deac/32.png) [@haythem](https://discuss.elastic.co/u/haythem)\
**Post date:** [November 1, 2019, 9:03am UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083/3 "2019-11-01T09:03:38Z")

</div>

@AquaX Hi , i tried removing doc\_as\_upsert but i got this error  
` Could not index event to Elasticsearch. {:status=>404, :action=>["update", {:_id=>"2019010218604", :_index=>"rapport_index_dg_finale_test", :_type=>"_doc", :routing=>nil, :retry_on_conflict=>1}, #<LogStash::Event:0x3606e081>], :response=>{"update"=>{"_index"=>"rapport_index_dg_finale_test", "_type"=>"_doc", "_id"=>"2019010218604", "status"=>404, "error"=>{"type"=>"document_missing_exception", "reason"=>"[_doc][2019010218604]: document missing", "index_uuid"=>"V6toDwWOSyG8YJNXrpZJtA", "shard"=>"0", "index"=>"rapport_index_dg_finale_test"}}}}`  
any idea what's wrong ?

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [November 1, 2019, 11:15am UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083/4 "2019-11-01T11:15:38Z")

</div>

Yep! Now change action to “index”. Sorry didn’t see that you had “update”

---

<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:** [November 29, 2019, 11:15am UTC](https://discuss.elastic.co/t/logstash-insert-or-update-if-exists/206083/5 "2019-11-29T11:15:39Z")

</div>

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