看,灰机...

谁帮忙看下这个错误

Elasticsearch | 作者 hjqtlq | 发布于2017年08月04日 | 阅读数:22569

错误原文这样的
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [PlayerId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "paymentdb",
"node": "ZicnPW_IRsCdYH_gUL3r9Q",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [PlayerId] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
]
},
"status": 400
}
我的查询语句这样的:
{"aggregations":{"totalPlayer":{"cardinality":{"field":"PlayerId"}}},"size":0}    
已邀请:

shellmeng

赞同来自: hjqtlq laoyang360

这个问题是查询时候一个比较常见的问题。
如果你的索引中,该字段不是数值型(integer、double、long)或者keyword,而是text类型的,在使用该字段进行查询、排序、聚合时候,就会出现Fielddata is disabled on text fields by default. 
解决办法:
1.把改字段的索引类型改成keyword或者数值型
或者
2:索引字段类型还是text,但是加mapping中fielddata=true。这种不推荐,因为这样加载时候,占用的内存

kennywu76 - Wood

赞同来自: hjqtlq

_source里的PlayerID是Int并不意味着索引的时候就是Int,你需要看索引mapping里这个字段的类型定义。

hjqtlq

赞同来自:

提示说PlayerId不能为text类型,但是我的PlayerId全部都是INT类型的啊!!!
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 828,
"max_score": 1,
"hits": [
{
"_index": "paymentdb",
"_type": "log",
"_id": "590fea472ff194131419f587",
"_score": 1,
"_source": {
"PlayerId": 1000051,
"extraInfo": "999999",
"UpdateTime": "2017-05-08T09:40:09.018000",
"RMB": 1,
"Process": true,
"amount": "1.00",
"serverId": "8",
"tradeNo": "20170508114704515"
}
}
]
}
}

Erin

赞同来自:

 Elasticsearch exception [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 [addTime] in order to load field data by uninverting the inverted index. Note that this can use significant memory.]
这咋解决啊

要回复问题请先登录注册