Search code examples
hibernatespring-bootsolrj

SolrJ POJO Annotations


This question is related to SolrJ document as a bean. I have an entity that has another entity within it. Could you please tell me how to annotate for inner entities? The issue I am facing is the inner entities fields are missing while indexing. In the below example, It is just adding Content fields and missing out author name and id.

Example: "Content" is one class that has "Author" as its has-a relationship entity.

class Content{ 

@Field("uniqueId") 
String id; 

@Field("timeStamp") 
Long timeStamp; 

//What should be the annotation type for this entity? 
Author author; 
} 

class Author{ 
@Field("authorName") 
String authorName; 

@Field("authorId") 
String id; 

} 

My schema xml is:

<field name="uniqueId" type="string" /> 
<field name="timeStamp" type="long" /> 
<field name="authorName" type="string" /> 
<field name="authorId" type="string" /> 

Solution

  • According to SOLR-1945 this is possible since Solr 5.1, by using the child property on the @Field annotation, as you can see in the Java docs.

    In your case it would be:

    class Content { 
        @Field("uniqueId") 
        String id; 
    
        @Field("timeStamp") 
        Long timeStamp; 
    
        @Field(child = true) // You should use this annotation
        Author author; 
    }
    
    
    
    class Author { 
        @Field("authorName") 
        String authorName; 
    
        @Field("authorId") 
        String id; 
    }