简体   繁体   English

想在 springboot 应用程序中创建嵌套数组 elasticsearch 的子字段

[英]want to create subfields of nested array elasticsearch in springboot application

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现在我想在 springboot 应用程序中使用这些字段创建 feed class 我如何在 springboot 应用程序中使用此映射将评论字段的子字段初始化为嵌套数组我已经这样做了但不知道如何初始化评论的子字段并将评论初始化为嵌套类型是 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我不知道如何初始化评论字段的子字段,因为我是初学者,我正在使用 elasticsearch 7.17.3

You can create a Comment class like this:您可以像这样创建Comment class:

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:而不是使用private String[] comment ,你应该使用:

@Field(type= FieldType.Nested , name="comment")
private List<Comment> comment;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM