记一次Elasticsearch查询报错

来源:互联网 发布:极限挑战电影 知乎 编辑:程序博客网 时间:2024/06/03 20:55

记一次Elasticsearch异常:

  • 异常:org.elasticsearch.search.SearchParseException: No mapping found for [id] in order to sort on

  • 出现场景:Elasticsearch库中无数据时,带过滤条件查询。

  • 原因查找:

    It only happens the first time, when you have no data, so this entity is not indexed yet by ElasticsearchMaybe we can try to catch the error, but it should not happened when you have data.In production, it should be already indexed, so there are no issue in prod
  • 解决方式:捕捉并处理异常

  • 代码:

    @ControllerAdvice  public class ExceptionHandlerAdvice {    @ExceptionHandler(value = SearchParseException.class)public ResponseEntity searchParseException(SearchParseException e){    String content = e.getCause().getMessage();    Msg msg = new Msg<String>(MessageType.MSG_TYPE_FAILURE,content,null);    return new ResponseEntity(msg, HttpStatus.OK);    }}
原创粉丝点击