Hello, I am newbie here.. I have a bunch of ELK indexes that returns below output when querying via POSTMAN GET request.
</>
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 9.650149,
"hits": [
{
"_index": "inx-mon-2020.11.45.311-v1",
"_type": "_doc",
"_id": "8wxU8uclg3bUmpdjyAIw",
"_score": 9.650149,
"_source": {
"createDate": "2020-11-06T12:00:00.000+1100",
"createdBy": "user1",
"aZoneId": "Zone1",
"itemId": "ITEMXYZ",
"mId": "MU",
"pickQty": 28,
"searchBaseType": "uomSearchable",
"searchType": "uomPickedSearchable",
"domain": {
"version": "2020.1.4"
}
}
}
]
}
}
</>
Then I want the above Elasticsearch output inserted into a table in sql server
Below my ELK config file.
</>
input
{
elasticsearch {
hosts => ["localhost:9200"]
index => "inx-mon-2020.11.45.311-v1"
user => "root"
password => "****"
}
}
output {
jdbc{
driver_jar_path =>"/usr/share/logstash/bin/sqljdbc_7.4/enu/mssql-jdbc-7.4.1.jre11.jar"
connection_string => "jdbc:sqlserver://localhost:1433;databaseName=mydatabase;user=myuser;password=mypass"
statement => ["INSERT into mydatabase.dbo.mytable ([timestamp]
,[elkindex]
,[id]
,[createDate]
,[createdBy]
,[aZoneId]
,[itemId]
,[mId]
,[pickQty]) VALUES(?,?,?,?,?,?,?,?,?)", "@timestamp", "[hits][_index]", "[hits][_id]", "createDate", "createdBy", "aZoneId", "itemId", "mId", "pickQty" ]
}
stdout { codec => rubydebug }
}
</>
All working but I want the "_index" which has the value "inx-mon-2020.11.45.311-v1" captured in the my insert statement under the column elkindex.
How would do this?
I get the below debug info.. See there is no reference to the header data in insert statement, such as below three fields.
"_index": "inx-mon-2020.11.45.311-v1",
"_type": "_doc",
"_id": "8wxU8uclg3bUmpdjyAIw",
INSERT into mytable ([timestamp]\n ,[elkindex]\n ,[id]\n ,[createDate]\n ,[createdBy]\n ,[aZoneId]\n ,[itemId]\n ,[uomId]\n ,[pickQty]) VALUES(?,?,?,?,?,?,?,?,?)", :event=>"{"aZoneId":"Zone1","searchBaseType":"uomSearchable","searchType":"uomPickedSearchable","itemId":"ITEMXYZ","@version":"1","mId":"MU","createdBy":"user1","domain":{"version":"2020.1.4"},"pickQty":28,"createDate":"2020-11-06T12:00:00.000+1100","@timestamp":"2021-08-15T11:48:51.805Z"}"}
Thank you for your reply.