es查询报错Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]

一、背景

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"]
    }
  }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天草二十六_简村人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值