0
votes

when Iam posting json object to apache solr 6 while indexing through java code Iam getting error as below:

the error message is as below:

"{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.common.SolrException"],"msg":"[doc=null] missing required field: id","code":400}}"

and my json object is as below:

"_childDocuments_" :[    
    {
      "entityname": "ReportDuplicate"
    }
  ],
"_childDocuments_" :[    
    {
      "entityname": "LinkedReport"
    }
  ],    

"_childDocuments_" :[    
    {
      "entityname": "Source"
    }
  ],
"_childDocuments_" :[
    {
      "entityname": "Literature",
"_childDocuments_" :[
        {
          "entityname": "Authors"
        }
      ]
    }
  ],
"_childDocuments_" :[

    {
      "entityname": "AdditionalInformation"
    }
  ],

And my java code to post the json object is as below:

org.apache.http.client.HttpClient client = HttpClientBuilder.create().build();

                HttpPost post = new HttpPost("http://localhost:8983/solr/icsr/update/json?wt=json&commit=true");
                StringEntity entity  = new StringEntity("{\"add\": { \"doc\":"+value+" }}", "UTF-8");

                entity.setContentType("application/json");
                post.setEntity(entity);                
                HttpResponse response = client.execute(post);
                HttpEntity httpEntity = response.getEntity();
                InputStream in = httpEntity.getContent();

                String encoding = httpEntity.getContentEncoding() == null ? "UTF-8" : httpEntity.getContentEncoding().getName();
                encoding = encoding == null ? "UTF-8" : encoding;
                String responseText = IOUtils.toString(in, encoding);
                System.out.println("response Text is " + responseText);

Im using solr 6 server to index the data from java code : As im geeting bad HTTP request while debugging and Im new to solr, And no changes are done in managed-schema.xml file : thansk in advance

2

2 Answers

0
votes

Check your schema.xml file . There must be a declaration like

<field name="id" type="string" multiValued="false" required="true" stored="true"/>

You have may be set required=true , while indexing a document either provide its id also, or just make required=false , it will 100% work !! Let me know if it helps you.

0
votes

Solr always accept date in format 2016-06-20T14:54:27.734Z (it is an example) . Send date only in this kind of format YYYY-MM-DDThh:mm:ssZ , where

YYYY is the year. MM is the month. DD is the day of the month. hh is the hour of the day as on a 24-hour clock. mm is minutes. ss is seconds. Z is a literal 'Z' character indicating that this string representation of the date is in UTC

Send date in this format . This will 100% work !! Let me know if this helped you .