Elasticsearch数据库all shards failed
@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "EsRoundVo", description = "es根据圆形区域查询车辆实时数据请求参数")
public class EsRoundVo extends EsIndexTypeVo{
@ApiModelProperty(name = "latitude", value = " 纬度", required = true)
@NotNull(message = "纬度不能为空!")
@DoubleRange(min = -90D, max = 90D, message = "纬度值应在 -90 到 90 之间!")
private Double latitude;
@ApiModelProperty(name = "longitude", value = "经度", required = true)
@NotNull(message = " 经度不能为空!")
@DoubleRange(min = -180D, max = 180D, message = "经度值应在 -180 到 180 之间!")
private Double longitude;
@ApiModelProperty(name = "radius", value = "半径", required = true)
@NotNull(message = "半径不能为空")
@Min(value = 0, message = "半径不能为负!")
private Double radius;
@ApiModelProperty(name = "radiusUnit", value = "半径单位,in,yd,ft,km,NM,mm,cm,mi,m", required = true)
@NotEmpty(message = "半径单位不能为空!")
@EnumValueScope(scope = AccessConstant.RadiusEnum.class, message = "半径单位不在取值范围内!")
private String radiusUnit;
@ApiModelProperty(name = "includes", value = "可选展示字段,不填默认全字段,所有es字段皆可选")
private String[] includes;
@ApiModelProperty(name = "offset", value = "偏移量,默认为0")
private int offset = 0;
@ApiModelProperty(name = "pageSize", value = "每页数量,默认为10")
@Min(value = 1, message = "每页数量最小为1!")
@Max(value = 1000, message = "每页数量最大为1000!")
private int pageSize = 10;
}
public EsResultVo getCircle(EsRoundVo esRound){
try {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.geoDistanceQuery(LOCATION.getValue())
.point(esRound.getLatitude(), esRound.getLongitude())
.distance(esRound.getRadius(), DistanceUnit.fromString(esRound.getRadiusUnit())));
SearchRequestBuilder requestBuilder = elasticsearchClient.prepareSearch(esRound.getIndex())
.setTypes(esRound.getType())
.setFetchSource(esRound.getIncludes(), null)
.setQuery(queryBuilder)
.setFrom(esRound.getOffset())
.setSize(esRound.getPageSize());
SearchHits searchHits = requestBuilder.get().getHits();
List<Object> res = Stream.of(searchHits.getHits()).map(SearchHit::getSource).collect(Collectors.toList());
return EsResultVo.format(res, esRound.getOffset(), esRound.getPageSize(), searchHits.getTotalHits());
}catch (Exception e){
log.error("es接口有误",e);
throw IotServerException.create(THIRD_PARTY_API_REQUEST_ERROR, e.getMessage());
}
}