ฉันค่อนข้างใหม่ที่จะต้อง ElasticSearch. ฉันทำงานให้โครงการอยู่ไหนเราต้องค้นหาสำหรับวัตถุ(ข้อเสนอ)นั้นมีส่วนตั้งสอง(OfferTranslation). เป้าหมายคือทำให้งานวิจัยพื้นฐานบางอย่างของช่องข้อมูลข้อเสนอแต่ยังเป็นมากมาย OfferTranslation ฟิลด์ นี่คือ minified เวอร์ชั่นของทั้งสองเรียน:
Offer.class (โปรดสังเกตว่าฉัน annotated รตั้งค่ากับ@สนาม(ประเภท=FieldType.รอบการ)ดังนั้นฉันสามารถทำให้รอบการค้นข้อมูลอย่างที่ mentionned ในห้อย่างเป็นทางการหมอ) :
@org.springframework.data.elasticsearch.annotations.Document(indexName = "offer")
@DynamicMapping(DynamicMappingValue.False)
public class Offer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@Field(type = FieldType.Long)
private Long id;
@OneToMany(mappedBy = "offer", targetEntity = OfferTranslation.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(
value = { "pictures", "videos", "owner", "contexts", "offer", "personOfInterests", "followers" },
allowSetters = true
)
@Field(type = FieldType.Nested, store = true)
private Set<OfferTranslation> offersTranslations = new HashSet<>();
}
OfferTranslation.class :
@DynamicMapping(DynamicMappingValue.False)
public class OfferTranslation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@Field(type = FieldType.Long)
private Long id;
@NotNull
@Size(max = 100)
@Column(name = "title", length = 100, nullable = false)
@Field(type = FieldType.Text)
private String title;
@NotNull
@Size(max = 2000)
@Column(name = "summary", length = 2000, nullable = false)
@Field(type = FieldType.Text)
private String summary;
@Size(max = 2000)
@Column(name = "competitor_context", length = 2000)
@Field(type = FieldType.Text)
private String competitorContext;
@NotNull
@Size(max = 2000)
@Column(name = "description", length = 2000, nullable = false)
@Field(type = FieldType.Text)
private String description;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "maturity", nullable = false)
@Field(type = FieldType.Auto)
private RefMaturity maturity;
@ManyToOne
@Field(type = FieldType.Object, store = true)
private RefLanguage language;
@NotNull
@Column(name = "created_at", nullable = false)
@Field(type = FieldType.Date)
private Instant createdAt;
}
ที่คาดหวังพฤติกรรมเป็นเรื่องฉันสามารถทำให้ nestedQueries ที่แล้ว:
QueryBuilder qBuilder = nestedQuery("offersTranslations",boolQuery().must(termQuery("offersTranslations.language.code",language)), ScoreMode.None);
แต่สิ่งที่ฉันได้มันเป็นข้อยกเว้น:ล้มเหลวในการสร้างกับการค้นหา:[รอบการ]รอบการวัตถุอยู่ใต้เส้นทา[offersTranslations]ไม่ใช่ของรอบการประเภท"
แก้ไข:ฉันสามารถเข้าถึง offersTranslations.ภาษาสินะรหัสโดยใช้ปกติค้นข้อมูล(ซึ่งไม่รบกวนฉันตอนนี้). แต่ฉันยังไม่เข้าใจ
ฉันวางแผนจะบอกว่าสนาม offersTranslations ไม่ใช่ของครอบการประเภทอย่างที่คุณเห็นด้านบนแต่ตั้งแต่ฉันเคย@สนาม(ประเภท=FieldType.รอบการ)ฉันไม่เข้าใจพฤติกรรม เป็นไปได้มั้ยที่ใครบางคนจะได้อธิบายเหรอ?
{
"offer" : {
"mappings" : {
"properties" : {
"_class" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"categories" : {
"properties" : {
"id" : {
"type" : "long"
}
}
},
"criteria" : {
"properties" : {
"id" : {
"type" : "long"
}
}
},
"id" : {
"type" : "long"
},
"keywords" : {
"properties" : {
"id" : {
"type" : "long"
}
}
},
"offersTranslations" : {
"properties" : {
"competitorContext" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"createdAt" : {
"type" : "date"
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "long"
},
"language" : {
"properties" : {
"code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"maturity" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"state" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"summary" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"updatedAt" : {
"type" : "date"
}
}
},
"units" : {
"properties" : {
"id" : {
"type" : "long"
}
}
}
}
}
}
}