首页 > 其他分享 >Elasticsearch索引不存在时,查询接口报错怎么办?

Elasticsearch索引不存在时,查询接口报错怎么办?

时间:2024-01-16 18:23:48浏览次数:31  
标签:index 文档 xxx long 索引 Elasticsearch 报错 order

1、索引不存在,报错:type=index_not_found_exception, reason=no such index
解决办法:

DSL:
GET /text_index_003/_search?ignore_unavailable=true
java 代码:
 NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN)
                .withQuery(xxxQuery)
                .withAggregations(xxxAgg)
                .build();

2、排序字段mapping不存在报错:"reason":"No mapping found for [xxx] in order to sort on"

解决办法:

DSL:
GET /text_005/_search?ignore_unavailable=true
{
  "sort": [
    {
      "price": {
        "order": "desc",
        "unmapped_type": "long"
      }
    }
  ],
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "xxx": {
              "gte": 10,
              "lte": 20
            }
          }
        },
        {"term": {
          "yyy": "ddd"
        }}
      ]
    }
  }
}
Java:

new FieldSortBuilder("xxx").unmappedType("long").order(SortOrder.DESC);
 
SortBuilders.fieldSort("xxx").unmappedType("long").order(SortOrder.DESC)
 

完美解决!!!!

更多细节参考官方文档:
es官方文档
spring-data-elasticsearch官方文档
参考说明

 

标签:index,文档,xxx,long,索引,Elasticsearch,报错,order
From: https://www.cnblogs.com/hbuuid/p/16870175.html

相关文章

  • vscode报错Pylance client: couldn‘t create connection to server.解决
    问题描述:一打开vscode,右下角就弹报错,Pylanceclient:couldn’tcreateconnectiontoserver.,让我打开output,打开后似乎是在说连不上server因为连不上server,所以我的python代码没法解析,尝试重开vscode也没用问题解决:点开左侧的拓展,找到PythonExtensionPack,这就是解析python代......
  • git 提交报错
    这个问题是因为当你在终端输入gitcommit-m“XXX”,提交代码的时候,pre-commit(客户端)钩子,它会在Git键入提交信息前运行做代码风格检查。如果代码不符合相应规则,则报错,而它的检测规则就是根据.git/hooks/pre-commit文件里面的相关定义。解决方法(三种)1、第一种卸载husky。只要......
  • ElasticSearch中_source、store_fields、doc_values性能比较【转载】
    原文地址请点击在这篇文章中,我想从性能的角度探讨ElasticSearch为我们存储了哪些字段,以及在查询检索时这些字段如何工作。实际上,ElasticSearch和Solr的底层库Lucene提供了两种存储和检索字段的方式:store_fields和doc_values。此外,ElasticSearch默认提供了 _source 字段,这是在......
  • Elastic实战:彻底解决spring-data-elasticsearch日期、时间类型数据读取报错问题
    0.引言在使用spring-data-elasticsearch读取es中时间类型的数据时出现了日期转换报错,不少初学者会在这里困惑很久,所以今天我们专门来解读该问题的几种解决方案。1.问题分析该问题的报错形式一般是:Failedtoconvertfromtype[java.lang.String]totype[java.util.Date]f......
  • 携程OceanBase开源实践——索引统计功能实现
    【作者】施纬,携程数据库研发工程师,主要负责数据库运维和内核研发。姜贤富,携程高级数据库研发工程师,主要负责携程数据库监控运维及工具研发,拥有十年运维经验。【概述】自从2021年OceanBase开源以来,携程一直致力于其在实际业务场景下的应用实践,探索新一代分布式数据库的可能性。......
  • Spring Boot3.x集成ElasticSearch8.x
    SpringBoot3.x集成ElasticSearch8.x版本说明,本demo使用SpringBoot3.2.1+JDK17+ElasticSearch8.11.3前提是已经部署好了自己的ElasticSearch环境,我这里直接用容器默认部署好了,能访问即可创建SpringBoot项目导入pom依赖<dependency><grou......
  • CentOS7 报错 ”Repository base is listed more than once in the configuration...
    CentOS7在使用yum时出现以下错误:RepositorybaseislistedmorethanonceintheconfigurationRepositoryupdatesislistedmorethanonceintheconfigurationRepositoryextrasislistedmorethanonceintheconfigurationRepositorycentosplusislistedmore......
  • 安装torch2trt中遇到的报错:ModuleNotFoundError: No module named 'torch2trt.flatten
    这一个报错折腾了一整天,在这里记录一下方便他人可以快速解决问题:首先说明一下本人的版本情况:Linux系统CUDA:11.8Python:3.8torch:2.0.0torchvision:0.15.0代码中报错的位置是:fromtorch2trtimporttorch2trt报错的原因是:ModuleNotFoundError:Nomodulenamed'torch2trt......
  • 一文让你对mysql索引底层实现明明白白
    开篇:图片是本人随笔画的,有点粗糙,望大家谅解,如有不妥之处,请联系我们,感谢一、索引到底是什么.索引是帮助mysql高效获取数据的排好序的数据结构.索引是存储在文件里的.数据结构:二叉树HASHBTREE   如果没有索引的话,循环一条一条的找,找一次就是一次IO,这样速度就会很慢......
  • Unity报错记录->ArgumentNullException: Value cannot be null. Parameter name: _uni
    问题描述项目报错ArgumentNullException:Valuecannotbenull.Parametername:_unity_self不会影响项目正常运行,但是在DeBug模式下会一直卡住,非常恶心。解决方法删除项目中的Library文件夹,重新加载项目......