# Logstash unable to write records to existing elasticsearch index

**URL:** https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659
**Category:** Logstash
**Created:** [January 21, 2023, 9:17pm UTC](https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659 "2023-01-21T21:17:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)
#### Post date: [January 21, 2023, 9:17pm UTC](https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659/1 "2023-01-21T21:17:58Z")

</div>

I can successfully get logstash to write records to an elasticsearch index if the index doesn't exist in the first place. But I can't seem to get logstash to write records to an index if it already exists.

For example, this scenario works PERFECTLY:

**SCENARIO 1**  
I have a file called `/root/setup/data/csv/data.csv` with the following contents:

```auto
order_id
1
2

```

And I have a file called `/root/setup/logstash/csv.conf` with the following contents:

```auto
input {
  file {
    path => "/root/setup/data/csv/data.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
    mode => "read"
    exit_after_read => true
    file_completed_action => "log"
    file_completed_log_path => "/root/logs"
  }
}

filter {
  csv {
    autodetect_column_names => true
  }
  mutate {
    convert => {
      "order_id" => "integer"
    }
  }
}

output {
  elasticsearch {
    hosts => ["elastic.myserver.net:9200"]
    ssl => true
    user => "elastic"
    password => "PASS123456789"
    index => "csv"
  }
}

```

I then have a brand new installation of elastic and kibana v.8.6. And then I ran this command  
`/usr/share/logstash/bin/logstash -f /root/setup/logstash/csv.conf`

Everything works perfectly, I see a new index called `csv` with two records with the proper data in each records.

**SCENARIO 2**  
I make a brand new installation of elastic and kibana. Then I run this command:

```auto
curl -X PUT -u elastic:PASS123456789 "https://elastic.myserver.net:9200/csv"

```

This causes an empty index `csv` to appear. Then I go through the same steps as SCENARIO 1. But no new records are written to the `csv` index.

Why can't logstash write records to an existing index?

NOTE: I also tried adding a mapping to the `csv` index, but it didn't make any difference. Logstash still can't write to an index that already exists.

---

<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: [January 21, 2023, 9:38pm UTC](https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659/2 "2023-01-21T21:38:05Z")

</div>

Does /root/logs get updated when you run logstash in the second case?

---

<div class="post-metadata">

### Author: ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)
#### Post date: [January 21, 2023, 9:46pm UTC](https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659/3 "2023-01-21T21:46:13Z")

</div>

Oh wait, things are just slow! I waited 5 minutes, and then the records showed up.

So if an index already exists, it just takes longer for elastic to process the incoming data from logstash.

---

<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: [February 18, 2023, 9:46pm UTC](https://discuss.elastic.co/t/logstash-unable-to-write-records-to-existing-elasticsearch-index/323659/4 "2023-02-18T21:46:31Z")

</div>

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