简体   繁体   English

Logstash翻译插件问题解析csv

[英]Logstash translate plugin problem parsing csv

I'm trying to parse all the columns of a CSV file (except the first one, obviously). 我正在尝试解析CSV文件的所有列(显然除了第一列)。 The plugin only get the second column as result of the filter. 该插件仅作为过滤器的结果获得第二列。 All the other column are ignored. 所有其他列都被忽略。

It should be possible, according to this sentence getting from the documentation : 应该可以根据这句话得到文件:

When using a CSV dictionary, multiple values in the translation must be extracted with another filter eg Dissect or KV. 使用CSV词典时,必须使用其他过滤器(例如Dissect或KV)提取转换中的多个值。 Note that the fallback is a string so on no match the fallback setting needs to formatted so that a filter can extract the multiple values to the correct fields. 请注意,回退是一个字符串,因此不需要格式化回退设置,以便过滤器可以将多个值提取到正确的字段。

Here is my logstash code : 这是我的logstash代码:

translate {
    field => "idBatch"
    dictionary_path => "D:\idBatch-description.csv"
    refresh_interval => 500
    destination => "donneesDictionnaireExterne"
    # Données par défaut en l'absence de correspondance
    fallback => "Aucune correspondance trouvée,10000"
    add_tag => [ "import_CSV_ok"]
}

# Mapper des données du dictionnaire externe
dissect {
    mapping => {
        "donneesDictionnaireExterne" => "%{descriptionBatch},%{maxDuration}"
        # EXEMPLE pour GAR01B0 : Batch d'injection Archive;86408
    }
}

Here is a sample of my CSV file : 以下是我的CSV文件示例:

"GDA08A0_SupPdc","Batch de Suppression de PDC","9999"
"GDI01A0_Parsing","Moteur de parsing des etats internes","9999"

Does anyone know why it doesn't work ? 有谁知道为什么它不起作用?

The translate filter will ignore everything after the second column, you will need to change the format of your dictionary. 翻译过滤器将忽略第二列之后的所有内容,您需要更改字典的格式。

Your dictionary needs to be something like this. 你的字典需要是这样的。

"GDA08A0_SupPdc","Batch de Suppression de PDC;9999"
"GDI01A0_Parsing","Moteur de parsing des etats internes;9999"

Then your dissect filter will be like this one: 然后你的剖析过滤器就像这样:

dissect {
    mapping => {
        "donneesDictionnaireExterne" => "%{descriptionBatch};%{maxDuration}"
    }
}

You can also use a mutate filter to remove the donneesDictionnaireExterne field. 您还可以使用mutate过滤器删除donneesDictionnaireExterne字段。

mutate {
    remove_field => ["donneesDictionnaireExterne"]
}

Finally the output for your example is: 最后,您的示例的输出是:

{
    "descriptionBatch" => "Batch de Suppression de PDC",
         "maxDuration" => "9999",
            "@version" => "1",
          "@timestamp" => 2019-04-02T02:10:45.107Z,
             "idBatch" => "GDA08A0_SupPdc",
             "message" => "{ \"idBatch\":\"GDA08A0_SupPdc\"}",
                "tags" => [
        [0] "import_CSV_ok"
    ],
                "host" => "hostname"
}
{
    "descriptionBatch" => "Moteur de parsing des etats internes",
         "maxDuration" => "9999",
            "@version" => "1",
          "@timestamp" => 2019-04-02T02:10:45.109Z,
             "idBatch" => "GDI01A0_Parsing",
             "message" => "{ \"idBatch\":\"GDI01A0_Parsing\"}",
                "tags" => [
        [0] "import_CSV_ok"
    ],
                "host" => "hostname"
}

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

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