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

来源:互联网 发布:java apache 框架 编辑:程序博客网 时间:2024/06/06 18:27

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}
原创粉丝点击