嵌套对象日期字段的Spring Data ES查询

时间:2017-05-08 06:37:29

标签: spring spring-data-elasticsearch

使用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唯一性,这最终只会是一条记录。

如何根据其属性?

限制嵌套元素的数据

0 个答案:

没有答案