首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring Data Elasticsearch?

Spring Data Elasticsearch?

提问于 2020-08-17 11:16:45
回答 0关注 0查看 128

前提:

es6.7+Spring Data Elasticsearch3.8.2

po

代码语言:javascript
复制
@Data
@Document(indexName = "test_index")
public class PersonPO implements Serializable {

    @Id
    private Long id;

    @Field(store = true, analyzer = "ik_smart", searchAnalyzer = "ik_smart", type = FieldType.Text)
    private String name;

    @Field(store = true, analyzer = "ik_smart", searchAnalyzer = "ik_smart", type = FieldType.Text)
    private String address;

    @Field(store = true, type = FieldType.Text)
    private String sex;

    @Field(store = true, type = FieldType.Text)
    private String email;

    @Field(store = true, type = FieldType.Date)
    private LocalDateTime birthDay;

    @Field(store = true, type = FieldType.Integer)
    private Integer sort;

//    @Parent(type = "text")
//    private String personId;

}

问题:

1、save方法返回的对象没有主键

public interface PersonRepository extends ElasticsearchRepository<PersonPO, Long> { }

代码语言:javascript
复制
PersonPO personPO = new PersonPO();
personPO.setName("天才");
personPO.setSex("男");
personPO.setAddress("中国浙江省杭州市萧山区"+new Random().nextLong());
personPO.setBirthDay(LocalDateTime.now());
personPO.setEmail(new Random().nextLong() +"@qq.com");
personPO.setSort(new Random().nextInt()%39);
PersonPO save = personRepository.save(personPO);
System.out.println(save);

返回的数据

PersonPO(id=null, name=天才, address=中国浙江省杭州市萧山区8144708322016118683, sex=男, email=-8489652585446092083@qq.com, birthDay=2020-08-17T11:00:56.833, sort=-37)

2、父子查询使用@Parent不行,应该怎么使用

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档