# Logstash group time series by decade

**URL:** <https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462>\
**Category:** Logstash\
**Created:** [November 5, 2021, 2:58am UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462 "2021-11-05T02:58:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [November 5, 2021, 2:58am UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/1 "2021-11-05T02:58:09Z")

</div>

I am ingesting academic articles and splitting the index by year:

```auto
output {
    elasticsearch {
        hosts => ["${ES_HOST_PROD}"]
        index => "works-%{year}"
        user => "${ES_USER_PROD}"
        password => "${ES_PASSWORD_PROD}"
        document_id => "%{my_id}"
    }
}

```

However, for the 1800s there are very few documents for each index. So I have 100 documents in the index works-1802, but I have 4 million in works-2020. What I would like to do is send any document in the 1800s into a single index labeled something like works-1800. Is there a way to do that in logstash?

---

<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:** [November 5, 2021, 3:08am UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/2 "2021-11-05T03:08:25Z")

</div>

> [@caseydm](#):
>
> What I would like to do is send any document in the 1800s into a single index labeled something like works-1800. Is there a way to do that in logstash?

You could change your output to reference something like [indexSuffix] and in the filter section do something like

```
if [year] {
    mutate { convert => { "year" => "integer" } }
    if [year] < 1900 {
        mutate { add_field => { "indexSuffix" => "1800" } }
    } else {
        mutate { add_field => { "indexSuffix" => "%{year}" } }
    }
} else {
    mutate { add_field => { "indexSuffix" => "Yikes" } }
}

```

Obviously you can add else blocks to merge decades of the early 1900s if desired.

---

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [November 5, 2021, 3:15am UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/3 "2021-11-05T03:15:50Z")

</div>

Oh this is a great idea. Thank you!

---

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [November 5, 2021, 12:01pm UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/4 "2021-11-05T12:01:25Z")

</div>

Quick question - do you know if there is a way to remove indexSuffix after I am done with it, so it is not actually indexed?

---

<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:** [November 5, 2021, 5:48pm UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/5 "2021-11-05T17:48:03Z")

</div>

Call it [@metadata][indexSuffix] instead (or use mutate+remove\_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:** [December 3, 2021, 5:48pm UTC](https://discuss.elastic.co/t/logstash-group-time-series-by-decade/288462/6 "2021-12-03T17:48:45Z")

</div>

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