1

I am trying to persist nested documents in solr. I have tried both Field(child= true) and @Childdocument annotation.

With @Field(child=true) & @ChildDocument i get

[doc=null] missing required field: id, retry=0 commError=false errorCode=400

I tried @Indexed with @Id. Also tried to specify required = false.

@Service
public class NavigationMapper implements DocumentMapper<Navigation> {
    @Override
    public SchemaDefinition getSchemaDefinition() {
        SchemaDefinition sd = new SchemaDefinition();
        sd.setName(Navigation.class.getSimpleName());
        sd.setFields(new ArrayList<>());


        for(Method method : Navigation.class.getDeclaredMethods()){
            if(method.getName().startsWith("get") && method.getParameterCount() <= 0){
                SchemaDefinition.FieldDefinition fd = new SchemaDefinition.FieldDefinition();
                String fieldName = method.getName().replace("get", "");

                fd.setName(fieldName.replace(fieldName.charAt(0), fieldName.toLowerCase().charAt(0)));
                fd.setRequired(false);
                fd.setStored(true);
                sd.getFields().add(fd);
            }
        }
        return sd;
    }

With @Field i get the package name in the stored value : activePage:

["org.apache.solr.common.SolrInputField:activePage=Page(id=blt6134c9cf711a7c27,

and get below error while i try to read in my rest controller.

No converter found capable of converting from type [java.lang.String] to type [com.blizzard.documentation.data.shared.model.page.Page]

I did a lot of reading about this and haven't been able to successfully configure and persist the nested document in SolrDb. I read that i could use SolrJConverter for this , but not sucessfull with it either. Is there any working example i can refer to or tutorial about this feature?

@Data
@SolrDocument(collection = "Navigation")
public class Navigation implements Serializable {


    @Id
    //@Indexed(required = false)
    private String id;

    @Field
    @Indexed(name = "path", type = "string")
    private String path;


    @ChildDocument
    private Page navigationRoot;

    @ChildDocument
    private Page activePage;
}

@Data
@SolrDocument(collection = "Page")
public class Page implements Serializable {


    @Id
   // @Indexed(name= "id", type="string", required = false)
    private String id;

    @Field
    @Indexed(name= "path", type="string")
    private String path;


    @Field
    private PageContentType contentType;


    @ChildDocument
    private List<Page> children;


    @Indexed("root_b")
    private boolean root;

}

I expect to store the nested document inthe solrDb.

JSmith
  • 4,519
  • 4
  • 29
  • 45
osunanda
  • 11
  • 1

0 Answers0