How to insert Nested document in solr using spring data solr?
Asked Answered
I

1

6

I need to insert this kind data to solr server.

{
    "id":"09123"
    "firstName": "Harshana651175279",
    "lastName": "Samaranayake332146645",
    "department": {
            "id":"001",
            "depName":"dep01"        
        }
}

These are the my POJOs for inserting data.

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
}

without deparment data its working fine. But can't insert as nested document. When i try it, inserted just like this

{
    "firstName": "Harshana651175279",
    "lastName": "Samaranayake332146645",
    "department": [
        "org.ftm.solr.domain.Department@479c1814"
    ],
    "id": "2e204ab3-772d-4af1-a2be-866e21206ecd",
    "_version_": 1536317096485453800
}

and this is my schema configured for this.

<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"/>

So how can i use these kind of nested document with solr n spring data solr ?

Instancy answered 5/6, 2016 at 17:29 Comment(1)
You cannot use the nested documents in SOLR. It needs to fatten before you push the document into SOLR. For Reference : https://qnalist.com/questions/4775755/how-to-write-nested-schema-xml-in-solrAuricula
H
4

Yes you can insert nested document, Check the answer of below question: SOLRJ-6.0.0: Insertion of a bean object which associate list of bean object is giving null pointer exception

Hypsography answered 7/6, 2016 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.