您的位置:首页 > 其它

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

2017-07-21 16:40 274 查看
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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Elasticsea