elasticsearch - 如何在Logstash ElasticSearch中使用_timestamp

标签 elasticsearch logstash

我试图弄清楚如何在logstash中使用_timestamp

我试图添加到映射:

   "_timestamp" : {
      "enabled" : true,
      "path" : "@timestamp"
   },

但这没有预期的效果。我在elasticsearch-template.json文件中做到了这一点(我尝试了是否使用"store"=true):
{
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : "5s"
  },
  "mappings" : {
    "_default_" : {
       "_timestamp" : {
          "enabled" : true,
          "store" : true,
          "path" : "@timestamp"
       },

       "_all" : {"enabled" : true},
       "dynamic_templates" : [ {
  .....

然后将修改后的文件添加到输出过滤器
output {
  elasticsearch_http {
    template => '/tmp/elasticsearch-template.json'
    host => '127.0.0.1'
    port=>9200
  }
}

为了确保数据库是干净的,我反复进行以下操作:
curl -XDELETE http://localhost:9200/logstash*
curl -XDELETE http://localhost:9200/_template/logstash
rm ~/.sincedb_*

然后尝试导入我的日志文件。但是由于某些原因,未设置_timestamp

映射似乎还可以
{
  "logstash-2014.03.24" : {
    "_default_" : {
      "dynamic_templates" : [ {
        "string_fields" : {
          "mapping" : {
            "index" : "analyzed",
            "omit_norms" : true,
            "type" : "string",
            "fields" : {
              "raw" : {
                "index" : "not_analyzed",
                "ignore_above" : 256,
                "type" : "string"
              }
            }
          },
          "match" : "*",
          "match_mapping_type" : "string"
        }
      } ],
      "_timestamp" : {
        "enabled" : true,
        "store" : true,
        "path" : "@timestamp"
      },
      "properties" : {
        "@version" : {
          "type" : "string",
          "index" : "not_analyzed",
          "omit_norms" : true,
          "index_options" : "docs"
        },
        "geoip" : {
          "dynamic" : "true",
          "properties" : {
            "location" : {
              "type" : "geo_point"
            }
          }
        }
      }
    },
    "logs" : {
      "dynamic_templates" : [ {
        "string_fields" : {
          "mapping" : {
            "index" : "analyzed",
            "omit_norms" : true,
            "type" : "string",
            "fields" : {
              "raw" : {
                "index" : "not_analyzed",
                "ignore_above" : 256,
                "type" : "string"
              }
            }
          },
          "match" : "*",
          "match_mapping_type" : "string"
        }
      } ],
      "_timestamp" : {
        "enabled" : true,
        "store" : true,
        "path" : "@timestamp"
      },
      "properties" : {
        "@timestamp" : {
          "type" : "date",
          "format" : "dateOptionalTime"
        },

数据库中的文档看起来像
 {
    "_id": "Cps2Lq1nTIuj_VysOwwcWw", 
    "_index": "logstash-2014.03.25", 
    "_score": 1.0, 
    "_source": {
      "@timestamp": "2014-03-25T00:47:09.703Z", 
      "@version": "1", 
      "created": "2014-03-25 01:47:09,703", 
      "host": "macbookpro.fritz.box", 
      "message": "2014-03-25 01:47:09,703 - Starting new HTTP connection (1): localhost", 
      "path": "/Users/scharf/git/ckann/annotator-store/logs/requests.log", 
      "text": "Starting new HTTP connection (1): localhost"
    }, 
    "_type": "logs"
  }, 

为什么没有设置_timestamp ???

最佳答案

简而言之,它确实有效。

我测试了您的确切情况,发现的是:

当启用_source并从_timestamp中的某些路径指定_source时,
您永远不会在文档中看到_timestamp,但是,如果添加了?fields查询字符串部分,例如:
http://<localhost>:9200/es_test_logs/ESTest1/ilq4PU3tR9SeoLo794wZlg?fields=_timestamp您将获得正确的_timestamp值。

如果您在外部(在_timestamp文档中)传递_source而不是使用path,则您将照常在文档中_timestamp属性下看到_source

如果禁用_source字段,则即使在设置为store" : true的文档中,也将看不到任何ANY属性。只有在指定?fields或构建返回这些字段的查询时,才会看到它们。

关于elasticsearch - 如何在Logstash ElasticSearch中使用_timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22665878/

相关文章:

email - Logstash 电子邮件从多个日志文件动态发出警报

c# - 在Elasticsearch中分组搜索结果

elasticsearch - 使用NEST 1.0映射嵌套类型

java - 如何在 ElasticSearch 中获取模拟 TransportClient

parsing - Logstash:嵌套 grok 搜索?将一个字段解析为多个字段?

logging - ELK - Logstash + Redis - 数据复制

elasticsearch - 突出显示 ElasticSearch 自动完成

node.js - 具有 Express 框架的 ElasticSearch

json - Elasticsearch查询性能(如果有多个字段还是只有一个字段)?

csv - 尝试索引CSV文件时Logstash没有响应