I have used Windows environment variables in Logstash config file. Following command was used to create env variable:
$env:MW_Index = 'mw-test-index-temp'
In my config file, I have called this index.
mutate { add_field => { "[@metadata][target_index]" => "${MW_INDEX}" } }
Now, when I run the Logstash from command line, it works fine but running it as a service does not ingest data. Following command is being used to run it as a service:
Start-Service -name logstash