我尝试在索引上定义_timestamp属性。因此,首先,我创建索引
curl -XPUT 'http://elasticsearch:9200/ppe/'
来自服务器的响应:{"ok":true,"acknowledged":true}
然后,我尝试使用_timestamp来定义映射
curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{
"log": {
"properties": {
"_ttl": {
"enabled": true
},
"_timestamp": {
"enabled": true,
"store": "yes"
},
"message": {
"type": "string",
"store": "yes"
},
"appid": {
"type": "string",
"store": "yes"
},
"level": {
"type": "integer",
"store": "yes"
},
"logdate": {
"type": "date",
"format": "date_time_no_millis",
"store": "yes"
}
}
}
}'我收到了来自服务器的回答
{
"error": "MapperParsingException[No type specified for property [_timestamp]]",
"status": 400
}我的映射有什么问题?
发布于 2012-12-06 21:36:18
必须在与properties对象相同的级别上定义_ttl和_timestamp等特殊字段:
curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{
"log": {
"_ttl": {
"enabled": true
},
"_timestamp": {
"enabled": true,
"store": "yes"
},
"properties": {
"message": {
"type": "string",
"store": "yes"
},
"appid": {
"type": "string",
"store": "yes"
},
"level": {
"type": "integer",
"store": "yes"
},
"logdate": {
"type": "date",
"format": "date_time_no_millis",
"store": "yes"
}
}
}
}
'发布于 2014-12-27 21:08:30
请注意,尽管_timestamp是在顶层定义的,但它将在fields内部返回
curl 'http://localhost:9200/myindex/mytype/AUqL0PW7YDMmKSIKO1bk?pretty=true&fields=_timestamp'
{
"_index" : "myindex",
"_type" : "mytype",
"_id" : "AUqL0PW7YDMmKSIKO1bk",
"_version" : 1,
"found" : true,
"fields" : {
"_timestamp" : 1419684935099
}
}请注意,fields=_timestamp或fields=_timestamp,_source必须显式请求_timestamp。
请注意,只有当此字段标记为'store': true时,才能返回_timestamp。但在按_timestamp排序时,有一种方法可以访问此值,如下所示:
curl 'http://localhost:9200/myindex/mytype/_search?pretty=true' -d '
{ "sort": [ "_timestamp" ], "size": 1}
'给出结果:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : null,
"hits" : [ {
"_index" : "myindex",
"_type" : "mytype",
"_id" : "AUqL0PDXYDMmKSIKO1bj",
"_score" : null,
"sort" : [ 1419684933847 ]
} ]
}
}现在sort[0]是第一个(也是本例中唯一的)排序值:_timestamp。以这种方式使用时,_timestamp不必标记为"store": true。
https://stackoverflow.com/questions/13744233
复制相似问题