当前位置 博文首页 > 闫玉林的博客:Elasticsearch排序Fielddata is disabled on text
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [publishDate] 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": "bbs",
"node": "3t-pKsnfSOidEJQ3nZihmQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [publishDate] 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
}
创建索引后,搜索,加上发布时间(publishDate)排序时报错,不加(相关度排序)时,返回正常。
一开始是怀疑,发布时间为空导致的,就在创建索引时,加了判断,为null时强制复制 new Date(),还是不行。
最终看了下mapping,发现同事在创建索引时,发布时间字段,未设置为Date,而是text。text是默认分词的,不能用于聚合和排序。最终删除了索引,重建mapping,将publishDate设置为Date类型,问题解决
cs