9

我试图_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
}

我的映射有什么问题?

4

2 回答 2

16

必须在与对象相同的级别上定义特殊字段,例如_ttl和:_timestampproperties

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"
            }
        }
    }
}
'
于 2012-12-06T13:36:17.690 回答
3

请注意,虽然_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=_timestampor明确请求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

于 2014-12-27T13:08:29.840 回答