[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
现象
在做某一次用到elasticsearch的地位位置搜索时,报错:
ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
我使用的是GeoDistanceQueryBuilder进行ElasticSearch的地理位置搜索以及排序
排查
后来登录到elasticsearch的服务器上去查看错误日志,发现报错如下:
就是说我的location不是geo_point类型的,这个问题也是排查了好久。
问题的原因很简单,是因为我的index是通过IndexRequest自动创建的,会有问题。
例如:
String string = JSONObject.fromObject(entity).toString();IndexRequest indexRequest = new IndexRequest(INDEX).type(DOC).id(INDEX + "_" + entity.getId()).source(string, XContentType.JSON);bulkRequest.add(indexRequest);
解决
手工创建,或者通过Java代码创建索引都可以。一定注意,对应mapping的属性的类型一定是geo_point才行
- 这里我换了个索引,position表示位置信息
# 使用Java手工创建索引
public class CreateElsIndexMain {static final String INDEX_NAME = "t_els_mock";@Testpublic void test() throws Exception {RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1",9200,"http")));boolean exists = checkExists(client);if (exists) {deleteIndex(client);}createIndex(client);}public static boolean checkExists(RestHighLevelClient client) throws Exception {GetIndexRequest existsRequest = new GetIndexRequest();existsRequest.indices(INDEX_NAME);boolean exists = client.indices().exists(existsRequest, RequestOptions.DEFAULT);return exists;}public static void createIndex(RestHighLevelClient client) throws Exception {Settings.Builder setting = Settings.builder().put("number_of_shards", "5").put("number_of_replicas", 1);XContentBuilder mappings = JsonXContent.contentBuilder().startObject().startObject("properties").startObject("id").field("type", "text").endObject().startObject("name").field("type", "keyword").endObject().startObject("createTime").field("type", "keyword").endObject().startObject("score").field("type","keyword").endObject().startObject("longitude").field("type","float").endObject().startObject("latitude").field("type","float").endObject().startObject("position").field("type","geo_point").endObject().endObject().endObject();CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME).settings(setting).mapping("doc",mappings);CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);System.out.println(createIndexResponse);}public static void deleteIndex(RestHighLevelClient client) throws Exception {DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest();//删除索引同样要创建对象接受索引名deleteIndexRequest.indices(INDEX_NAME);//传递索引名//执行delete方法进行删除;AcknowledgedResponse delete = client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);}}
Kibana数据
我们可以使用测试数据,将数据放到es中,通过kibana的dev tools查看该索引的数据,如下示例:
添加数据到es的代码
@Autowiredprivate RestHighLevelClient client;private static final String INDEX = "t_els_mock";String DOC = "doc";public void addData(){BulkRequest bulkRequest = new BulkRequest();List<MockLocationEntity> entities = getEntities();for (MockLocationEntity entity : entities){String string = JSONObject.fromObject(entity).toString();IndexRequest indexRequest = new IndexRequest(INDEX).type(DOC).id(INDEX + "_" + entity.getId()).source(string, XContentType.JSON);bulkRequest.add(indexRequest);}try {BulkResponse bulk = client.bulk(bulkRequest, RequestOptions.DEFAULT);} catch (IOException e) {}}private static List<MockLocationEntity> getEntities(){List<MockLocationEntity> list = new ArrayList<>();MockLocationEntity one = new MockLocationEntity();one.setId(UUID.randomUUID().toString());one.setName("YuanYan GuoJi");one.setScore("10");one.setCreateTime("20220322145900");one.setLongitude(117.20);one.setLatitude(38.14);one.setPosition(one.getLatitude() + "," +one.getLongitude());MockLocationEntity two = new MockLocationEntity();two.setId(UUID.randomUUID().toString());two.setName("WenGuang DaSha");two.setScore("9");two.setCreateTime("20220322171100");two.setLongitude(116.01);two.setLatitude(38.89);two.setPosition(two.getLatitude() + "," +two.getLongitude());MockLocationEntity three = new MockLocationEntity();three.setId(UUID.randomUUID().toString());three.setName("NeiMengGu JiuDian");three.setScore("8");three.setCreateTime("20220322171101");three.setLongitude(117.99);three.setLatitude(39.24);three.setPosition(three.getLatitude() + "," +three.getLongitude());MockLocationEntity four = new MockLocationEntity();four.setId(UUID.randomUUID().toString());four.setName("GuoXianSheng");four.setScore("10");four.setCreateTime("20220322171102");four.setLongitude(117.20);four.setLatitude(39.50);four.setPosition(four.getLatitude() + "," +four.getLongitude());Location fourLocation = new Location();MockLocationEntity five = new MockLocationEntity();five.setId(UUID.randomUUID().toString());five.setName("NongYe YinHang");five.setScore("8");five.setCreateTime("20220322171103");five.setLongitude(116.89);five.setLatitude(39.90);five.setPosition(five.getLatitude() + "," +five.getLongitude());Location fiveLocation = new Location();MockLocationEntity six = new MockLocationEntity();six.setId(UUID.randomUUID().toString());six.setName("XingBaKe");six.setScore("9");six.setCreateTime("20220322171104");six.setLongitude(117.25);six.setLatitude(39.15);six.setPosition(six.getLatitude() + "," +six.getLongitude());MockLocationEntity seven = new MockLocationEntity();seven.setId(UUID.randomUUID().toString());seven.setName("JuFuYuan");seven.setScore("6");seven.setCreateTime("20220322171104");seven.setLongitude(117.30);seven.setLatitude(39.18);seven.setPosition(seven.getLatitude() + "," +seven.getLongitude());list.add(one);list.add(two);list.add(three);list.add(four);list.add(five);list.add(six);list.add(seven);return list;}
[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]相关推荐
- 解决Elasticsearch报错:exception [type=search_phase_execution_exception, reason=all shards failed]
关于exception [type=search_phase_execution_exception, reason=all shards failed]这个es错误我是如何解决的! 由于服务器性能不 ...
- ES使用聚合查询报错exception [type=search_phase_execution_exception, reason=all shards failed]
首先看聚合查询写的代码 聚合查询 使用的是tags这个字段分组查询,使用term查询. term查询的话必须查询的字段是keyword类型,而且在java代码后面需要加入.keyword. text是 ...
- Elasticsearch exception [type=action_request_validation_exception, reason=Validation Failed:
Elasticsearch exception [type=action_request_validation_exception, reason=Validation Failed: type已经显 ...
- ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=Unknow
这种多半是配置或者插件不对 ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, ...
- Elasticsearch exception [type=circuit_breaking_exception, reason=[parent] Data too large, data
以上异常原因是field data 的缓存不够用. 修改方法,向Elasticsearch发送如下请求,设置fielddata缓存占用jvm内存的30%或者更小: 之后再发送请求即可成功.
- ElasticsearchStatusException[Elasticsearch exception [type=circuit_breaking_exception, reason=[paren
出现环境 在测试向ES中导入数据时发生数据超出大小异常 报错详情 报错原因 分配给ES的的内存空间太小了 修改docker-compose.yml配置文件 把内存调高 修改后重新运行 运行结果 导入数 ...
- Elasticsearch 7.2.0 搜索时报 all shards failed 错误
问题描述: 通过ElasticSearch搜索时,当搜索的内容过长(大概25个汉字以上)时,会莫名其妙的报错,Elasticsearch exception [type=search_phase_ex ...
- ES 查询时提示:all shards failed [type=search_phase_execution_exception]
我的情况和解决方案 这种错误大概率是 ES 的查询语句语法错误,比如我当时是,时间筛选的条件的格式写错了,导致 ES 查询时解析错误,从而报了all shards failed [type=searc ...
- ElasticSearch创建索引:[hotel/6g9tufKRuWDdWfgE_F30Q] ElasticsearchStatusException[Elasticsearch exception
报错: [hotel/hxWlZTdjTuKaC8m2uzj_JQ] ElasticsearchStatusException[Elasticsearch exception [type=resour ...
最新文章
- 2017年中国人工智能产业最全研究报告发布 | AI世界2018年八大趋势
- 【238】◀▶IEW-Unit03
- SDWebImage的使用及图片不改变问题的解决
- 【Spring】- Bean生命周期
- 使用摄像头运行ORB SLAM2---使用视频运行ORB-SLAM2
- 【复杂系统迁移 .NET Core平台系列】之认证和授权
- vue 全家桶 - 前端工程化
- 借助xUnit减少了生产问题
- 《java入门第一季》之类面试题
- 推荐常用的小程序Ui框架
- yolo5纸张卡片顶点检测,实现任意倾斜角度较正
- API接口通讯参数规范(2)
- iOS CoreData (二) 版本升级和数据库迁移
- windwos::mutex
- mi自学站【2018年8月】
- matlab在有限差分法中的应用,MATLAB在有限差分法中的应用
- Visual Studio中更改项目名称
- vue vue-element-ui组件 eltable 表头背景颜色
- Kettle 9.0 源码编译
- throw语句以及throw “error“ 和 throw new Error(“error“)的区别
热门文章
- 保护您的眼睛 用淡苹果绿的IE背景色
- “考试包过”?买考研真题答案?买“内部资料”?这些都是谣言!
- 0510 人力资本、制度与环境 by香港城市大学能源及环境学院张林博士
- 黑客与画家特别值得记录的
- 中国最美的一千个汉字 : 千字文2
- 2022年最新《谷粒商城开发教程》:2 - vue 简要笔记
- IM开发之即时通讯服务器Ejabberd的介绍和搭建
- 为高尔夫比赛砍树2022-05-23每日一题 hard
- 独立站运营 | 除了TIDIO,还有哪些WooCommerce聊天机器人推荐?
- iphone死机屏幕没反应?可以用这2种办法解决!