# Creating a custom id in a mapping

**URL:** https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460
**Category:** Elasticsearch
**Created:** [November 9, 2016, 10:05am UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460 "2016-11-09T10:05:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Denny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denny/32/9157_2.png) [@Denny](https://discuss.elastic.co/u/Denny)
#### Post date: [November 9, 2016, 10:05am UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/1 "2016-11-09T10:05:34Z")

</div>

Hello,

I'm trying to give my indexed documents a custom id. So far no luck. This is a sample from my dataset:

```
_DESCRIPTIONS_ | _VALUES_
ID | WAUX87
Model | Avensis

```

Each document has an ID in its data and I want the corresponding value (in this case WAUX87) being used as the \_id in Elasticsearch. I'm trying to do that in my mapping:

```
PUT pdf_docs
{ "settings": {
  "number_of_shards": 12,
  "number_of_replicas": 2
},
"mappings": {
"pdf_docs": {
  "_id" : {
            "path" : "ID"
        },
  "properties": {
    "DESCRIPTIONS": {
      "type": "string",
      "index": "not_analyzed"
    },
    "VALUES": {
      "type": "string",
      "index": "not_analyzed"
    },
    "COLUMN-3": {
      "type": "string",
      "index": "not_analyzed"
    },
    "LUMN-4": {
      "type": "string",
      "index": "not_analyzed"
    }
  }}}}

```

This mapping above will give me an error: \__id is not configurable_  
I've Googled and tried searching in the official docs but I can't figure out how to do this. Any ideas?

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [November 9, 2016, 10:11am UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/2 "2016-11-09T10:11:44Z")

</div>

Have a look here: [https://www.elastic.co/blog/great-mapping-refactoring#meta-fields](https://www.elastic.co/blog/great-mapping-refactoring#meta-fields)

you need to explicitly pass the \_id for your index requests.

---

<div class="post-metadata">

### Author: ![Denny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denny/32/9157_2.png) [@Denny](https://discuss.elastic.co/u/Denny)
#### Post date: [November 9, 2016, 11:36am UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/3 "2016-11-09T11:36:36Z")

</div>

Ok thanks! Is it possible to write something in Logstash for it? I have thousands of csv-files to index which I would like to have a custom id.

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [November 9, 2016, 11:48am UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/4 "2016-11-09T11:48:08Z")

</div>

The Logstash Elasticsearch output has the `document_id` property which can be configured to the ID field.

---

<div class="post-metadata">

### Author: ![Denny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denny/32/9157_2.png) [@Denny](https://discuss.elastic.co/u/Denny)
#### Post date: [November 9, 2016, 1:58pm UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/5 "2016-11-09T13:58:03Z")

</div>

Thanks for your answer. I've played around with the document\_id in my logstash conf but I don't get the right results yet. This is my conf:

```
input
{
    file
    {
        path => "/home/DSAdmin/pdf-1.csv"
        start_position => "beginning"
        ignore_older => 0
        sincedb_path => "/dev/null"
     }
}

filter {
csv {
columns => ["DESCRIPTIONS", "VALUES", "DATE"]
separator => ','
}
}

output
{
    elasticsearch {
        action => "index"
        hosts => "localhost"
        index => "pdf"
        document_id => "%{?}"
        workers => 8
    }
    stdout {}
}

```

With the dataset I have I don't know how to work with the document\_id (therfore the questionmark)

```
_DESCRIPTIONS_ | _VALUES_
Id | WAUX87
Model | Avensis

```

I want Logstash to look at the row featuring 'Id' and use the corresponding value in the next column as a custom id which is in this case 'WAUX87'. I hope it's possible or else I'll look for other ways.

---

<div class="post-metadata">

### Author: ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)
#### Post date: [November 9, 2016, 2:31pm UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/6 "2016-11-09T14:31:18Z")

</div>

This is a pure Logstash question now, so maybe better ask in the [Logstash forums](https://discuss.elastic.co/c/logstash).

---

<div class="post-metadata">

### Author: ![Denny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denny/32/9157_2.png) [@Denny](https://discuss.elastic.co/u/Denny)
#### Post date: [November 9, 2016, 2:57pm UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/7 "2016-11-09T14:57:50Z")

</div>

Ok thanks for your help 🙂

---

<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: [December 7, 2016, 2:58pm UTC](https://discuss.elastic.co/t/creating-a-custom-id-in-a-mapping/65460/8 "2016-12-07T14:58:01Z")

</div>

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