# How to set auto-generated \_id to json field(csv column) in logstash file

**URL:** <https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482>\
**Category:** Logstash\
**Created:** [July 23, 2021, 1:07pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482 "2021-07-23T13:07:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashutosh2808](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Ashutosh2808](https://discuss.elastic.co/u/Ashutosh2808)\
**Post date:** [July 23, 2021, 1:07pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482/1 "2021-07-23T13:07:15Z")

</div>

I've csv columns as below in logstash conf file:

```auto
filter{
csv {
            columns => ["ResolutionId","IssueId"]
            separator => ","
            skip_header => "true"
              
       }
            
    mutate {
        remove_field => ["path", "host"]
        copy => {
          "ResolutionId" => "_id"
      
          }
     }
}

```

I want to store the value of auto-generated id(\_id) that I see in Kibana into "ResolutionId". I've tried by using copy in mutate plugin but it doesn't stoe the value. Can someone please help me to achieve this?

---

<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:** [July 23, 2021, 1:29pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482/2 "2021-07-23T13:29:13Z")

</div>

The \_id is generated when the data is ingested into Elasticsearch.  
What you can do is define an ingest pipeline in Elasticsearch that copies the `_id` to `ResolutionID`.

> **[Ingest pipelines | Elasticsearch Guide \[7.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/ingest.html)**

Or you can try and update the mapping of your destination index and use the `copy_to` parameter to copy the `_id` to `ResolutionId`

> **[copy\_to | Elasticsearch Guide \[7.13\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html)**

I have not tested this but the query for the mapping may look something like this:

```auto
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "_id": {
        "copy_to": "ResolutionID" 
      },
      "ResolutionID": {
        "type": "text"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 23, 2021, 7:32pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482/3 "2021-07-23T19:32:57Z")

</div>

Just Driving By....

@Ashutosh2808 Welcome to the Community

Or You could use a Runtime Field... not as efficient... but super easy!

In the Index Pattern Create One... and it can be used anywhere... just keep in mind since it is runtime it is not actually persisted.

 ![Screen Shot 2021-07-23 at 12.31.18 PM](https://us1.discourse-cdn.com/elastic/original/3X/8/8/88fff7c6ca9c713cd24e6bd8f2a5c1a1317384f6.png)

 ![Screen Shot 2021-07-23 at 12.35.29 PM](https://us1.discourse-cdn.com/elastic/original/3X/c/7/c75e801144f05b87705a6891f2f51057459b0abb.png)

 ![Screen Shot 2021-07-23 at 12.35.37 PM](https://us1.discourse-cdn.com/elastic/original/3X/6/7/6747bbc7b357fc2540aed7ec04e8c5d959fb30bc.png)

---

<div class="post-metadata">

**Author:** ![ritchierich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritchierich/32/4329_2.png) [@ritchierich](https://discuss.elastic.co/u/ritchierich)\
**Post date:** [July 23, 2021, 10:19pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482/4 "2021-07-23T22:19:51Z")

</div>

@Ashutosh2808 - Welcome to the community!

Another option would be to assigned the document id in the elasticsearch output. This might give you extra flexibility to control it before being ingested into elasticsearch.

```auto
output {
  elasticsearch {
    hosts => ['eshost:9200']
    index => "logstash-resolution"
    document_id => "%{ResolutionId}"
    doc_as_upsert => "true"
    action => "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:** [August 20, 2021, 10:20pm UTC](https://discuss.elastic.co/t/how-to-set-auto-generated-id-to-json-field-csv-column-in-logstash-file/279482/5 "2021-08-20T22:20:15Z")

</div>

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