在Elasticsearch中排序,忽略字段的日期部分

时间:2016-12-30 04:46:04

标签: elasticsearch

我的日期字段映射为:

 "created": {
          "type"  : "date",
          "format": "yyyy-MM-dd HH:mm:ss"
     },

现在我根据以上字段进行排序:

"sort":[
    {"created":{"order":"asc"}}
],

排序时只需要时间的一部分,并忽略日期部分。

{
    "_index": "somehting",
    "_type": "UserActivity",
    "_id": "81574",
    "_score": null,
    "_source": {
      "created": "2016-03-29 00:00:07",
      "appCode": "appcode",
      "userId": "100008057363993"
    },
    "sort": [
      "00:00:07"
    ]
  },

如何根据整个日期排序? 请注意我不能使用脚本作为生产服务器上的禁用脚本,我无法重新索引..

添加总映射:

{
  "someIndex": {
    "mappings": {
      "UserActivity": {
        "_timestamp": {
          "enabled": true,
          "store": true,
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "properties": {
          "_table": {
            "type": "string"
          },
          "_tableat": {
            "type": "string"
          },
          "activity": {
            "properties": {
              "_table": {
                "type": "string"
              },
              "_tableat": {
                "type": "string"
              },
              "clientId": {
                "type": "integer"
              },
              "code": {
                "type": "string"
              },
              "created": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss"
              },
              "foreignName": {
                "type": "string"
              },
              "frequency": {
                "type": "integer"
              },
              "id": {
                "type": "long"
              },
              "lastUpdated": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss"
              },
              "name": {
                "type": "string"
              },
              "points": {
                "type": "long"
              },
              "strategy": {
                "type": "string"
              }
            }
          },
          "activityId": {
            "type": "string"
          },
          "appCode": {
            "type": "string"
          },
          "clientId": {
            "type": "long"
          },
          "created": {
            "type": "string"
          },
          "details": {
            "type": "string"
          },
          "foreignName": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "lastUpdated": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "notes": {
            "type": "string"
          },
          "userId": {
            "type": "long"
          }
        }
      }
    }
  }
}

0 个答案:

没有答案