使用Spring Data ES
。
我有一个名为ship
的索引,其定义如下:
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Document(indexName = "ship", type = "journey")
public class ShipJourney {
@Id
private String shipId;
@Field(type = FieldType.Nested)
private List<ShipLocation> shipLocation;
//getters and setters
}
ShipLocation
是一个嵌套对象,定义为:
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.time.LocalDateTime;
public class ShipLocation {
private double latitude;
private double longitude;
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime recordedOnTime;
//setters and getters
}
我想在LocalDateTime
参数之前或之前找到一个发货地点。
我试过了:
ShipJourney findTopByShipIdAndShipLocationRecordedOnTimeLessThanOrderByShipLocationRecordedOnTimeDesc(
String shipId, LocalDateTime recordedOnTime);
后来才意识到我在Top
本身上使用ShipJourney
,由于shipId's
唯一性,这最终只会是一条记录。
如何根据其属性?
限制嵌套元素的数据