spring-projects/spring-data-examples

Spring Data Elasticsearch

yangdehong opened this issue · 2 comments

use:es6.7+Spring Data Elasticsearch3.8.2

entity:
@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、why methon save can not return primary
public interface PersonRepository extends ElasticsearchRepository<PersonPO, Long> {
}

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);

return data
PersonPO(id=null, name=123, address=123, sex=1, email=-8489652585446092083@qq.com, birthDay=2020-08-17T11:00:56.833, sort=-37)

2、how to search parent-child

I am beginner to open source,
According to me in this scenario either we have to add @GeneratedValue annotation with primary key or set the value of primary key like "personPo.setId(1212)".

This issue tracker is for bugs and feature requests of spring-data-examples. For general support of Spring Data please post your question on Stack Overflow.