我正在获取以下格式的XML,我希望使用SpringBoot将其索引到Solr中。但是,当我尝试使用Document
List
索引父ChildDocuments
时,我收到了异常。
XML -
<EmployeeMaster xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<Name>Empolyee1</Name>
<ID>1</ID>
<Department>
<Name>Department1</Name>
<ID>1</ID>
</Department>
<Department>
<Name>Department1</Name>
<ID>1</ID>
</Department>
</Employee>
</EmployeeMaster>
我有以下Entity
-
Employee.java
@Getter
@Setter
@SolrDocument(solrCoreName = "employee")
public class Employee implements IEmployee, Serializable {
@Id
@Field(ID_FIELD)
private String id;
@Field(NAME_FIELD)
private String name;
@Field(child = true)
private Collection<Department> departments;
@Field(ENTITY_TYPE_FIELD)
private String entityType;
public Employee(String id) {
this.id = "EMP_" + id;
this.entityType = "employee";
}
}
Deparment.java
@Getter
@Setter
@SolrDocument(solrCoreName = "employee")
public class Department implements IDepartment, Serializable {
@Id
@Field(ID_FIELD)
private String id;
@Field(NAME_FIELD)
private String name;
@Field(ENTITY_TYPE_FIELD)
private String entityType;
public Department(String id) {
this.id = "DEP_" + id;
this.entityType = "department";
}
}
当我尝试使用save
类中的SolrCrudRepository
方法将其保存到Solr时,我得到以下异常 -
Caused by: org.springframework.data.solr.UncategorizedSolrException: Error from server at http://localhost:8983/solr: ERROR: [doc=EMP_1] unknown field 'departments';
nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: ERROR: [doc=EMP_1] unknown field 'departments'
Repository
,EmployeeRepository
只是extends
SolrCrudRepository
的接口。
在我的Service
课程中,我从save
调用了EmployeeRepository
方法。
POM -
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
</dependencies>
Solr架构 -
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="_version_" type="long" indexed="true" stored="false"/>
<field name="id" type="string" multiValued="false" indexed="true" required="false" stored="true"/>
<field name="name" type="lower" multiValued="false" indexed="true" required="false" stored="true"/>
<field name="entity_type" type="string" multiValued="false" indexed="true" required="false" stored="true"/>