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

bq9c1y66  于 2022-12-09  发布在  Logstash
关注(0)|答案(1)|浏览(215)
elasticsearch {
                hosts => "elasticsearch:9200"
                index => "logmessages"
                document_type => "message"
       }

我想在Elasticsearch中创建一个具有特定Map的索引,然后将Logstash指向该索引以存储数据。我该如何操作?当Logstash将数据推送到一个不存在的索引时,它似乎工作正常。

byqmnocz

byqmnocz1#

您只需要创建一个具有所需Map的索引,然后按如下所示传递索引名称:

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)

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

相关问题