使用DataImportHandler索引SOLR中MongoDB集合中的字段时获取JSONParseException

时间:2016-01-20 17:25:01

标签: mongodb solr

我在尝试索引MongoDB集合中的数据时看到了这个异常:

Exception while processing: products document : SolrInputDocument(fields: []):org.apache.solr.handler.dataimport.DataImportHandlerException: com.mongodb.util.JSONParseException: 
{idStr,name,code,description,price,brand,size,color}
 ^
    at org.apache.solr.handler.dataimport.MongoEntityProcessor.initQuery(MongoEntityProcessor.java:46)
    at org.apache.solr.handler.dataimport.MongoEntityProcessor.nextRow(MongoEntityProcessor.java:54)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:244)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:476)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:415)
    at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:481)
    at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:462)
Caused by: com.mongodb.util.JSONParseException: 
{idStr,name,code,description,price,brand,size,color}
 ^
    at com.mongodb.util.JSONParser.parseString(JSON.java:387)

以下是我的核心conf文件夹中dataimport目录中的data-source-config文件:

<dataConfig>    
 <dataSource name="mymongodb" type="MongoDataSource" database="mongodb://*.*.*.*/testdb" />
     <document name="data">

      <entity 
      name="products"
      processor="MongoEntityProcessor"
      query="{idStr,name,code,description,price,brand,size,color}"
      collection="products"
      datasource="mymongodb"
      transformer="MongoMapperTransformer" >

        <field column="idstr" name="idstr" mongoField="idStr"/>
        <field column="name" name="name" mongoField="name"/>
        <field column="code" name="code" mongoField="code"/>
        <field column="description" name="description" mongoField="description"/>
        <field column="price" name="price" mongoField="price"/>
        <field column="brand" name="brand" mongoField="brand"/>
        <field column="size" name="size" mongoField="size"/>
        <field column="color" name="color" mongoField="color"/>

    <entity 
    name="categories"
    processor="MongoEntityProcessor"
    query="{'idStr':'${categories.idstr}'}"
    collection="categories"
    datasource="mymongodb"
    transformer="MongoMapperTransformer">

        <field column="type" name="type" mongoField="type"/>
    </entity>   
    </entity>
    </document> 
</dataConfig>

我正在尝试使用产品集合的idStr(字段名称=&gt; idstr)加入类别集合的字段idStr,并获取上述字段(名称,描述,...来自产品和类别中的类型字段)。

对此异常的任何评论/解决方案都会非常感激。谢谢!

2 个答案:

答案 0 :(得分:0)

您的SOLR字段已声明为idstr,但您在query的{​​{1}}属性dataConfig中引用它(camelcase差异)。

答案 1 :(得分:0)

我能够解决这个问题...... 以下是data-source-config文件中的工作配置:

 <entity 
name="products"
query="select idStr,name,code,description,price,brand,size,color from products">

    <field name="prodidStr" column="idStr" />
    <field name="name" column="name" />
    <field name="code" column="name" />
    <field name="description" column="description" />
    <field name="price" column="price" />
    <field name="brand" column="brand"  />
    <field name="size" column="size" />
    <field name="color" column="color"  />

  <entity 
  name="categories" 
  dataSource="mongod"     
  query="select idStr,ancestors from categories  where idStr = '${products.idStr}'">
    <field name="catidStr" column="idStr" />
    <field  name="ancestors" column="ancestors" />
</entity> 

</entity>