Harshana Samaranayake
Harshana Samaranayake

Reputation: 504

How to insert Nested document in solr using spring data solr?

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 ?

Upvotes: 6

Views: 2558

Answers (1)

Sanjay Madnani
Sanjay Madnani

Reputation: 813

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

Upvotes: 4

Related Questions