写入DataStax Solr表
我试着从一个Solr表中读取文档,然后用不同的键空间将文档写入另一个Solr表。这是我使用的代码的运行版本:写入DataStax Solr表,solr,cassandra,datastax,Solr,Cassandra,Datastax,我试着从一个Solr表中读取文档,然后用不同的键空间将文档写入另一个Solr表。这是我使用的代码的运行版本: public static void main(String[] args ) { HttpSolrServer solrServer = new HttpSolrServer(sourceSolrTableUrl); solrServer.setParser(new XMLResponseParser()); HttpSolrServer targetSolr
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);
}
代码似乎在以下行中断:
targetSolrServer.add(inputDocs);
服务器上运行的Solr版本为4.0.0。
我在客户端代码中使用Solr-4.0.0-BETA JAR
谁能给我指点一下哪里出了问题吗?发现了我的错误。我试图插入的日期值与schema.xml中的格式不一致 我想这告诉我,我应该确保将来尝试插入Solr的所有数据都应该与schema.xml格式匹配 摘录自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"/>
<!--
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"/>