我试图定义_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
}
这有什么错我的映射?
特殊领域,如_ttl
和_timestamp
都在同一水平被定义为properties
对象:
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"
}
}
}
}
'
不过要注意的是,虽然_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
}
}
需要注意的是_timestamp
必须由明确要求fields=_timestamp
或fields=_timestamp,_source
。
需要注意的是_timestamp
当这个字段被标记为只可返回'store': true
。 但通过排序时访问该值的方式_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
以这种方式使用时。