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

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

问题描述

弹性搜索专家,

我一直找不到一个简单的方法来告诉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-field/

I see 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 example for all indices for a specific type (using _all): http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/

但无法找到任何关于添加所有文档的文档,无论索引和类型如何,都可以添加。

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

推荐答案

在创建索引时提供它。

$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.

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

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