elasticsearch 7.12.1报错处理:ElasticsearchStatusException[Elasticsearch exception [type=parse_exception]

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

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

最近在使用RestHighLevelClient测试后端数据时,遇到如下一个报错:


ElasticsearchStatusException[Elasticsearch exception [type=parse_exception, reason=numeric value expected]
]
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:176)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1933)
	...
	Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://192.***.***.***:9200], URI [/exp_store_location/_search?typed_keys=true&max_concurrent_shard_requests=5&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512&ccs_minimize_roundtrips=true], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"parse_exception","reason":"numeric value expected"}],"type":"parse_exception","reason":"numeric value expected"},"status":400}
		at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:326)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:296)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:270)
		at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1654)
		... 71 more

一、我的测试代码:

// 根据坐标排序
    @Test
    void testByLocation() throws Exception {
        SearchRequest request = new SearchRequest("exp_store_location");
        String location = "22.910906957435557,113.87965738641294";
        GeoDistanceQueryBuilder geoDistanceQuery = QueryBuilders.geoDistanceQuery("location"); // 设置查询字段
        //geoDistanceQuery.point(new GeoPoint(location)); // 设置查询中心坐标
        geoDistanceQuery.distance("15",DistanceUnit.KILOMETERS); // 设置查询半径

        request.source().query(geoDistanceQuery);
        /*request.source().query(QueryBuilders.geoDistanceQuery("location").point(new GeoPoint(location)).distance("15",DistanceUnit.KILOMETERS)).sort(
                SortBuilders
                        .geoDistanceSort("location",new GeoPoint(location))
                        .order(SortOrder.ASC)
                        .unit(DistanceUnit.KILOMETERS)
        ).sort(SortBuilders
                .fieldSort("averagePrice")
                .order(SortOrder.ASC)
        );*/
        SearchResponse response = client.search(request, RequestOptions.DEFAULT);
        System.out.println(response.toString());
    }

二、问题所在

问题出在我没有给geoDistanceQuery设置中心坐标

 		GeoDistanceQueryBuilder geoDistanceQuery = QueryBuilders.geoDistanceQuery("location"); // 设置搜索字段
        geoDistanceQuery.point(new GeoPoint(location)); // 设置中心坐标
        geoDistanceQuery.distance("15",DistanceUnit.KILOMETERS); // 设置搜索距离范围

设置中心坐标后问题得到解决。
以下是elastic客户端查询索引的代码文章来源地址https://www.toymoban.com/news/detail-593140.html

GET /exp_store_location/_search
{
  "query": {
    "geo_distance": {
      "distance": "150km",
      "location": "22.910906957435557,113.87965738641294"
    }
  }
  , "sort": [
    {
      "_geo_distance": {
        "location": "22.910906957435557,113.87965738641294",
        "order": "asc",
        "unit": "km"
      },
      "averagePrice": {
        "order": "asc"
      }
    }
  ]
}

最后分享一下我自己的范围测试查询代码

 // 根据坐标排序
    @Test
    void testByLocation() throws Exception {
        SearchRequest request = new SearchRequest("exp_store_location");
        String location = "22.910906957435557,113.87965738641294";
        /*GeoDistanceQueryBuilder geoDistanceQuery = QueryBuilders.geoDistanceQuery("location"); // 设置查询字段
        geoDistanceQuery.point(new GeoPoint(location)); // 设置查询中心坐标
        geoDistanceQuery.distance("15",DistanceUnit.KILOMETERS); // 设置查询半径
        request.source().query(geoDistanceQuery);*/
        request.source()
                 // 查询条件
                .query(QueryBuilders.geoDistanceQuery("location")
                        .point(new GeoPoint(location))
                        .distance("15",DistanceUnit.KILOMETERS)
                )
                // 对结果的排序方式
                .sort(SortBuilders
                        .geoDistanceSort("location",new GeoPoint(location))
                        .order(SortOrder.ASC)
                        .unit(DistanceUnit.KILOMETERS)
                )
                .sort(SortBuilders
                .fieldSort("averagePrice")
                .order(SortOrder.ASC)
                );
        SearchResponse response = client.search(request, RequestOptions.DEFAULT);
        System.out.println(response.toString());
    }

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

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

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

