我已经尝试过很多迭代,但它根本没有工作。我希望自动将_timestamp或@timestamp附加到每个文档。 似乎不能让它发挥作用。
尽管文件正在被正确摄取
curl -XPOST 'http://X.X.X.X:9200/associations' -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_default_":{
"_timestamp" : {
"enabled" : true,
"store" : true,
"path" : "post_date"
}
}
}
}'
我也试过直接在我的索引
中设置它curl -XPUT 'http://X.X.X.X:9200/associations' -d '{
"mappings": {
"_timestamp" :
{
"enabled":true,
"store": "yes",
"path" : "post_date",
"type": "date",
"format" : "yyyy-MM-dd HH:mm:ss"
}
}
}'
答案 0 :(得分:0)
您拥有的第一个代码块似乎对我有用。如果我用它来定义索引:
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"_default_": {
"_timestamp": {
"enabled": true,
"store": true,
"path": "post_date"
}
}
}
}
然后将一些文档添加到新类型中:
PUT /test_index/doc/1
{
"post_date": "2015-1-25"
}
PUT /test_index/doc/2
{
"post_date": "2015-1-15"
}
我现在可以看到新映射中的时间戳:
GET /test_index/_mapping
...
{
"test_index": {
"mappings": {
"_default_": {
"_timestamp": {
"enabled": true,
"store": true,
"path": "post_date"
},
"properties": {}
},
"doc": {
"_timestamp": {
"enabled": true,
"store": true,
"path": "post_date"
},
"properties": {
"post_date": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
}
我可以搜索该类型,并在fields中询问"_timestamp"
,我会在结果中找回时间戳:
POST /test_index/doc/_search
{
"fields": [
"_timestamp",
"post_date"
]
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"fields": {
"post_date": [
"2015-1-25"
],
"_timestamp": 1422144000000
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_score": 1,
"fields": {
"post_date": [
"2015-1-15"
],
"_timestamp": 1421280000000
}
}
]
}
}
以下是我使用的代码:
http://sense.qbox.io/gist/1ab1ecb73d3e87cffe0052ce1706e7985d197fad
顺便说一句,我正在运行Elasticsearch 1.3.4版。