首页 > 其他分享 >elasticsearch使用Sort排序时Please use a keyword field instead.

elasticsearch使用Sort排序时Please use a keyword field instead.

时间:2024-05-23 16:18:43浏览次数:16  
标签:Sort use recordTime keyword Please exception field

具体报错信息

ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[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 [recordTime] in order to load field data by uninverting the inverted index. Note that this can use significant memory.]]; nested: ElasticsearchException[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 [recordTime] in order to load field data by uninverting the inverted index. Note that this can use significant memory.]];

原因是在使用es查询的时候使用了orderby.

核心提示在Please use a keyword field instead. Alternatively, set fielddata=true on [recordTime] in order to load field data by uninverting the inverted index.

待排序字段recordTime没有为排序优化,所以无法排序,需要配置FieldType.Keywordfielddata = true

给对应的字段加上注解,这里使用的是easy-es,注解有所不同

    @IndexField(fieldType = FieldType.KEYWORD)
    private LocalDateTime recordTime;

项目启动后会自动在ElasticSearch创建索引,查询索引信息,有mapping才说明注解配置生效了,因为注解声明的字段信息在ElasticSearch对应的就是mapping

刷新索引可以看到
image

标签:Sort,use,recordTime,keyword,Please,exception,field
From: https://www.cnblogs.com/leepandar/p/18208791

相关文章

  • React 中的useCallback
    useCallback 是React中的一个钩子函数,它用于创建一个稳定的回调函数,并且可以帮助优化性能。通常情况下,当父组件向子组件传递回调函数时,如果没有使用 useCallback,每次父组件重新渲染时,都会创建一个新的回调函数实例,这可能导致子组件不必要的重新渲染。使用 useCallback 可以......
  • Mybatis框架 <insert> 标签内 useGeneratedKeys="true" 和 keyProperty="xxx" 属性
    useGeneratedKeys="true" 和 keyProperty="secondIndex" 这两个属性经常与MyBatis(Java持久层框架)的 <insert> 标签一起使用。这两个属性主要用于在插入记录后,从数据库返回的自动生成的主键或其他键值中,获取该键值并将其设置到Java对象的某个属性中。useGeneratedK......
  • error: use of deleted function ‘YYSTYPE::YYSTYPE()’[解决]
    /home/zhywyt/Cmpelier/compiler2024/build/y.tab.cpp:1036:9:error:useofdeletedfunction‘YYSTYPE::YYSTYPE()’1036|YYSTYPEyylval;报错信息如下:bison文件中的union如下,发现错误为name的类型为带析构函数的类,导致出现问题。具体原因不明。修改为string*后编译......
  • 解决postgres数据库remaining connection slots are reserved for non-replication su
    来源:【小工具】-解决postgres数据库remainingconnectionslotsarereservedfornon-replicationsuperuserconnectio-CSDN博客psycopg2.OperationalError:FATAL:remainingconnectionslotsarereservedfornon-replicationsuperuserconnection报错信息Traceback......
  • 9-4 file-sort命令的使用
    9.4.1file查看文件file命令作用:file-determinefiletype #确定文件类型用法:file/etc/passwd注:linux系统不根据后缀名识别文件类型用file命令查看文件的类型 9.4.2按一定规则排序查看文件查看文件:ls-ltr:按时间排序 t......
  • PWN系列-Unsorted Bin Attack
    PWN系列-UnsortedBinAttack概述UnsortedBinAttack,顾名思义,该攻击与Glibc堆管理中的的UnsortedBin的机制紧密相关。UnsortedBinAttack被利用的前提是控制UnsortedBinChunk的bk指针。UnsortedBinAttack可以达到的效果是实现修改任意地址值为一个较大的数值......
  • Java RMI遇到的Connection refused to Host: 127.x.x.x/192.x.x.x/10.x.x.x问题解决方
    问题故障解决记录--JavaRMIConnectionrefusedtohost:x.x.x.x....在学习JavaRMI时,我遇到了以下情况问题原因:可能大家的host是10或者192的私有地址,我估计都是和我一样的一个原因:/etc/hosts文件的配置问题(我是ubuntu系统下的实验环境),也就是主机名称和IP地址的映射关系......
  • [ES2024] Improve Application-wide Error Handling rethrowing JavaScript Error wit
    Thenew cause datapropertythatyoucanaddtoathrown Error canbeusedtoretainaccesstotheoriginalerrorcaughtinapromiserejection. constsendLog=(...args)=>console.log(...args);asyncfunctionfetchStuff(){awaitfetch('h......
  • currentTuningFileInfoRef.current = useMemo(() => { return tuningFileOptionsMemo?
    在React中,useMemo和useEffect都是Hooks,但它们各自有不同的用途和适用场景。上述代码片段使用了useMemo来memoize(记忆化)一个计算结果,确保只要依赖项(tuningFileOptionsMemo和currentTuningFileId)不变,返回的引用也不会改变。这样做可以避免在每次渲染时都进行查找操作,从而提......
  • 火山引擎ByteHouse助推金融头部客户精准营销提效
    随着数字经济的快速发展,数字金融作为数字经济的重要支撑和驱动力,得到了各界的高度重视。在2023年12月,国家数据局等十七部门联合印发《“数据要素×”三年行动计划(2024—2026年)》,就数据要素×金融服务场景,提出要提升金融服务水平。 数据驱动在金融领域中的重要作用不言而喻。从......