无法用毫秒正确排序日期

时间:2013-11-05 10:28:27

标签: elasticsearch

使用秒的映射定义:

  "time": {
           "type": "date",
           "store": "yes",
           "format": "yyyy/MM/dd HH:mm:ss",
           "index": "analyzed"
        },

时间字段正确排序“desc”和“asc”

然而,我们需要毫秒精度

  "time": {
           "type": "date",
           "store": "yes",
           "format": "yyyy/MM/dd HH:mm:ss.SSS",
           "index": "analyzed"
        },

然后奇怪的是,“asc”的排序正在返回排序顺序 而对“desc”的排序正在返回正确的毫秒级

1 个答案:

答案 0 :(得分:3)

回答我自己的问题..自定义映射语法不正确。更正后的版本是 下面用毫秒正确排序日期。

唯一剩下的小问题是接受错误格式的方式和原因以及如何防止这种情况。

POST test2
{
   "settings": {
    "number_of_shards": 1
},
"mappings": {
  "logevent": {
     "properties": {
        "logtime": {
           "type": "date",
           "store": "yes",
           "format": "yyyy/MM/dd HH:mm:ss.SSS"
        },
        "eventKey": {
           "type": "string",
           "store": "yes",
           "index": "analyzed"
        },
        "channelid": {
           "type": "string",
           "store": "yes",
           "index": "analyzed"
        },
        "eventtype": {
           "type": "string",
           "store": "yes",
           "index": "analyzed"
        },
        "step": {
           "type": "string",
           "store": "yes",
           "index": "analyzed"
        },
        "line": {
           "type": "string",
           "store": "yes",
           "index": "analyzed"
        }
     }
  }
   }
}