簡體   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