how to use logstash input elasticsarch index dynamic value

659 Views Asked by At

Please help me.

What I want is to know how to dynamically change the index during logstash elasticsearch input.

i want this

input {
    elasticsearch {
        hosts => localhost:9200
        index => index-+{yyyy}-{increasing value}
    }
}

result

input {
    elasticsearch {
        hosts => localhost:9200
        index => index-2022-52
    }
}

I need to be able to set the value to change every day.

ex) Using Linux scripts

Thank you in advance for your help.

1

There are 1 best solutions below

4
On

You can leverage environment variables.

Your input configuration would look like this:

input {
    elasticsearch {
        hosts => localhost:9200
        index => index-${YEAR}-${SEQ}
    }
}

And then set those variables from your shell just before running Logstash

export YEAR=2022
export SEQ=52

./bin/logstash -f test.conf