मैं कर रहा हूँ काफी नए ElasticSearch करने के लिए. मैं काम कर रहा हूँ एक परियोजना पर जहां हम खोज करने की जरूरत के लिए एक वस्तु (प्रस्ताव) में शामिल है कि एक सेट के दो (OfferTranslation). लक्ष्य बनाने के लिए है के आधार पर अनुसंधान के कुछ क्षेत्रों की पेशकश, लेकिन यह भी की एक बहुत कुछ OfferTranslation क्षेत्रों. यहाँ एक minified संस्करण के दोनों वर्गों :
Offer.class (ध्यान दें कि मैं एनोटेट सेट के साथ @क्षेत्र(प्रकार= 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"
}
}
}
}
}
}
}