Issue using logstash-input-jdbc to load mongo data

Hello, I'm using logstash to load MongoDB data to elasticsearch. I get MongoDB data inside the map field (inside source). I want data to be part of the source, not in a separate field.
I used db.collection.find() statement and I'm getting documents as,
{
"_index": "test",
"_type": "doc",
"_id": "wxma3GkBX1wUOA268XBA",
"_score": 1,
"_source": {
"map": {
"_id": "5b534ae2e4b0671367e2e3ce",
"total": 247,
"status": active,
"dateModified": 1553585121902,
},
"@timestamp": "2019-04-02T05:52:14.923Z",
"@version": "1"
}
}

I want it as :
{
"_index": "test",
"_type": "doc",
"_id": "wxma3GkBX1wUOA268XBA",
"_score": 1,
"_source": {
"_id": "5b534ae2e4b0671367e2e3ce",
"total": 247,
"status": active,
"dateModified": 1553585121902,
"@timestamp": "2019-04-02T05:52:14.923Z",
"@version": "1"
}
}

If you want to move the fields of "map" to the top level you can use ruby

    ruby {
        code => '
            m = event.remove("map")
            m.each { |k, v|
                event.set(k, v)
            }
        '
    }

Thank you :slight_smile: Issue has been resolved .

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.