Hi,
sure I can, even if I’m not really proud of it, it has been a “quick and dirty” one.
To get all the fields used in each index:
root@graylog01:~# mongo
> use graylog;
> db.getCollection("index_field_types").find({});
This gave me many JSON dictionaries, one per index, like:
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_0", "fields" : []}
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_1", "fields" : []}
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_2", "fields" : []}
I’ve then put this output in a script (transformed in a list of dict) and created the Mongocommands:
import sys
import json
import re
def ObjectId(string):
return string
data = [
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_0", "fields" : []},
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_1", "fields" : []},
{ "_id" : ObjectId(...), "index_set_id" : "...", "index_name" : "index_2", "fields" : []}
]
num = []
for index in data:
for field in index['fields']:
if field['field_name'].startswith('snmp'):
if not field['field_name'] in num:
num.append(field['field_name'])
print("db.index_field_types.update({'index_name' : '" + index['index_name'] + "'}, {$pull : { 'fields' : { 'field_name' : '" + field['field_name'] + "' }}});")
Back to Mongo, I’ve used these commands to delete the unwanted fields, like:
> db.index_field_types.update({'index_name' : 'index_0'}, {$pull : { 'fields' : { 'field_name' : 'snmp_1_3_6_1_6_3_1_1_4_1_0' }}});
Again, not the most elegant but it worked!
Regards,
Matteo