栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch sort illegal

elasticsearch sort illegal

在elasticsearch中进行sort排序遇到的bug,bug描述如下:

"error" : {
    "root_cause" : [
      {
        "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 [time] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
      }

.......

该问题知识记录暂时没有详细深入的了解原理,但是结局方法应该可行。

搜索语句如下:

GET test_record/_search
{
  "query": {
    "regexp": {
      "word": ".*"
    }
  },
  "sort": [
    {
      "time": {
        "order": "desc"
      }
    }
  ]
}

错误修改如下:

将time换成time.keysord

通过网络发现出现此错误的可能不止sort一种,aggs也可能出现这种错误。

错误的原因是我们sort或者aggs的字段是text类型,而text类型是作为有个整体提供默认没有索引。

而使用keyword是有索引的,因此可以通过time.keyword来sort或者aggs

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/336300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号