繁体   English   中英

如何从 Logstash 将数据推送到现有索引(弹性搜索)?

[英]How to push data to an existing index(Elastic Search) from Logstash?

elasticsearch {
                hosts => "elasticsearch:9200"
                index => "logmessages"
                document_type => "message"
       }

我想在 Elasticsearch 中创建具有某些映射的索引,然后将 Logstash 指向该索引以存储数据。 我该怎么做? 当 Logstash 将数据推送到不存在的索引时,它似乎工作正常。

您只需要使用所需的映射创建一个索引,然后按如下方式传递索引名称:

output {
  elasticsearch {
    hosts => ["elastic_search_server_ip:port"] #localhost:9200
    action => "index"
    index => "your_existing_index_name"}

# How to create index with mappings 
index_mapping = {
    "settings": {
            "number_of_shards": 1,
            "number_of_replicas": 0
        },

    'mappings': {'properties': {
        'id': {'type': 'long'},
        "location": {
                "type": "geo_point"
                } 
    }}}
resp = es.indices.create(index = "test", body = index_mapping, ignore = 400)

注意:您的索引应包含所有列/字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM