POST feeds/_doc
{
"feed_id": "3",
"title": "jose ",
"body": "This is Jose allen",
"comment": [
{
"c_id": "13",
"feed_id": "2",
"c_text": "hey"
},
{
"c_id": "13",
"feed_id": "3",
"c_text": " here"
}
]
}
this is the mapping
PUT feeds
{
"mappings": {
"properties": {
"comment":{
"type": "nested"
}
}
}
}
Now i want to create the feed class in springboot application with these fields how can i intialize subfields of comment field as nested array with this mapping in springboot application i have done this but dont know how i can intialize subfileds of comment and intializing comment as nested type is right approch to intiliaze
@Document(indexName = "feeds")
public class Feed {
@Id
private String feed_id;
@Field(type = FieldType.Text, name = "title")
private String title;
@Field(type = FieldType.Text, name = "body")
private String body;
@Field(type= FieldType.Nested , name="comment")
private String[] comment;
}
i dont know how to intialize subfields of comment field as i am begineer i am using elasticsearch 7.17.3
CodePudding user response:
You can create a Comment
class like this:
public class Comment {
@JsonProperty("c_id")
private String cId;
@JsonProperty("feed_id")
private String feedId;
@JsonProperty("c_text")
private String cText;
// Getters, setters, ...
}
and instead of using private String[] comment
, you should use:
@Field(type= FieldType.Nested , name="comment")
private List<Comment> comment;