首页 文章

如何使elasticsearch为所有索引中的每个文档添加时间戳字段?

提问于
浏览
25

Elasticsearch专家,

我一直无法找到一种简单的方法来告诉ElasticSearch为所有索引(以及所有文档类型)中添加的所有文档插入_timestamp字段 .

我看到特定类型的示例:http://www.elasticsearch.org/guide/reference/mapping/timestamp-field/

并且还查看特定类型的所有索引的示例(使用_all):http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/

但无法找到任何有关添加它的文档,无论索引和类型如何,都会添加所有文档 .

2 回答

  • 22

    您可以在创建索引时提供它 .

    $curl -XPOST localhost:9200/test -d '{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "_default_":{
            "_timestamp" : {
                "enabled" : true,
                "store" : true
            }
        }
      }
    }'
    

    然后,这将自动为您放入索引的所有内容创建_timestamp . 然后在请求_timestamp字段时索引某些东西后,它将被返回 .

  • 30

    Elasticsearch过去常常支持自动为正在编制索引的文档添加时间戳,但在2.0.0中为deprecated this feature

    从最近的(5.x)documentation

    _timestamp和_ttl字段已弃用,现已删除 . 作为_timestamp的替代,您应该使用应用程序端的当前时间戳填充常规日期字段 .

相关问题