elasticsearch - 返回 elasticsearch 中的时间戳字段

标签 elasticsearch

为什么在能够通过它过滤查询时看不到 _timestamp 字段?

以下查询返回正确的文档,但不是时间戳本身。如何返回时间戳?

{
  "fields": [
    "_timestamp",
    "_source"
  ],
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "_timestamp": {
            "from": "2013-01-01"
          }
        }
      }
    }
  }
}

映射是:

{
    "my_doctype": {
        "_timestamp": {
            "enabled": "true"
        },
        "properties": {
            "cards": {
                "type": "integer"
            }
        }
    }
}

示例输出:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "test1",
      "_type" : "doctype1",
      "_id" : "HjfryYQEQL6RkEX3VOiBHQ",
      "_score" : 1.0, "_source" : {"cards": "5"}
    }, {
      "_index" : "test1",
      "_type" : "doctype1",
      "_id" : "sDyHcT1BTMatjmUS0NSoEg",
      "_score" : 1.0, "_source" : {"cards": "2"}
    }]
  }

最佳答案

启用时间戳字段时,默认情况下会对其进行索引但不存储。因此,虽然您可以按时间戳字段进行搜索和过滤,但您无法通过记录轻松检索它。为了能够检索时间戳字段,您需要使用以下映射重新创建索引:

{
    "my_doctype": {
        "_timestamp": {
            "enabled": "true",
            "store": "yes"
        },
        "properties": {
            ...
        }
    }
}

通过这种方式,您将能够检索时间戳作为自纪元以来的毫秒数。

关于elasticsearch - 返回 elasticsearch 中的时间戳字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15653676/

相关文章:

django - 无法使用Django Haystack和Elasticsearch搜索术语的一部分

elasticsearch - 堆栈 elasticsearch + fluentd

elasticsearch - Elasticsearch 节点之一继续进入错误状态

elasticsearch - 使用ElasticSearch按给定数组排序

javascript - Elasticsearch 正则表达式中的空格不起作用

elasticsearch - 为什么 NEST 包括 TCP 保持事件状态?

java - 基于条件的平均 Elasticsearch 查询

elasticsearch - 您需要删除Elasticsearch别名吗?

elasticsearch - 是否可以确保对Elasticsearch中的搜索进行n匹配?

docker - Elasticsearch Pod没有运行重启