簡體   English   中英

為了將 csv 上傳到 elasticsearch,logstash remove_field 不起作用

[英]logstash remove_field not working in order to upload csv to elasticsearch

我正在使用 elasticsearch、kibana 和 logstash 6.0.1。

我希望通過logstash和刪除字段(路徑、@timestamp、@version、主機和消息)將csv數據上傳到elasticsearch。 我在下面顯示了 logstash.conf 和 emp.csv 文件。 如果我不使用 remove_field 指令但我需要,上傳將起作用。 此外,未創建索引。

logstash.conf:

input {

  file {
      path => "e:\emp.csv"
      start_position => "beginning"
  }
}
filter {
  csv {
      separator => ","
      columns => ["code","color"]
      remove_field => ["path", "@timestamp", "@version", "host", "message"]
  }

  mutate {convert => ["code", "string"]}
  mutate {convert => ["color", "string"]}

}
output {
  elasticsearch {
    hosts => "http://localhost:9200"
    index => "emp5"
    user => "elastic"
    password => "password"
  }
  stdout {}
}

emp.csv:

1,blue
2,red

在這種情況下缺少什么?

在您的csv文件中,您嘗試刪除的數據不可用。

而是嘗試刪除例如pathhost字段:

(...)
filter {
  csv {
      separator => ","
      columns => ["code","color"]
  }
    mutate {
      remove_field => ["path", "host"]
    }
(...)

對於信息,如果字段path和/或host不存在,則沒有問題。 如果字段存在,插件將刪除字段,如果字段不存在,則不執行任何操作。

編輯:我已經在新的elastic stack上對其進行了測試:

您可以使用以下命令刪除索引:

curl -X DELETE "localhost:9200/emp5"

另請注意,在您當前的配置中, logstash只會讀取該文件一次。 您可以通過在內部添加sincedb_path => "/dev/null"或在Windows情況下更改該行為: sincedb_path => "NUL"

input {
    file {
           (...) # here
         }

部分。

然后在logstash工作之后驗證結果:

curl -X GET "localhost:9200/emp5?pretty"
{
  "emp5" : {
    "aliases" : { },
    "mappings" : {
      "doc" : {
        "properties" : {
          "@timestamp" : {
            "type" : "date"
          },
          "@version" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "code" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "color" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "message" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "number_of_shards" : "5",
        "blocks" : {
          "read_only_allow_delete" : "true"
        },
        "provided_name" : "emp5",
        "creation_date" : "1576099826712",
        "number_of_replicas" : "1",
        "uuid" : "reXYzqPgQryYcASoov9l5A",
        "version" : {
          "created" : "6080599"
        }
      }
    }
  }
}

如您所見,沒有hostpath字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM