如何使弹性搜索将时间戳记字段添加到所有索引中的每个文档?
弹性搜索专家,
我一直找不到一个简单的方法来告诉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.