nafas
nafas

Reputation: 5423

adding document to solr 4.5.1 with java

I'm trying to add the following document to solr

{
  "id":"myId",
  "parent": "Alice",
  "children":["adam","eva"]
}

I'm getting this Exception :

Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: ERROR: [doc=5f783ce04e8c21c705db52eca6ae72bb] unknown field 'parent' at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:425) at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:180) at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117) at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116) at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:102) at xxxx.xxx.addToSolr(Download.java:660) at xxxx.xxx.main(Download.java:460)

This is my code:

public static void addToSolr(String parent, JSONArray children) throws Exception {

    HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:8983/solr/knowledgebase/");

    String id = DigestUtils.md5Hex(parent);

    SolrInputDocument document = new SolrInputDocument();

    document.addField("id", id);
    document.addField("parent", parent);
    document.addField("children", children);

    server.add(document);
    server.commit();

}

I'm using solr 4.5.1.

What is this unknown field mean? Do I need to add something to solr schema or config file or have I made stupid error with my java code?

Upvotes: 0

Views: 147

Answers (1)

AR1
AR1

Reputation: 5005

The error:

unknown field 'parent'

normally means that you don't have a field called parent in your schema.xml. The solution is very simple and consists in adding such field.

 

Upvotes: 1

Related Questions