Spring Boot Solr:子文档的索引列表

时间:2017-11-24 14:29:21

标签: java spring spring-boot solr spring-data-solr

我正在获取以下格式的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'

RepositoryEmployeeRepository只是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"/>

0 个答案:

没有答案