如何使elasticsearch将时间戳字段添加到所有索引中的每个文档? [英] How to make elasticsearch add the timestamp field to every document in all indices?

查看:16
本文介绍了如何使elasticsearch将时间戳字段添加到所有索引中的每个文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Elasticsearch 专家,

Elasticsearch experts,

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

I have been unable to find a simple way to just tell ElasticSearch to insert the _timestamp field for all the documents that are added in all the indices (and all document types).

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

I see an example for specific types: http://www.elasticsearch.org/guide/reference/mapping/timestamp-field/

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

and also see an example for all indices for a specific type (using _all): http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/

但我无法找到任何有关默认情况下为所有添加的文档添加它的文档,而不管索引和类型如何.

but I am unable to find any documentation on adding it by default for all documents that get added irrespective of the index and type.

推荐答案

您可以通过在创建索引时提供它来做到这一点.

You can do this by providing it when creating your index.

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

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

That will then automatically create a _timestamp for all stuff that you put in the index. Then after indexing something when requesting the _timestamp field it will be returned.

这篇关于如何使elasticsearch将时间戳字段添加到所有索引中的每个文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