I want to store json object {'customerId': '123', 'customerName': 'abc'} to Elastisearch via Logstash, but the json object is stored as message="{'customerId': '123', 'customerName': 'abc'}" in Elasticsearch. How can I remove "message" field and make my own fields be direct children of "_source"?
Node.js code using UDP socket to send json:
> var dgram = require('dgram');
var client = dgram.createSocket('udp4'); var message = new Buffer("{'customerId': '123', 'customerName': 'abc'}"); // I tried to remove double quote here, and the object will not be stored to Elasticsearch client.send(message, 0, message.length, port, host, function(err, bytes) { if (err) throw err; console.log('UDP client message sent'); client.close(); });
Logstash configuration:
input {
udp {
port => 8515
}
}filter{
json{
source => "message"
}
}output {
elasticsearch {
hosts => ["https://172.25.75.103:443"]
user => "myUser"
password => "myPassword"
index => "myIndex"
}
}
Current output:
{ "_index": "myIndex", "_type": "doc", "_id": "N_w8fXABocJFtplFKRoK", "_version": 1, "_score": null, "_source": { "@version": "1", "host": "172.19.132.126", "@timestamp": "2020-02-25T16:44:10.891Z", "message": "{'customerId': '123', 'customerName': 'abc'}" }
Expected Output:
{ "_index": "myIndex", "_type": "doc", "_id": "N_w8fXABocJFtplFKRoK", "_version": 1, "_score": null, "_source": { "@version": "1", "host": "172.19.132.126", "@timestamp": "2020-02-25T16:44:10.891Z", "customerId": "123", "customerName" : "abc" }