# Incremental value in document IDs

**URL:** <https://discuss.elastic.co/t/incremental-value-in-document-ids/212810>\
**Category:** Logstash\
**Created:** [December 23, 2019, 6:19am UTC](https://discuss.elastic.co/t/incremental-value-in-document-ids/212810 "2019-12-23T06:19:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![psteh](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@psteh](https://discuss.elastic.co/u/psteh)\
**Post date:** [December 23, 2019, 6:19am UTC](https://discuss.elastic.co/t/incremental-value-in-document-ids/212810/1 "2019-12-23T06:19:26Z")

</div>

Greetings,

How do I have an incrementing field (counter) on _document\_id_ if I am using JDBC input?

The reason is that my statement is using _left join_ on multiple tables and have duplicate of IDs. Using IDs for _document\_id_ will update the document to latest which is not what I desire.

I have my SQL statement as follow

```
SELECT (@row_number:=ifnull(@row_number, 0) + 1) AS num, ...

```

And at **output**

```
document_id => "%{carId}-%{num}"

```

But the output when I checked the IDs at Kibana doese not have increment value and remain as _1_

**Update 1:-**  
Resort to simple ruby script to have incremental count.  
Found out that the Logstash output does not really follow SQL _order by_.  
Is there anyway for me to force following inserting with _order by_?

Regards.  
psteh

---

<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:** [December 23, 2019, 2:44pm UTC](https://discuss.elastic.co/t/incremental-value-in-document-ids/212810/2 "2019-12-23T14:44:12Z")

</div>

> [@psteh](#):
>
> Is there anyway for me to force following inserting with _order by_ ?

See [here](https://discuss.elastic.co/t/batch-size-in-logstash/206919/5).

---

<div class="post-metadata">

**Author:** ![psteh](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@psteh](https://discuss.elastic.co/u/psteh)\
**Post date:** [December 24, 2019, 2:24am UTC](https://discuss.elastic.co/t/incremental-value-in-document-ids/212810/3 "2019-12-24T02:24:07Z")

</div>

Thanks for your reply and that link.

---

<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:** [January 21, 2020, 2:24am UTC](https://discuss.elastic.co/t/incremental-value-in-document-ids/212810/4 "2020-01-21T02:24:11Z")

</div>

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