Elasticsearch 异常 [类型=search_phase_execution_exception,原因=所有分片失败]

发布于 2025-01-11 00:46:59 字数 1650 浏览 0 评论 0原文

我正在 Spring Boot Rest API 中进行弹性搜索。我正在尝试添加基于距离的查询。我在运行时遇到以下异常:

Elasticsearch 异常 [type=search_phase_execution_exception, Reason=all shards failed];嵌套异常是 ElasticsearchStatusException[Elasticsearch 异常 [type=search_phase_execution_exception, Reason=all shards failed]]

以下是我的代码:

// Geo distance
        GeoDistanceSortBuilder distanceSortBuilder = new GeoDistanceSortBuilder("location", latitude, longitude);
        distanceSortBuilder.unit(DistanceUnit.MILES);
        distanceSortBuilder.order(SortOrder.ASC);

        DisMaxQueryBuilder searchByParameterQueryBuilder = QueryBuilders.disMaxQuery();
        searchByParameterQueryBuilder.add(QueryBuilders.wildcardQuery(parameterType, "*" + searchParameter + "*"));

        System.out.println(parameterType + ": " + searchByParameterQueryBuilder);
        // System.out.println("");

        // Distance query
        QueryBuilder distanceQuery = new BoolQueryBuilder().must(QueryBuilders.geoDistanceQuery("location")
                .point(latitude, longitude).distance(distance, DistanceUnit.MILES)).must(searchByParameterQueryBuilder);

        // System.out.println("Distance query: " + distanceQuery);

        Query searchQuery = new NativeSearchQueryBuilder().withFilter(distanceQuery).withSort(distanceSortBuilder)
                .build();

        System.out.println("Search query: " + searchQuery);

        SearchHits<Elastic_Business_Service_Model> serviceHits = elasticsearchOperations.search(searchQuery,
                Elastic_Business_Service_Model.class, IndexCoordinates.of(Business_Service_Index));

我不知道我做错了什么。

I am working on elastic search in spring boot rest API. I am trying to add distance based query. I am getting following exception while running:

Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]

Following is my code:

// Geo distance
        GeoDistanceSortBuilder distanceSortBuilder = new GeoDistanceSortBuilder("location", latitude, longitude);
        distanceSortBuilder.unit(DistanceUnit.MILES);
        distanceSortBuilder.order(SortOrder.ASC);

        DisMaxQueryBuilder searchByParameterQueryBuilder = QueryBuilders.disMaxQuery();
        searchByParameterQueryBuilder.add(QueryBuilders.wildcardQuery(parameterType, "*" + searchParameter + "*"));

        System.out.println(parameterType + ": " + searchByParameterQueryBuilder);
        // System.out.println("");

        // Distance query
        QueryBuilder distanceQuery = new BoolQueryBuilder().must(QueryBuilders.geoDistanceQuery("location")
                .point(latitude, longitude).distance(distance, DistanceUnit.MILES)).must(searchByParameterQueryBuilder);

        // System.out.println("Distance query: " + distanceQuery);

        Query searchQuery = new NativeSearchQueryBuilder().withFilter(distanceQuery).withSort(distanceSortBuilder)
                .build();

        System.out.println("Search query: " + searchQuery);

        SearchHits<Elastic_Business_Service_Model> serviceHits = elasticsearchOperations.search(searchQuery,
                Elastic_Business_Service_Model.class, IndexCoordinates.of(Business_Service_Index));

I have no idea what I am doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文