elasticsearch 将时间类型为时间戳保存格式的时间字段格式化返回

dsl查询用法如下:

GET /your_index/_search
{
  "_source": {
    "includes": [
      "timestamp", // Include the timestamp field in the search results
      // Other fields you want to include
    ],
    "excludes": []
  },
  "query": {
    // Your query here
  },
  "script_fields": {
    "formatted_timestamp": {
      "script": {
        "source": "doc['timestamp'].value.format('yyyy-MM-dd HH:mm:ss')"
      }
    }
  }
}

示例:

{
  "_source": {
    "includes": [
      "_host",
      "_time"
    ],
    "excludes": []
  },
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "formatted_time": {
      "script": {
        "source": "doc['_time'].value != null ? doc['_time'].value.toInstant().toString() : null"
      }
    }
  }
}

elasticsearch 将时间类型为时间戳保存格式的时间字段格式化返回_第1张图片

你可能感兴趣的:(#,ElasticSearch,elasticsearch,大数据,dsl)