# How to name elasticsearch index based on time in result set from JDBC input?

**URL:** <https://discuss.elastic.co/t/how-to-name-elasticsearch-index-based-on-time-in-result-set-from-jdbc-input/71810>\
**Category:** Logstash\
**Created:** [January 17, 2017, 5:11am UTC](https://discuss.elastic.co/t/how-to-name-elasticsearch-index-based-on-time-in-result-set-from-jdbc-input/71810 "2017-01-17T05:11:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [January 17, 2017, 5:11am UTC](https://discuss.elastic.co/t/how-to-name-elasticsearch-index-based-on-time-in-result-set-from-jdbc-input/71810/1 "2017-01-17T05:11:19Z")

</div>

Hi,

I am using jdbc input having a query like;

```
SELECT id,name,address,timea,timeb FROM mytable where TO_CHAR(timea,'yyyy-mm-dd') > '2017-01-01' and TO_CHAR(timeb,'yyyy-mm-dd') < '2017-01-16'

```

I have configured my elasticsearch output like;

```
index => "myindex-%{+YYYY-MM-dd}"

```

I was expecting indices like `myindex-2017-01-01`, `myindex-2017-01-02`, `myindex-2017-01-03` etc. But what I got was a single index `myindex-2017-01-17` with all entries inside. I think it took my system date instead of date from query result. How can I achieve indices like I have mentioned?

Thanks in advance..

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 17, 2017, 6:29am UTC](https://discuss.elastic.co/t/how-to-name-elasticsearch-index-based-on-time-in-result-set-from-jdbc-input/71810/2 "2017-01-17T06:29:39Z")

</div>

Use the date filter to parse one of the date fields and store the result in the `@timestamp` field.

---

<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:** [February 14, 2017, 6:29am UTC](https://discuss.elastic.co/t/how-to-name-elasticsearch-index-based-on-time-in-result-set-from-jdbc-input/71810/3 "2017-02-14T06:29:46Z")

</div>

Closed on February 14, 2017, 6:29am UTC

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