# How to set the document id dynamically with the column value from the table

**URL:** <https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064>\
**Category:** Logstash\
**Created:** [June 10, 2019, 10:14pm UTC](https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064 "2019-06-10T22:14:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashokchinna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashokchinna/32/47123_2.png) [@ashokchinna](https://discuss.elastic.co/u/ashokchinna)\
**Post date:** [June 10, 2019, 10:14pm UTC](https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064/1 "2019-06-10T22:14:36Z")

</div>

I want to set the id value for each document in the elastic search.

I am trying to set the account\_no as an id. However, when I tried to do, the id is set as the string value "%{account\_no}".

The statement document\_id =\> "%{account\_no}" is not fetching the value from the input filter.

```
   #jdbc.conf
    input {
        jdbc {
                # path of the jdbc driver
                jdbc_driver_library => "C:\Ashok\ojdbc8-full\ojdbc8.jar"

                # The name of the driver class 
                jdbc_driver_class => "oracle.jdbc.Driver"

                # Mysql jdbc connection string to company database
                jdbc_connection_string => "jdbc:oracle:thin:@new-connection:1234:dbsource"
            
                # user credentials to connect to the DB
                jdbc_user => "xyz"
                jdbc_password => "xyz"

                # when to periodically run statement, cron format (ex: every 30 minutes)
                schedule => "30 * * * *"

                # query parameters
                parameters => { "account_no" => "213072717" }

                # sql statement 
                statement => "SELECT * FROM accounts WHERE account_no= :account_no 
            }
    }

    output {
        elasticsearch {
          index => "bank"
          document_type => "account"
          hosts => "localhost:9200"
     document_id => "%{account_no}"
        }
    }
```

---

<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:** [June 11, 2019, 9:44am UTC](https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064/2 "2019-06-11T09:44:34Z")

</div>

That suggests that your events do not have an [account\_no] field on them. Check using

```
output { stdout { codec => rubydebug } }
```

---

<div class="post-metadata">

**Author:** ![ashokchinna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashokchinna/32/47123_2.png) [@ashokchinna](https://discuss.elastic.co/u/ashokchinna)\
**Post date:** [June 11, 2019, 4:18pm UTC](https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064/3 "2019-06-11T16:18:57Z")

</div>

You are right, the column name is in caps. Looks like it's case sensitive.

Thank you @Badger

---

<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:** [July 9, 2019, 4:18pm UTC](https://discuss.elastic.co/t/how-to-set-the-document-id-dynamically-with-the-column-value-from-the-table/185064/4 "2019-07-09T16:18:59Z")

</div>

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