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
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值