elasticsearch 我可以强制ES以epoch\u millis格式返回日期吗?,elasticsearch,elasticsearch" /> elasticsearch 我可以强制ES以epoch\u millis格式返回日期吗?,elasticsearch,elasticsearch" />

elasticsearch 我可以强制ES以epoch\u millis格式返回日期吗?

elasticsearch 我可以强制ES以epoch\u millis格式返回日期吗?,elasticsearch,elasticsearch,我有这个字段映射 "time": { "type": "date", "format": "strict_date_optional_time||epoch_millis" }, 我正在使用此筛选器查询文档: "range": { "time": { "gt": "1473157500000", "lte": "1473158700000

我有这个字段映射

"time": {
              "type": "date",
              "format": "strict_date_optional_time||epoch_millis"
           },
我正在使用此筛选器查询文档:

"range": {
            "time": {
              "gt": "1473157500000",
              "lte": "1473158700000",
            "format": "epoch_millis"
            }
这可以工作并返回文档,但结果以不同的格式显示时间字段:

"time": "2016-09-06T10:25:23.678",

是否可以强制以epoch\u millis返回查询?

源代码始终返回原始文档中的数据。
理想情况下,我认为将
\u源数据转换为所需格式以便在客户端显示或以其他方式显示可能更理想、更灵活。
但是,对于上述用例,您可以使用
fielddata\u fields

将以字段数据实际存储方式的格式返回字段,在
date
的情况下,字段恰好是
epoch\u millis

从文件:

允许为每次点击返回字段的字段数据表示形式 字段数据字段可以用于未存储的字段。它是 重要的是要了解使用fielddata_fields参数 使该字段的术语加载到内存(缓存),从而 将导致更多的内存消耗

例如:

post <index>/_search
{
    "fielddata_fields": [
       "time"
    ]    
}
post/\u搜索
{
“字段数据\字段”:[
“时间”
]    
}

源文件始终返回原始文档中的数据。
理想情况下,我认为将
\u源数据转换为所需格式以便在客户端显示或以其他方式显示可能更理想、更灵活。
但是,对于上述用例,您可以使用
fielddata\u fields

将以字段数据实际存储方式的格式返回字段,在
date
的情况下,字段恰好是
epoch\u millis

从文件:

允许为每次点击返回字段的字段数据表示形式 字段数据字段可以用于未存储的字段。它是 重要的是要了解使用fielddata_fields参数 使该字段的术语加载到内存(缓存),从而 将导致更多的内存消耗

例如:

post <index>/_search
{
    "fielddata_fields": [
       "time"
    ]    
}
post/\u搜索
{
“字段数据\字段”:[
“时间”
]    
}

ES 6.5以后,我们需要在此特定结构中使用
docvalue\u字段
,因为
fielddata\u字段
已被弃用。例如,假设我们摄取了以下格式的json文档:

{
  "@version": "1",
  "@timestamp": "2019-01-29T10:01:19.217Z",
  "host": "C02NTJRMG3QD",
  "message": "hello world!"
}
现在,让我们使用
docvalue\u字段执行以下get查询:

curl -X GET \
  http://localhost:9200/myindex/_search \
  -H 'Content-Type: application/json' \
  -d '{
  "query": {
    "match_all": {}
  },
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "epoch_millis"
    }
  ]
}'
我们将得到以下响应:

{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "myindex",
                "_type": "doc",
                "_id": "mY8OmWgBF3ZItz5TVDiL",
                "_score": 1,
                "_source": {
                    "@version": "1",
                    "@timestamp": "2019-01-29T10:01:19.217Z",
                    "host": "C02NTJRMG3QD",
                    "message": "hello world!"
                },
                "fields": {
                    "@timestamp": [
                        "1548756079217"
                    ]
                }
            }
        ]
    }
}

ES 6.5以后,我们需要在此特定结构中使用
docvalue\u字段
,因为
fielddata\u字段
已被弃用。例如,假设我们摄取了以下格式的json文档:

{
  "@version": "1",
  "@timestamp": "2019-01-29T10:01:19.217Z",
  "host": "C02NTJRMG3QD",
  "message": "hello world!"
}
现在,让我们使用
docvalue\u字段执行以下get查询:

curl -X GET \
  http://localhost:9200/myindex/_search \
  -H 'Content-Type: application/json' \
  -d '{
  "query": {
    "match_all": {}
  },
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "epoch_millis"
    }
  ]
}'
我们将得到以下响应:

{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "myindex",
                "_type": "doc",
                "_id": "mY8OmWgBF3ZItz5TVDiL",
                "_score": 1,
                "_source": {
                    "@version": "1",
                    "@timestamp": "2019-01-29T10:01:19.217Z",
                    "host": "C02NTJRMG3QD",
                    "message": "hello world!"
                },
                "fields": {
                    "@timestamp": [
                        "1548756079217"
                    ]
                }
            }
        ]
    }
}