对于其余版本,请参阅版本化插件文档。html
有关插件的问题,请在讨论论坛中打开一个主题,对于错误或特性请求,请在Github中打开一个问题,关于Elastic支持的插件列表,请考虑Elastic支持矩阵。git
兼容性说明
从Elasticsearch 5.3开始,有一个名为
http.content_type.required
的HTTP设置,若是此选项设置为true
,而且你使用的是Logstash 2.4到5.2,则须要将Elasticsearch输入插件更新到4.0.2或更高版本。github
从Elasticsearch集群中读取搜索查询的结果,这对于重放测试日志、重建索引等很是有用。你可使用cron语法按期调度摄取(请参阅调度设置)或运行查询一次以将数据加载到Logstash中。json
示例:数组
input { # 读取Elasticsearch中与给定查询匹配的全部文档 elasticsearch { hosts => "localhost" query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }' } }
这将使用如下格式建立Elasticsearch查询:服务器
curl 'http://localhost:9200/logstash-*/_search?&scroll=1m&size=1000' -d '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }'
能够调度此插件的输入根据特定调度按期运行,此调度语法由rufus-scheduler提供支持,语法相似cron,有一些特定于Rufus的扩展(例如时区支持)。curl
示例:elasticsearch
* 5 * 1-3 * |
将从1月到3月的天天凌晨5点每分钟执行一次 |
0 * * * * |
将在天天每小时的第0分钟执行 |
0 6 * * * America/Chicago |
将在天天上午6:00(UTC/GMT-5)执行 |
能够在此处找到描述此语法的更多文档。ide
此插件支持如下配置选项以及稍后描述的通用选项。性能
设置 | 输入类型 | 必须 |
---|---|---|
ca_file |
一个有效的文件系统路径 | No |
docinfo |
boolean |
No |
docinfo_fields |
数组 | No |
docinfo_target |
string |
No |
hosts |
数组 | No |
index |
string |
No |
password |
string |
No |
query |
string |
No |
schedule |
string |
No |
scroll |
string |
No |
size |
number |
No |
slices |
number |
No |
ssl |
boolean |
No |
user |
string |
No |
另请参阅通用选项以获取全部输入插件支持的选项列表。
ca_file
docinfo
boolean
false
若是设置,事件中包含Elasticsearch文档信息,例如索引、类型和ID。关于元数据,可能须要注意的是,若是你正在提取文档,意图从新索引它们(或只是更新它们),那么elasticsearch输出中的action
选项想要知道如何处理这些事情,可使用添加到元数据的字段动态分配它。
示例:
input { elasticsearch { hosts => "es.production.mysite.org" index => "mydata-2018.09.*" query => '{ "query": { "query_string": { "query": "*" } } }' size => 500 scroll => "5m" docinfo => true } } output { elasticsearch { index => "copy-of-production.%{[@metadata][_index]}" document_type => "%{[@metadata][_type]}" document_id => "%{[@metadata][_id]}" } }
从Logstash 6.0开始,因为删除了Logstash 6.0中的类型,所以不推荐使用
document_type
选项,它将在Logstash的下一个主要版本中删除。
docinfo_fields
["_index", "_type", "_id"]
docinfo
选项请求文档元数据存储,则此选项会列出要在当前事件中保存的元数据字段,有关详细信息,请参阅Elasticsearch文档中的文档元数据。docinfo_target
string
"@metadata"
hosts
ca_file
index
string
"logstash-*"
password
user
选项中的用户名一块儿使用的密码,若是设置为空字符串,则将禁用身份验证。query
string
'{ "sort": [ "_doc" ] }'
schedule
string
"* * * * *"
(每分钟执行一次查询),默认状况下没有调度,若是没有给出调度,那么该语句只运行一次。scroll
string
"1m"
size
number
1000
slices
number
在某些状况下,能够经过使用Sliced Scroll API同时消费查询的多个不一样切片来提升整体吞吐量,特别是若是管道花费大量时间等待Elasticsearch提供结果。若是设置,则slices
参数告诉插件将工做分红多少个切片,并将并行地从切片生成事件,直到全部切片完成滚动。
Elasticsearch手册指出,当滚动查询使用的切片多于索引中的碎片时,对查询和Elasticsearch集群可能会产生负面的性能影响。
slices
参数,则插件不会将切片指令注入查询。ssl
boolean
false
user
string
password
选项中的密码一块儿使用的用户名,若是设置为空字符串,则将禁用身份验证。全部输入插件都支持如下配置选项:
设置 | 输入类型 | 必需 |
---|---|---|
add_field | hash | No |
codec | codec | No |
enable_metric | boolean | No |
id | 字符串 | No |
tags | 数组 | No |
type | 字符串 | No |
add_field
hash
{}
codec
codec
"json"
enable_metric
boolean
true
id
string
为插件配置添加惟一ID
,若是未指定ID,Logstash将生成一个ID,强烈建议在配置中设置此ID,当你有两个或更多相同类型的插件时,这尤为有用,例如,若是你有2个elasticsearch输入。在这种状况下添加命名ID将有助于在使用监控API时监控Logstash。
input { elasticsearch { id => "my_plugin_id" } }
tags
type
string
type
字段添加到此输入处理的全部事件,类型主要用于过滤器激活,类型存储为事件自己的一部分,所以你也可使用该类型在Kibana中搜索它。若是你尝试在已有类型的事件上设置类型(例如,当你将事件从shipper发送到索引器时),则新输入将不会覆盖现有类型,shipper设置的类型即便在发送到另外一个Logstash服务器时仍会保留该事件。