ES排序报错:Elasticsearch exception [type=illegal_argument_exception, reason=Text

这篇具有很好参考价值的文章主要介绍了ES排序报错:Elasticsearch exception [type=illegal_argument_exception, reason=Text。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

更改前:

@ApiOperation("分页排序")
    @GetMapping("pageAndSort/{page}/{size}")
    public Page<Hero> pageAndSort(@PathVariable Integer page,@PathVariable Integer size){
        //构建本地查询对象
        NativeSearchQueryBuilder query = new NativeSearchQueryBuilder();
        //
        PageRequest pageRequest = PageRequest.of(page, size);

        query.withPageable(pageRequest);
        query.withSort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));

        SearchHits<Hero> search = elasticTemplate.search(query.build(), Hero.class);
        List<Hero> blogs = new ArrayList<>();
        for (SearchHit<Hero> hero : search) {
            blogs.add(hero.getContent());
        }
        PageImpl<Hero> heroes = new PageImpl<>(blogs, pageRequest, search.getTotalHits());
        return heroes;
    }

错误提示信息: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 [createTime] in order to load field data by uninverting the inverted index. Note that this can use significant memory.]

翻译过来就是:对于需要每个文档字段数据(如聚合和排序)的操作,文本字段没有进行优化,因此这些操作在默认情况下是禁用的。请使用关键字字段代替。或者,在[createTime]上设置fielddata=true,以便通过反求倒排索引来加载字段数据。注意,这可能会使用有效内存。]

在es中,text类型的字段使用一种叫做fielddata的查询时内存数据结构。当字段被排序,聚合或者通过脚本访问时这种数据结构会被创建。它是通过从磁盘读取每个段的整个反向索引来构建的,然后存存储在java的堆内存中。

 这里fileddata默认是不开启的。Fielddata可能会消耗大量的堆空间

所以换一种方式解决:在需要的字段上添加关键字  keyword

更改后:

 @ApiOperation("分页排序")
    @GetMapping("pageAndSort/{page}/{size}")
    public Page<Hero> pageAndSort(@PathVariable Integer page,@PathVariable Integer size){
        //构建本地查询对象
        NativeSearchQueryBuilder query = new NativeSearchQueryBuilder();
        //
        PageRequest pageRequest = PageRequest.of(page, size);

        query.withPageable(pageRequest);
        query.withSort(SortBuilders.fieldSort("createTime.keyword").order(SortOrder.DESC));

        SearchHits<Hero> search = elasticTemplate.search(query.build(), Hero.class);
        List<Hero> blogs = new ArrayList<>();
        for (SearchHit<Hero> hero : search) {
            blogs.add(hero.getContent());
        }
        PageImpl<Hero> heroes = new PageImpl<>(blogs, pageRequest, search.getTotalHits());
        return heroes;
    }


        query.withSort(SortBuilders.fieldSort("createTime.keyword").order(SortOrder.DESC));文章来源地址https://www.toymoban.com/news/detail-506932.html

到了这里,关于ES排序报错:Elasticsearch exception [type=illegal_argument_exception, reason=Text的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=illegal_argument_excep

    org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=illegal_argument_exception, reason=request [/zc/_search] contains unrecognized parameters: [ccs_minimize_roundtrips], [ignore_throttled]] 原因: 该异常是由于在对索引进行搜索请求时,使用了不被识别的参数导致的。具体来说,异常信息中列出了两

    2024年02月08日
    浏览(33)
  • Caused by: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Roo

     我们在使用RestClient创建索引库时出现了这个错误。 可以检查一下 CreateIndexRequest 类型变量request 是否导入正确的包 有两个同名的包,我们选择: import org.elasticsearch.client.indices.CreateIndexRequest;     测试成功  创建的DSL的索引库  以上解决办法参考 Elasticsearch exception [type=mapp

    2024年01月23日
    浏览(40)
  • Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]

    Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed] 今天在做项目遇到这个问题,Es那边出现了问题,谷粒商城去Es中查数据的时候,根据品牌id去查询数据报错。   {\\\"error\\\":{\\\"root_cause\\\":[{ \\\"type\\\":\\\"query_shard_exception\\\",\\\"reason\\\":\\\"failed to create query: {n  \\\"bool\\\" : {n    \\\"fil

    2024年02月02日
    浏览(31)
  • Elasticsearch exception [type=index_not_found_exception, reason=no such index [**]]

     1.代码运行出现找不到Index,先排除index是否存在。   2.springboot和ES映射,默认是把对象类型映射为index,class对象默认是大写开头,所以要看是都是因为大小写不匹配。如若因为大小写原因导致,可以通过@Document注解指定index  

    2024年02月14日
    浏览(32)
  • Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]

    Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:   我们在使用RestClient创建索引库时出现了这个错误。 可以检查一下 CreateIndexRequest 类型变量request 是否导入正确的包 有两个同名的包,我们选择: 创建的索引

    2024年02月11日
    浏览(31)
  • 解决Elasticsearch exception [type=circuit_breaking_exception, reason=[parent] Data too large问题

    一、背景 公司有一批8万的数据存储在Mysql中,然后我使用多线程的方式调用Elasticsearch的bulk()方法推送到ES,但是在推送过程中出现了该问题,这属于插入数据时产生的问题 二、异常 三、解决办法 加大 -Xms 和 -Xmx 的值,比如 docker-compose.yaml 文件中可以这样设置: 四、解释

    2024年02月03日
    浏览(36)
  • Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index r【已解决】

    亲测 2022/08/16 BJ 集群存储资源高水位异常,默认当磁盘空间大于95%时,就会禁止写入。 首先让es节点腾出足够的空间、 删除磁盘数据 ; 扩容。 执行恢复命令 让es恢复到可写入状态。问题解决!

    2024年02月12日
    浏览(32)
  • Elasticsearch exception [type=parsing_exception, reason=[multi_match] unknown token [START_ARRAY] af

    代码报错 QueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(deptIdList, “data.deptId”, “modifiedData.deptId”); multiMatchQuery这个API,第一个参数不支持List类型, 虽然传List没报错, 但是往ES发送查询请求的时候就会抛异常出来 传一个字段, 如果你想多字段in查询,就用类似下面这样写法就可以了

    2024年02月07日
    浏览(41)
  • ES 报错 403 cluster_block_exception....

    错误日志如上,导致报错的原因是 索引变为只读,因为磁盘上没有更多空间。如果您使用了 95% 的磁盘空间。es 服务器将每 30 秒将所有索引变为只读模式。如果没有剩余空间,则需要释放足够的空间或按照指南所述更改 es 配置。 解决思路 1.清理或者扩展磁盘空间 2.es服务器

    2024年02月11日
    浏览(34)
  • elasticsearch创建索引报[type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]......

    小伙伴们,你们好,我是老寇 经过反复排查,发现是安装的pinyin和ik分词版本不对,只需要修改成与es版本一致即可 es 7.6.2 举例 1.在windows界面用压缩软件打开elasticsearch-analysis-ik-7.6.2.jar 2.将pom.xml拖出到桌面 3.修改版本 4.将pom.xml放回压缩包( 原路放回 ) 5. elasticsearch-analysis

    2024年02月13日
    浏览(23)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包