'How to pass dynamic instance environment tag into filebeat

I have assigned environment tag to my machines and want to have the environment populated into my filebeat logs. Was looking at use add_fields in the processor as below, but looks like it is not working.

- add_fields:
      fields: 
         environment: '${MACHINE_ENV}'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source