Hi @Christian_Dahlqvist,
Sorry for reply you late.  today  I tested the pipeline you gave me, seems the fields are deleted within index file properly, but the index prefix is not generated by the fields I expected.
P.S.
#metricbeat conf file
metricbeat.modules:
#system module
- module: system
  metricsets:
    - cpu
    - load
    - filesystem
    - fsstat
    - memory
    - network
    - process
  enabled: true
  period: 10s
  processes: ['.*']
  cpu_ticks: false
  tags:  "system"
  fields:
    env:      test 
    dc:       metricbeat-ld5  
    os:       linux
    service:  system
  fields_under_root: true
  raw: false
#pipline conf file
170713163220 root@uklogstash-test1 conf.d # cat beats.conf
#logstash for beats
input {
beats {
port => 5044
}
}
filter {
   mutate  {  add_field => { "[@metadata][index_prefix]" => "%{env}-%{dc}-%{os}-%{service}" } }   
   mutate  {  remove_field =>  ["dc","env","os","service"]  }
}
output {
  file {
    path => "/tmp/%{[@metadata][index_prefix]-%{+YYYY.MM.dd}"
  }
}
#result file
%{[@metadata][index_prefix]-%{+YYYY.MM.dd}
the index file i want is like this: test-metricbeat-ld5-linux-system-2017.07.13, not the index like above .
#contents of the result file
{"@timestamp":"2017-07-13T08:27:56.683Z","system":{"process":{"memory":{"rss":{"pct":8.0E-4,"bytes":3272704},"size":41332736,"share":2314240},"cmdline":"ntpd -u ntp:ntp -p /var/run/ntpd.pid -g","name":"ntpd","cpu":{"total":{"pct":0.0}},"pid":8694,"state":"sleeping","fd":{"limit":{"hard":4096,"soft":1024},"open":13}}},"beat":{"name":"uktelegraf-test1"},"@version":"1","metricset":{"module":"system","name":"process"},"type":"metricsets","tags":["system","beats_input_raw_event"]}
{"@timestamp":"2017-07-13T08:27:56.683Z","system":{"process":{"memory":{"rss":{"pct":0.0018,"bytes":7344128},"size":205381632,"share":2879488},"cmdline":"/usr/sbin/snmpd -LS0-6d -Lf /dev/null -p /var/run/snmpd.pid","name":"snmpd","cpu":{"total":{"pct":0.0}},"pid":8773,"state":"sleeping","fd":{"limit":{"hard":4096,"soft":1024},"open":10}}},"beat":{"name":"uktelegraf-test1"},"@version":"1","metricset":{"module":"system","name":"process"},"type":"metricsets","tags":["system","beats_input_raw_event"]}
{"@timestamp":"2017-07-13T08:27:56.683Z","system":{"process":{"memory":{"rss":{"pct":4.0E-4,"bytes":1548288},"size":305324032,"share":667648},"cmdline":"/usr/local/bacula/sbin/bacula-fd -c /usr/local/bacula/etc/bacula-fd.conf","name":"bacula-fd","cpu":{"total":{"pct":0.0}},"pid":8891,"state":"sleeping","fd":{"limit":{"hard":4096,"soft":1024},"open":4}}},"beat":{"name":"uktelegraf-test1"},"@version":"1","metricset":{"module":"system","name":"process"},"type":"metricsets","tags":["system","beats_input_raw_event"]}
{"@timestamp":"2017-07-13T08:27:56.683Z","system":{"process":{"cmdline":"/sbin/rsyslogd -i /var/run/syslogd.pid","memory":{"rss":{"pct":7.0E-4,"bytes":2768896},"size":253755392,"share":1179648},"name":"rsyslogd","cpu":{"total":{"pct":0.0}},"pid":8986,"state":"sleeping","fd":{"limit":{"hard":4096,"soft":1024},"open":9}}},"beat":{"name":"uktelegraf-test1"},"@version":"1","metricset":{"module":"system","name":"process"},"type":"metricsets","tags":["system","beats_input_raw_event"]}
{"@timestamp":"2017-07-13T08:27:56.683Z","system":{"process":{"cmdline":"/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/puppet/bin/puppet agent --logdest /var/log/puppetlabs/puppet/puppet.log","memory":{"rss":{"pct":0.0209,"bytes":84119552},"size":320401408,"share":3543040},"name":"puppet","cpu":{"total":{"pct":0.0}},"pid":9047,"state":"sleeping","fd":{"limit":{"hard":4096,"soft":1024},"open":8}}},"beat":{"name":"uktelegraf-test1"},"@version":"1","metricset":{"module":"system","name":"process"},"type":"metricsets","tags":["system","beats_input_raw_event"]}
Would you please give me more idea about this?
Thanks in adavance.