【问题标题】:Writing to DataStax Solr table写入 DataStax Solr 表
【发布时间】:2013-12-20 11:49:33
【问题描述】:

我试图从一个 Solr 表中读取并将文档写入另一个键空间中的另一个。这是我使用的代码的破旧版本:

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);
}

当我运行这段代码时,这是我得到的错误:

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)

代码似乎在以下行中断:

targetSolrServer.add(inputDocs);

服务器上运行的 Solr 版本为 4.0.0。 我在客户端代码中使用 Solr-4.0.0-BETA jars。

谁能给我一些关于可能出错的指示?

【问题讨论】:

    标签: solr cassandra datastax


    【解决方案1】:

    发现我的错误。我试图插入一个不符合 schema.xml 格式的日期值。

    我想这告诉我我应该确保我将来尝试插入 Solr 的所有数据都应该匹配 schema.xml 格式。

    摘自我的 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"/>
    

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 2018-09-25
      • 1970-01-01
      • 2017-02-26
      • 2016-11-23
      • 1970-01-01
      • 2016-09-25
      • 2017-03-04
      • 2015-02-24
      相关资源
      最近更新 更多