# Pre-Index a field during Index Creation

**URL:** <https://discuss.elastic.co/t/pre-index-a-field-during-index-creation/192559>\
**Category:** Logstash\
**Created:** [July 28, 2019, 10:36am UTC](https://discuss.elastic.co/t/pre-index-a-field-during-index-creation/192559 "2019-07-28T10:36:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrashid](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mrashid](https://discuss.elastic.co/u/mrashid)\
**Post date:** [July 28, 2019, 10:36am UTC](https://discuss.elastic.co/t/pre-index-a-field-during-index-creation/192559/1 "2019-07-28T10:36:00Z")

</div>

I can understand that its possible to preindex a field during index creation as mentioned in the following page :  
[https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules-index-sorting.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules-index-sorting.html)

In my case I am creating index automatically every day by using date as one parameter. So how do I sort one field in an index which is created automatically by the already configured logstash output file ?

Logstash config :

```
output {
if [filteredValues] {
 file {
   path => "/etc/logstash/output.json"
   codec => line { format => "CI-ID : %{filteredValues}"}
   write_behavior => overwrite
 }
}
if "lastFailedBuild" in [source] {
  elasticsearch {
hosts => ["xxxxxxxxxxxxx:9200"]
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}-failurelogs"
document_type => "%{[@metadata][type]}"
  }
}else if "lastUnsuccessfulBuild" in [source] {
elasticsearch {
hosts => ["xxxxxxxxxx:9200"]
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}-failurelogs"
document_type => "%{[@metadata][type]}"
  }

}else {
  elasticsearch {
hosts => ["xxxxxxxxxxxxxxxxx:9200"]
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}-successlogs"
document_type => "%{[@metadata][type]}"
  }
}

```

Thanks in advance.

---

<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 25, 2019, 10:36am UTC](https://discuss.elastic.co/t/pre-index-a-field-during-index-creation/192559/2 "2019-08-25T10:36:10Z")

</div>

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