首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch _timestamp

Elasticsearch _timestamp
EN

Stack Overflow用户
提问于 2012-12-06 21:05:57
回答 2查看 6.6K关注 0票数 9

我尝试在索引上定义_timestamp属性。因此,首先,我创建索引

curl -XPUT 'http://elasticsearch:9200/ppe/'

来自服务器的响应:{"ok":true,"acknowledged":true}

然后,我尝试使用_timestamp来定义映射

代码语言:javascript
复制
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"
      }
    }
  }
}'

我收到了来自服务器的回答

代码语言:javascript
复制
{
  "error": "MapperParsingException[No type specified for property [_timestamp]]",
  "status": 400
}

我的映射有什么问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-06 21:36:18

必须在与properties对象相同的级别上定义_ttl_timestamp等特殊字段:

代码语言:javascript
复制
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"
            }
        }
    }
}
'
票数 16
EN

Stack Overflow用户

发布于 2014-12-27 21:08:30

请注意,尽管_timestamp是在顶层定义的,但它将在fields内部返回

代码语言:javascript
复制
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=_timestampfields=_timestamp,_source必须显式请求_timestamp

请注意,只有当此字段标记为'store': true时,才能返回_timestamp。但在按_timestamp排序时,有一种方法可以访问此值,如下所示:

代码语言:javascript
复制
curl 'http://localhost:9200/myindex/mytype/_search?pretty=true' -d ' 
   { "sort": [ "_timestamp" ], "size": 1}
 '

给出结果:

代码语言:javascript
复制
{
  "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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13744233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档