ES中查询数据使用date_histogram时报错

ES中,查询数据时,出现如下错误:

"reason": {
    "type": "illegal_argument_exception",
    "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [validataTimeSeconds] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}

原因是由于使用date_histogram计算柱状图数据的时候,field的值,必须为数值型(int,date,Long等),出现这种情况,就是因为插入数据时,将field的类型定义为String型了。

解决办法:将field的数值类型改为Long或其他数值型

GET  pi——2/event/_search  
{
  "size": 0,
  "query" : {
    "constant_score" : {
      "filter" : {
        "range" : {
          "validataTimeSeconds" : {
            "gte" : 1499654929, 
            "lte" : 1499655380
          }
        }
      }
    }
  },
  "aggs" : {
    "by_time" : {
      "date_histogram" : {
        "field" : "validataTimeSeconds",
        "interval" : "100ms",
        "extended_bounds":{
          "min" : 1499654929,
          "max" : 1499655380
        }
      },
      "aggs": {
        "event_status_group": {
          "filters": {
            "filters": {
                "NODATA":{
                "match_phrase":{
                  "status":-1
                }
              },
              "ALERT":{
                "match_phrase":{
                  "status":0
                }
              },
              "OK": {
                "match_phrase":{
                  "status":1
                }
              }
            }
          }
        }
      }
    }
  }
}
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [validataTimeSeconds] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "pi_2",
        "node": "L-BYrdr3TKK17zNDXM1vTA",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [validataTimeSeconds] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [validataTimeSeconds] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
    }
  },
  "status": 400
}
Date Histogram是一个在Elasticsearch使用的聚合方法,用于按照间间隔对日期进行分组和计数。它类似于Histogram,但是支持日期表达式作为区间。 Date Histogram的用法相对于Histogram来说更加灵活,可以根据指定的日期表达式来对间进行分组。例如,你可以将间隔(interval)指定为一个月,它会智能地知道2月比12月要短,并且还能根据区进行定制,以便根据用户的区来生成图形,而不是根据服务器的区。 通常的Histogram桶也可以处理日期,但是它不具备自动识别日期并根据日期的特性进行处理的能力。而Date Histogram可以根据指定的间间隔自动识别日期,并且能够合理地处理区,这样就可以根据客户端的区来进行图表的定制。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [date_histogram](https://blog.csdn.net/opera95/article/details/78614244)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [[Elasticsearch] 聚合 - 数据处理(Looking at Time)](https://blog.csdn.net/dm_vincent/article/details/42594043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值