我在MySQL中有一个列,其中一个列有json,我必须用多个键实现对这个列的搜索。我尝试使用日志存储创建一个使用Mysql的索引。
这是我的日志存储配置。Info是具有文本类型和文本形式的json对的列。
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost:3306/dbname"
# The user we wish to execute our statement as
jdbc_user => "user"
jdbc_password => "password"
# The path to our downloaded jdbc driver
jdbc_driver_library => "/usr/share/java/mysql-connector-java-5.1.38.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
# our query
statement => "SELECT info FROM organization"
}
}
output {
stdout { codec => json_lines }
elasticsearch {
"hosts" => "localhost:9200"
"index" => "new_index"
"document_type" => "doc"
}
}我尝试创建索引的映射,并将其中一个字段设置为嵌套在映射中,但没有将任何内容上传到索引中。MySQL对索引的原始更新将我的json视为文本,这使得搜索变得更加困难。任何人都有更好的解决方案,可以将json列更新为索引,以便我可以从键中搜索。
输出。
{
"check_index" : {
"aliases" : { },
"mappings" : {
"doc" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"@version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"info" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1528870439037",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "MkNrBMD8S8GYfDtxRyOFfg",
"version" : {
"created" : "6020499"
},
"provided_name" : "check_index"
}
}
}
}有信息是我的JSON字符串。在json中,我有许多键值,例如: address、same等,因此,我没有在这样的字段中创建单独的列,而是为该字段创建了一个json,并将其添加到该列中。但我找不到那个json。
发布于 2018-06-14 16:38:51
我想你要找的是JSON filter。只需在该JSON过滤器中添加JSON类型的列名即可。假设数据类型为JSON的列是info,则过滤器如下所示。
filter {
json {
source => "info"
}
}如果您有多个具有JSON数据类型的列,则可以在filter中重复您的json数据集。因此,对于JSON列info,最终的logstash如下所示。
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost:3306/dbname"
# The user we wish to execute our statement as
jdbc_user => "user"
jdbc_password => "password"
# The path to our downloaded jdbc driver
jdbc_driver_library => "/usr/share/java/mysql-connector-java-5.1.38.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
# our query
statement => "SELECT info FROM organization"
}
}
filter {
json {
source => "info"
}
}
output {
elasticsearch {
"hosts" => "localhost:9200"
"index" => "new_index"
"document_type" => "doc"
}
}https://stackoverflow.com/questions/50817496
复制相似问题