Ok, my current data structure is following
2023-07-05 00:11:56 [2023-07-04T21:11:56,855][INFO ][logstash.inputs.jdbc ][main][bbba3150f9c946cd7407c40277f99ddb5c77b481b669b359f5f6fd68c1b732b5] (0.001225s) SELECT id, endpoint, method, response, response_code, created_at, processed_at FROM request_queue WHERE id > 0 ORDER BY id ASC LIMIT 1
2023-07-05 00:11:56 {
2023-07-05 00:11:56 "total" => 944195,
2023-07-05 00:11:56 "limit" => 2,
2023-07-05 00:11:56 "@version" => "1",
2023-07-05 00:11:56 "page" => 1,
2023-07-05 00:11:56 "pages" => 472098,
2023-07-05 00:11:56 "docs" => [
2023-07-05 00:11:56 [0] {
2023-07-05 00:11:56 "id" => 5309714,
2023-07-05 00:11:56 "names" => [
2023-07-05 00:11:56 [0] {
2023-07-05 00:11:56 "name" => "Untitled the Pope's Exorcist sequel",
2023-07-05 00:11:56 "language" => nil
2023-07-05 00:11:56 }
2023-07-05 00:11:56 ]
2023-07-05 00:11:56 },
2023-07-05 00:11:56 [1] {
2023-07-05 00:11:56 "id" => 5307599,
2023-07-05 00:11:56 "names" => [
2023-07-05 00:11:56 [0] {
2023-07-05 00:11:56 "name" => "Masters of the Universe: Revolution",
2023-07-05 00:11:56 "language" => nil
2023-07-05 00:11:56 }
2023-07-05 00:11:56 ]
2023-07-05 00:11:56 }
2023-07-05 00:11:56 ],
2023-07-05 00:11:56 "@timestamp" => 2023-07-04T21:11:56.858622200Z,
2023-07-05 00:11:56 "sql_data" => {
2023-07-05 00:11:56 "endpoint" => "v1.3/movie",
2023-07-05 00:11:56 "response_code" => 200,
2023-07-05 00:11:56 "method" => "GET",
2023-07-05 00:11:56 "processed_at" => 2023-07-04T21:10:00.000Z,
2023-07-05 00:11:56 "created_at" => 2023-07-04T21:10:00.000Z,
2023-07-05 00:11:56 "id" => 1,
2023-07-05 00:11:56 "response" => #<Sequel::SQL::Blob:0x15f8 bytes=235 start="{\"docs\":[{" end="s\":472098}">
2023-07-05 00:11:56 }
2023-07-05 00:11:56 }
Content of request_queue.response
{
"docs": [
{
"id": 5309714,
"names": [
{
"name": "Untitled the Pope's Exorcist sequel",
"language": null
}
]
},
{
"id": 5307599,
"names": [
{
"name": "Masters of the Universe: Revolution",
"language": null
}
]
}
],
"total": 944195,
"limit": 2,
"page": 1,
"pages": 472098
}
I want to save each object from docs
as an index document.
My current conf
input {
jdbc {
jdbc_driver_library => "${LOGSTASH_JDBC_DRIVER_JAR_LOCATION}"
jdbc_driver_class => "${LOGSTASH_JDBC_DRIVER}"
jdbc_connection_string => "${LOGSTASH_JDBC_URL}"
jdbc_user => "${LOGSTASH_JDBC_USERNAME}"
jdbc_password => "${LOGSTASH_JDBC_PASSWORD}"
schedule => "*/1 * * * * *"
statement => "SELECT id, endpoint, method, response, response_code, created_at, processed_at FROM request_queue WHERE id > 0 ORDER BY id ASC LIMIT 1"
target => "sql_data"
}
}
filter {
json {
source => "[sql_data][response]"
}
split {
field => "docs"
add_field => {
"id" => "%{[docs][id]}"
"names" => "%{[docs][names]}"
}
remove_field => [
"sql_data",
"total",
"limit",
"page",
"pages"
]
}
}
After
add_field => {
"id" => "%{[docs][id]}"
"names" => "%{[docs][names]}"
}
the field names
being converted to JSON string.