Question

I was trying to read from one Solr table and write the documents to another one in a different keyspace. This is the run-down version of the code I used:

public static void main(String[] args ) {
    HttpSolrServer solrServer = new HttpSolrServer(sourceSolrTableUrl);
    solrServer.setParser(new XMLResponseParser());

    HttpSolrServer targetSolrServer = new HttpSolrServer(targetSolrTableUrl);

    SolrQuery query1 = new SolrQuery();
    query1.setQuery( "dev_key:T*" );

    QueryResponse query = solrServer.query(query1);
    SolrDocumentList solrDocList = query.getResults();

    Collection<SolrInputDocument> inputDocs = new ArrayList<SolrInputDocument>();
    for (SolrDocument doc : solrDocList) {
        counter++;
        SolrInputDocument inputDoc = new SolrInputDocument();

        value = (String) doc.get(DEV_KEY);
        addToDoc(inputDoc, DEV_KEY, value);

        value = Long.toString((Long)doc.get(DEVICE_ID));
        addToDoc(inputDoc, DEVICE_ID, value);

        value = (String) doc.get(DEVICE_TYPE);
        addToDoc(inputDoc, DEVICE_TYPE, value);

        value = df.format((Date) doc.get(DEVICE_MFG_DATE));
        addToDoc(inputDoc, DEVICE_MFG_DATE, value);

        value = (String) doc.get(DEV_MODEL);
        addToDoc(inputDoc, DEV_MODEL, value);

        inputDocs.add(inputDoc);
         System.out.println(counter + "\t" + value);

        if (inputDocs.size()>5) {
            break;
        }
    }

    try {
        targetSolrServer.add(inputDocs);
        targetSolrServer.commit();
    } catch (SolrServerException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private static void addToDoc(SolrInputDocument doc, String fieldName, String value) {
    doc.addField(fieldName, value);
}

When I run this code, this is the error I get:

Exception in thread "main" java.lang.RuntimeException: Invalid version (expected 2, but 60) or the data in not in 'javabin' format
at org.apache.solr.common.util.JavaBinCodec.unmarshal(JavaBinCodec.java:109)
at org.apache.solr.client.solrj.impl.BinaryResponseParser.processResponse(BinaryResponseParser.java:41)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:384)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:68)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:54)
at com.xyz.SolrPopulater.main(SolrPopulater.java:114)

The code seems to break at the following line:

targetSolrServer.add(inputDocs);

The Solr running on the server is of version 4.0.0. I use Solr-4.0.0-BETA jars in my client code.

Could anyone give me some pointers on what could be going wrong?

Was it helpful?

Solution

Found out my mistake. I was trying to insert a date value which was not as per the format in the schema.xml.

I guess this tells me I should make sure all the data I try to insert into Solr in future should match the schema.xml format.

Excerpt from my schema.xml

<!--

 The format for this date field is of the form 1995-12-31T23:59:59Z, and
         is a more restricted form of the canonical representation of dateTime
         http://www.w3.org/TR/xmlschema-2/#dateTime    
         The trailing "Z" designates UTC time and is mandatory.
         Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z
         All other components are mandatory.

         Expressions can also be used to denote calculations that should be
         performed relative to "NOW" to determine the value, ie...

               NOW/HOUR
                  ... Round to the start of the current hour
               NOW-1DAY
                  ... Exactly 1 day prior to now
               NOW/DAY+6MONTHS+3DAYS
                  ... 6 months and 3 days in the future from the start of
                      the current day

         Consult the DateField javadocs for more information.

         Note: For faster range queries, consider the tdate type

-->
<fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0"    positionIncrementGap="0"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top