索引嵌入式实体的正确方法?

时间:2019-06-12 01:44:36

标签: jhipster

我在JHipster(库存)中有一个实体,而不包含另一个实体(InventoryModel)。这两个实体在每个类的顶部均配置为具有各自的索引,但是我希望可以在父实体中搜索嵌入式实体字段。

例如我希望能够在库存索引中搜索嵌入式的stock.inventoryModel.name


/**
 * A InventoryModel.
 */
@Entity
@Table(name = "inventory_model")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@org.springframework.data.elasticsearch.annotations.Document(indexName = "inventorymodel")
public class InventoryModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Keyword)
    private Long id;

    @NotNull
    @Size(max = 20)
    @Column(name = "name", length = 20, nullable = false, unique = true)
    private String name;

    @Enumerated(EnumType.STRING)
    @Column(name = "vehicle_type")
    private VehicleType vehicleType;

    @Column(name = "jhi_desc")
    private String desc;

    @ManyToOne(optional = false)
    @NotNull
    @JsonIgnoreProperties("inventoryModels")
    private Make make;

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

    ///
}



/**
 * A Inventory.
 */
@Entity
@Table(name = "inventory")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@org.springframework.data.elasticsearch.annotations.Document(indexName = "inventory")
public class Inventory implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Keyword)
    private Long id;

    @NotNull
    @Size(max = 17)
    @Column(name = "vin", length = 17, nullable = false, unique = true)
    private String vin;

    @Min(value = 1900)
    @Max(value = 2050)
    @Column(name = "year")
    private Integer year;

    @Column(name = "color")
    private String color;

    @Size(max = 128)
    @Column(name = "comment", length = 128)
    private String comment;

    @ManyToOne(optional = false)
    @NotNull
    @JsonIgnoreProperties("inventories")
    @org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Nested, includeInParent=true, index=true)
    private InventoryModel inventoryModel;

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    ///
}

在inventoryModel.name中,您会注意到“字段”批注:

@ManyToOne(optional = false)
    @NotNull
    @JsonIgnoreProperties("inventories")
    @org.springframework.data.elasticsearch.annotations.Field(type = FieldType.Nested, includeInParent=true, index=true)
    private InventoryModel inventoryModel;

无论如何似乎都行不通,有什么主意吗?

0 个答案:

没有答案