如何使用 spring 数据 solr 在 solr 中插入嵌套文档?
How to insert Nested document in solr using spring data solr?
我需要将这种数据插入到solr服务器。
{
"id":"09123"
"firstName": "Harshana651175279",
"lastName": "Samaranayake332146645",
"department": {
"id":"001",
"depName":"dep01"
}
}
这些是我用于插入数据的 POJO。
public class SolrCustomer {
@Id
@Indexed
private String id;
@Field
@Indexed
private String firstName;
@Field
@Indexed
private String lastName;
@Field
private Department department;
//getters n setters
}
public class Department {
@Id
@Indexed
private String id;
@Field
@Indexed
private String departmentName;
//getters n setters
}
没有部门数据它工作正常。但不能作为嵌套文档插入。当我尝试它时,就像这样插入
{
"firstName": "Harshana651175279",
"lastName": "Samaranayake332146645",
"department": [
"org.ftm.solr.domain.Department@479c1814"
],
"id": "2e204ab3-772d-4af1-a2be-866e21206ecd",
"_version_": 1536317096485453800
}
这是我为此配置的架构。
<field name="department" type="strings" multiValued="true"/>
<field name="firstName" type="strings" multiValued="false"/>
<field name="id" type="string" indexed="true" required="true" stored="true"/>
<field name="lastName" type="strings" multiValued="false"/>
那么我如何将这些嵌套文档与 solr n spring data solr 一起使用?
是的,您可以插入嵌套文档,检查以下问题的答案:
我需要将这种数据插入到solr服务器。
{
"id":"09123"
"firstName": "Harshana651175279",
"lastName": "Samaranayake332146645",
"department": {
"id":"001",
"depName":"dep01"
}
}
这些是我用于插入数据的 POJO。
public class SolrCustomer {
@Id
@Indexed
private String id;
@Field
@Indexed
private String firstName;
@Field
@Indexed
private String lastName;
@Field
private Department department;
//getters n setters
}
public class Department {
@Id
@Indexed
private String id;
@Field
@Indexed
private String departmentName;
//getters n setters
}
没有部门数据它工作正常。但不能作为嵌套文档插入。当我尝试它时,就像这样插入
{
"firstName": "Harshana651175279",
"lastName": "Samaranayake332146645",
"department": [
"org.ftm.solr.domain.Department@479c1814"
],
"id": "2e204ab3-772d-4af1-a2be-866e21206ecd",
"_version_": 1536317096485453800
}
这是我为此配置的架构。
<field name="department" type="strings" multiValued="true"/>
<field name="firstName" type="strings" multiValued="false"/>
<field name="id" type="string" indexed="true" required="true" stored="true"/>
<field name="lastName" type="strings" multiValued="false"/>
那么我如何将这些嵌套文档与 solr n spring data solr 一起使用?
是的,您可以插入嵌套文档,检查以下问题的答案: