我想使用spring数据elasticsearch将elasticsearch文档映射到对象。我的文档包含嵌套对象,但是当我映射它们时,我得到一个空值。
这是我的存储库:
public interface DocumentRepository extends ElasticsearchRepository<Document,String> {
@Query("{\"bool\": {\"must\": [{\"term\": {\"content.content.page\":" +
" \"item\"}}]}}")
List<Document> getDocumentName(String keyWord, Pageable pageable);
} 这是我的文档:
@Getter
@Setter
@org.springframework.data.elasticsearch.annotations.Document(indexName = "non_omega_scoped",type = "documents")
public class Document {
@Id
private String id;
private String content;
private Metadata metadata;
private String scope;
private String filename;
public Document() {
}
public Document(String id, Metadata metadata, String filename) {
this.id = id;
this.metadata = metadata;
this.filename = filename;
}
public String getContent() {
return content;
}
主要方法:
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private ElasticsearchOperations es;
@Autowired
DocumentRepository documentRepository;
public static void main(String args[]) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
List<Document> documents=documentRepository.getDocumentName("",new PageRequest(0,10));
documents.forEach(
(document)-> {
System.err.println(document.getId());
System.err.println(document.getFilename());
System.err.println(document.getScope());
System.err.println(document.getMetadata().getYoaNumber());
}
);
}
输出为:
AWWGLKG1r_fC1ssn9Hht
/UW/AH/Policies/C001510K17A/TaxonomyList.xlsx
SGPC
null