ElasticSearch 中的数据类型 IP

Data type IP in ElasticSearch

我们正在通过 logstash 在 ElasticSearch 中推送数据。问题是对于 IP 地址,它被存储为字符串而不是 IP 数据类型。是否可以通过 grok 指定它?我尝试了下面的代码,但它似乎不起作用。

ip {             match => [ "ip", "IPV4" ]     }

无法在 logstash 内部实现映射,因为无法在内部设置复杂类型 grok:

By default all semantics are saved as strings. If you wish to convert a semantic’s data type, for example change a string to an integer then suffix it with the target data type. For example %{NUMBER:num:int} which converts the num semantic from a string to an integer. Currently the only supported conversions are int and float.

不过,还有thoughts about that feature

现在,您需要指定一个自定义 elasticsearch template. Start with logstash's default elasticsearch template 并在属性部分添加一行:

"ip": { "type": "ip"},

在您的 logstash 配置的 elasticsearch output 中将文件路径设置为您的 template.json

output {
    elasticsearch {
        # Your existing config
        template => "/path/to/your/template.json"
        template_overwrite => true
    }
}

请记住,模板仅适用于新索引。