# Spark Structured Streaming timeseries indices

**URL:** <https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [July 10, 2019, 8:32pm UTC](https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869 "2019-07-10T20:32:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielyahn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielyahn/32/41575_2.png) [@danielyahn](https://discuss.elastic.co/u/danielyahn)\
**Post date:** [July 10, 2019, 8:32pm UTC](https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869/1 "2019-07-10T20:32:45Z")

</div>

I have a follow up question to [[Spark Structured streaming] Elasticsearch sink index name](https://discuss.elastic.co/t/spark-structured-streaming-elasticsearch-sink-index-name/152449/4)

James said, "As christian has mentioned above, ES-Hadoop will not create an index name using the current time, but rather will let you give a field name on your document to use in the index name creation. This field can contain a timestamp, which is usually what users want when they are using time based indices."

What is the field name that ES-Hadoop (or ES possibly) looking for index name creation? And how do we configure which field to use?

Do we have a related documentation or example? In this example, [https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-sql-streaming-write-scala](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-sql-streaming-write-scala) , wouldn't it create a `spark` index?

---

<div class="post-metadata">

**Author:** ![danielyahn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielyahn/32/41575_2.png) [@danielyahn](https://discuss.elastic.co/u/danielyahn)\
**Post date:** [July 11, 2019, 2:32pm UTC](https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869/2 "2019-07-11T14:32:23Z")

</div>

I had to combine two examples ([one](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html#cfg-multi-writes-format) and [two](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-write-dyn)) to have it working for Structured Streaming timeseries indices.

In scala it looks something like

```auto
val df = spark.readStream.schema(schema)
.parquet("/path-to/*.parquet") //assuming parquet file has timestamp field
.withColumn("@timestamp",date_format('timestamp,"yyyy")) //format the field as you want in the index name

val stream = df.writeStream
.option("checkpointLocation", "/save/location")      
.format("es")
.start("timeseries-{@timestamp}/doc")

```

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [July 11, 2019, 7:09pm UTC](https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869/3 "2019-07-11T19:09:53Z")

</div>

> [@danielyahn](#):
>
> What is the field name that ES-Hadoop (or ES possibly) looking for index name creation? And how do we configure which field to use?

As you've already found out above, any field on a document can be used to create the index name. A simple example of this for streaming can be found at [Apache Spark support | Elasticsearch for Apache Hadoop [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-streaming-write-dyn)

---

<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 8, 2019, 7:24pm UTC](https://discuss.elastic.co/t/spark-structured-streaming-timeseries-indices/189869/4 "2019-08-08T19:24:05Z")

</div>

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