如何使用 Logstash 配置文件将 Logstash 中的字段设置为 "not_analyzed"

How to set field in Logstash as "not_analyzed" using Logstash config file

我有一个 elasticsearch 索引,我用它来索引一组文档。

这些文件最初是 csv 格式,我正在寻找使用 logstash 解析这些文件。

我的 Logstash 配置文件是。

    input {
        file {
                path => "/csv_files_for_logstash/app1lg.csv"
                        type => "core2"
                        start_position => "beginning"
        }   }


    filter {
        csv {
                separator => ","
                        columns=> ["Date","Package Name","App Version Code","Current Device Installs","Daily Device Installs","Daily Device Uninstalls","Daily Device Upgrades","Current User Installs","Total User Installs","Daily User Installs","Daily User Uninstalls"]
        }
        mutate {convert => ["App Version Code", "string"]}
        mutate {convert => ["Current Device Installs", "float"]}
        mutate {convert => ["Daily Device Installs", "float"]}
        mutate {convert => ["Daily Device Uninstalls", "float"]}
        mutate {convert => ["Current User Installs", "float"]}
        mutate {convert => ["Total User Installs", "float"]}
        mutate {convert => ["Daily User Installs", "float"]}
        mutate {convert => ["Daily User Uninstalls", "float"]}
        ruby {
                code => '
                  b = event["App Version Code"]
                  string2=""
                  for counter in (3..(b.size-1))
                         if counter == 4
                                 string2+= "."+ b[counter]
                         elsif counter ==  6
                                string2+= "("+b[counter]
                         elsif counter == 8
                                string2+= b[counter] + ")"
                         else
                                 string2+= b[counter]
                         end

                   end

                   event["App Version Code"] = string2

                  '

        }
}
   output {
        elasticsearch {
                embedded => true
                        action => "index"
                        host => "es"
                        index => "fivetry"
                        workers => 1

        }
        stdout{
                codec => rubydebug {
                }
        }
}

现在我的字段值(应用程序版本代码)在 csv 中看起来像“123456789”,我正在使用 Ruby 代码将其解析为“4.56(789)”。

这个术语将它分成不同的值,因为这没有被分析。

我知道还有其他方法可以创建映射并将其设置为 not_ananlysed ,但我不知道该怎么做 所以,

有什么方法可以只使用我的 logstash 配置文件来设置这个 not_analysed 吗?

此外,

在 Kibana 中,没有我可以使用准确字符串的 .raw 字段。

感谢和问候,

您无法通过 Logstash 配置设置映射。映射与 Logstash 无关,仅与 Elasticsearch 相关。

您需要在插入这些文档之前在 Elasticsearch 中预先映射这些字段,您可以创建索引,然后使用映射 API 来设置映射,或者您可以使用索引模板来这样做将允许您创建映射而无需最初创建索引。

Logstash 提供了一个用于新索引的默认模板。您可以编辑此文件,但这不是一个好主意(它会在升级等情况下被覆盖)。

elasticsearch{} output 允许您指定要使用的自己的模板,而不是默认模板。