一、背景
es查询报错:Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
详细错误:
出错了 [METHOD=GET URL=/api/v1/xxx/xxx PARAM=page=0&size=20&keywords=&propertyJson=&schoolIds=&stages=&subjects=
MSG=Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://192.168.80.71:9200], URI [/share_course_index/_doc/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=dfs_query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"No mapping found for [weight] in order to sort on","index_uuid":"hPGi_W40Tx-jFfcn8PZJ8Q","index":"share_course_index"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"share_course_index","node":"iRNxq8wnQ4CN1bHnoY9NLQ","reason":{"type":"query_shard_exception","reason":"No mapping found for [weight] in order to sort on","index_uuid":"hPGi_W40Tx-jFfcn8PZJ8Q","index":"share_course_index"}}]},"status":400}
二、错误原因
索引share_course_index缺乏字段weight,缺又对它进行了排序。
No mapping found for [weight] in order to sort on
修改前的代码:
List<Sort.Order> sortOrders = Lists.newArrayList(Sort.Order.desc("weight"), Sort.Order.desc("modifiedDate"));
修改后的代码:
List<Sort.Order> sortOrders = Lists.newArrayList(Sort.Order.desc("modifiedDate"));
去掉weight字段的排序即可。
(因为索引没有weight字段)
三、Kibana操作es索引
- 查看索引详情
GET /share_course_index/_mapping
- 新建es索引
PUT share_course_index
{
"mappings" : {
"_doc" : {
"properties" : {
"courseNo" : {
"type" : "keyword"
},
"createdDate" : {
"type" : "long"
},
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"modifiedDate" : {
"type" : "long"
},
"propertyItemIds" : {
"type" : "keyword"
},
"schoolIds" : {
"type" : "keyword"
},
"intro" : {
"type" : "text"
},
"createdBy" : {
"type" : "text"
},
"modifiedBy" : {
"type" : "text"
}
}
}
}
}
- 删除索引
DELETE /share_course_index
- 查询语句
GET /share_course_index/_search
{
"query": {
"multi_match": {
"query": "化学",
"fields": ["courseName", "courseNo"]
}
}
}