相关文章

  • Elasticsearch集群索引写入失败[FORBIDDEN/12/index read-only / allow delete (api)]处理流程

    操作系统:CentOS 7.3 软件版本:elasticsearch-6.7.2 正常将数据写入到Elasticsearch时,发现写入失败,出现如下报错 检查Elasticsearch集群的active master节点的日志,并没有发现error,但有WARN告警,显示与 flood stage disk watermark [90%] 有关。 上下文有 low disk watermark [80%] 的INFO日志信息,再次

    2024年02月10日
    浏览(48)
  • Elasticsearch8 - Docker安装Elasticsearch8.12.2

    最近在学习 ES,所以需要在服务器上装一个单节点的 ES 服务器环境:centos 7.9 目前最新版本是 8.12.2 新增配置文件 elasticsearch.yml 解释一下,前三行是开启远程访问和跨域,最后一行是开启密码访问 Networking | Elasticsearch Guide [8.12] | Elastic 在宿主机创建容器的挂载目录,我的目录

    2024年04月15日
    浏览(36)
  • Elasticsearch:如何创建 Elasticsearch PEM 和/或 P12 证书?

    你是否希望使用 SSL/TLS 证书来保护你的 Elasticsearch 部署? 在本文中,我们将指导你完成为 Elasticsearch 创建 PEM 和 P12 证书的过程。 这些证书在建立安全连接和确保 Elasticsearch 集群的完整性方面发挥着至关重要的作用。 友情提示:你可以选择其中一种方法来在你的环境中创建和

    2024年02月13日
    浏览(34)
  • 安装Elasticsearch 8.12.2版本出现的问题

            在Elasticsearch 官网下载了一个es的安装包,准备放在windows电脑上研究研究,下载下来之后启动报错。 jdk版本对应 warning: ignoring JAVA_HOME=E:devjdkjdk17jdk-17.0.10; using bundled JDK Exception in thread \\\"main\\\" java.lang.RuntimeException: starting java failed with [1] output: # # There is insufficient

    2024年03月26日
    浏览(47)
  • 【异常】ES报错ElasticsearchStatusException:missing authentication credentials for REST request

    使用Flink输出(sink)到Elasticsearch时,出现了上面的错误,是因为登录到ES,ES启用了账号密码的模式,因此必须要使用账号密码才能够访问它。 于是新增如下代码后,问题解决

    2024年02月11日
    浏览(64)
  • 【Elasticsearch教程12】Mapping字段类型之object

    首先给出结论: 在一个字段存储 一个 JSON对象,可以选择 object 类型 在一个字段存储 多个 JSON对象,可以选择 nested 类型 假设有一个人员信息如下: 建表时会建一个字段存一个值,它的缺点是字段 扁平化 , 无法直观的表现 层级关系 。 字段 值 region US manager_age 30 manager_firstn

    2024年02月09日
    浏览(26)
  • [Spring Boot]12 ElasticSearch实现分词搜索功能

    我们在使用搜索功能的时候,有时,为了使搜索的结果更多更广,比如搜索字符串“领导力”,希望有这些组合的结果(领导力、领导、领、导、力)都要能够全部展示出来。 这里我们引入ElasticSearch结合分词插件,来实现这样的搜索功能。 比如:一款app需要对“课程”进行

    2024年02月03日
    浏览(34)
  • centos7 搭建Elasticsearch 8.12.2集群并安装kibana 8.12.2

    rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch vim /etc/yum.repos.d/elasticsearch.repo 输入以下内容(默认会下载最新版本的Elasticsearch):

    2024年03月20日
    浏览(35)
  • ElasticSearch_12_ES的高性能设计

    容量问题: 电商网站商品上亿条时,涉及到单表数据过大必须拆分表,数据库磁盘占用过大必须分库(mycat)。 性能问题: mysql实现模糊查询必须使用 like, 只有 后模糊 才能走索引,前模糊和全模糊都不会走索引,比如查询“笔记本电脑”等时,上亿条数据的商

    2024年02月02日
    浏览(33)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包