【问题标题】:Elasticsearch COUNT() text fieldsElasticsearch COUNT() 文本字段
【发布时间】:2021-10-15 06:27:54
【问题描述】:

这是question 的扩展。我正在使用的查询,像这样应该计算每小时的条目数。

GET index_with_text/_search
{
  "size": 0,
  "query": {
    "range": {
      "timestamp": {
        "gte": "2021-06-15",
        "lte": "now"
      }
    }
  }, 
  "aggs": {
    "hit_count_per_day": {
      "date_histogram": {
        "field": "timestamp",
        "calendar_interval": "hour"
      }
    }
  }
}

但是我得到了这个......

"error" : {
"root_cause" : [
  {
    "type" : "illegal_argument_exception",
    "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [timestamp] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
  },

【问题讨论】:

  • 你能分享一下你的索引映射吗?

标签: elasticsearch querydsl


【解决方案1】:

根据您收到的错误,hit_count_per_day 似乎属于 text 类型。

您不能对只有text 类型的字段执行聚合。要执行date_histogram 聚合,您需要修改索引映射,然后重新索引数据。

您需要使用以下索引映射创建一个新索引,然后重新索引新索引中的数据

{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date"
      }
    }
  }
}

【讨论】:

  • 感谢或回复,我会尝试进一步调查并跟进!
  • @HCLW 当然,期待您的更新 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-21
  • 1970-01-01
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 2020-05-12
相关资源
最近更新 更多