文档 ID 未在 ElasticSearch 中设置,即使它是在 logstash.conf 中配置的

Document ID not set in ElasticSearch, even though it is configured inside logstash.conf

Here是我的logstash.conf.

里面的内容

(很抱歉没有直接把内容贴在这里。Whosebug 不允许有过高代码文本比的问题。)

作为测试,我 运行 PowerShell 命令

C:\Users\Me\Downloads\curl-7.64.1-win64-mingw\bin> .\curl.exe -XPUT 'http://127.0.0.1:31311/twitter_new/7'

我在 Logstash 终端上看到以下输出:

{
                "message" => "",
               "@version" => "1",
                   "host" => "127.0.0.1",
             "@timestamp" => 2019-04-09T11:35:22.458Z,
    "request_path_length" => 3,
                "headers" => {
              "http_host" => "127.0.0.1:31311",
         "content_length" => "0",
           "request_path" => [
            [0] "",
            [1] "twitter_new",
            [2] "7"
        ],
            "http_accept" => "*/*",
           "http_version" => "HTTP/1.1",
        "http_user_agent" => "curl/7.64.1",
         "request_method" => "PUT"
    },
               "index_id" => "twitter_new"
}

如您所见,document_id 未设置为 7,尽管这是我所期望的。

我该如何解决这个问题?

更新:

我变了

if [request_path_length == 3] {

if [request_path_length] == 3 {

我向 /twitter_new/8 提出了另一个 PUT 请求。然后我发出 GET 请求以检索所有条目,这是对应于我发出的最新 PUT 请求的条目:

{
    "_index": "twitter_new",
    "_type": "doc",
    "_id": "O5AIAmoBCWsefMj-o7Fw",
    "_score": 1,
    "_source": {
        "message": "",
        "document_id": "8",
        "@version": "1",
        "@timestamp": "2019-04-09T12:18:00.665Z",
        "index_id": "twitter_new",
        "request_path_length": 3,
        "headers": {
            "request_path": [
                "",
                "twitter_new",
                "8"
            ],
            "http_accept": "*/*",
            "http_version": "HTTP/1.1",
            "content_length": "0",
            "request_method": "PUT",
            "http_user_agent": "curl/7.64.1",
            "http_host": "127.0.0.1:31311"
        },
        "host": "127.0.0.1"
    }
}

如你所见,在source里面,document_id确实设置为8,但是_id仍然是一个运行domly生成的字符串。我希望 _id 也可以是 8,就像 _indextwitter_new 一样。

我是不是误会了什么?

您需要更改条件。

这是在 logstash 管道上引用字段的正确方法:

if [request_path_length] == 3

您正在使用 if [request_path_length == 3],它不起作用。