# Logstash script adding duplicate data

**URL:** <https://discuss.elastic.co/t/logstash-script-adding-duplicate-data/353223>\
**Category:** Logstash\
**Created:** [February 14, 2024, 5:05am UTC](https://discuss.elastic.co/t/logstash-script-adding-duplicate-data/353223 "2024-02-14T05:05:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritikapawar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritikapawar/32/98580_2.png) [@Ritikapawar](https://discuss.elastic.co/u/Ritikapawar)\
**Post date:** [February 14, 2024, 5:05am UTC](https://discuss.elastic.co/t/logstash-script-adding-duplicate-data/353223/1 "2024-02-14T05:05:58Z")

</div>

Hi,  
I'm uploading php\_error.logs using logstash script but when i run ths script it adds allover data again and again so index is showing count of duplicate data too. how i can avoid that?

This is the script which i am using

```auto
input {
  file {
    path => "/var/log/apache2/php_errors.log"
    start_position => "beginning"
    sincedb_path => "/dev/null"
    codec => multiline {
      pattern => '^\[\d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2} '
      negate => true
      what => "previous"
      auto_flush_interval => 1
      multiline_tag => ""
    }
  }
}

filter {
  grok {
    match => { "message" => "\[%{LOGTIME:[@metadata][timestamp]} %{DATA:[@metadata][tz]}\] PHP %{DATA:log_level}:%{SPACE}%{GREEDYDATA:log_message}" }
    pattern_definitions => { "LOGTIME" => "%{MONTHDAY}-%{MONTH}-%{YEAR} %{TIME}" }
  }

  date {
    match => ["[@metadata][timestamp]", "dd-MMM-yyyy HH:mm:ss" ]
    target => "@timestamp"
    timezone => "%{[@metadata][tz]}"
  }

  # You can remove unnecessary fields if needed
  mutate {
    remove_field => ["log", "message", "event", "host"]
  }
}

output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    user => "elastic"
    password => "plus91"
    index => "php_error_logs_all"
    action => "index"
    doc_as_upsert => true
  }

  stdout {
    codec => rubydebug
  }
}

```

---

<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:** [March 13, 2024, 5:06am UTC](https://discuss.elastic.co/t/logstash-script-adding-duplicate-data/353223/2 "2024-03-13T05:06:07Z")

</div>

Closed on March 13, 2024, 5:06am UTC

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