Solr DIH Quick Start

2019-03-27 01:04|来源: 网路

Step 1 : Edit your solrconfig.xml to add the request handler

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst>
</requestHandler>

 

Step 2 : Create a data-config.xml file as follows and save it to the conf dir

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://127.0.0.1/dbname" 
              user="test" 
              password="test1"  />
  <document>
    <entity name="first" 
            query="SELECT id, name FROM test">
    </entity>
  </document>
</dataConfig>

如果上面 的url参数写错,如写成jdbc:mysql://127.0.0.1:8080/dbname

可以看到如下信息:

信息: Creating a connection for entity first with URL: jdbc:mysql://127.0.0.1:8080/dbname

正确的值应当等于下图中host的值:

Step 3 : Ensure that your solr schema (schema.xml) has the fields 'id', 'name', 'desc'. Change the appropriate details in the data-config.xml

 

Step 4: 把下面组件放到<solr-home>/lib 目录

mysql-connector-java-5.1.19-bin.jar

apache-solr-dataimporthandler-extras-3.5.0.jar

 

Step 5 : Run the command http://localhost:8983/solr/dataimport?command=full-import

<response>  
...
    <str name="Total Requests made to DataSource">1</str>
    <str name="Total Rows Fetched">2</str>
    <str name="Total Documents Skipped">0</str>
...
</response>

 

Step 6: 验证

http://localhost:8983/solr/select/?q=terrya&version=2.2&start=0&rows=10&indent=on

<result name="response" numFound="1" start="0">
<doc>
<str name="id">SD453</str>
<str name="name">terrya</str>
</doc>
</result>

 


转自:http://www.cnblogs.com/season2009/archive/2012/04/25/2469300

相关问答

更多
  • 此功能已由SOLR-5147实施,并应适用于Solr 5.1+ 以下是从原始Jira票证中获取的示例配置。
    我已经使用了UpdateRequestHandler; 它非常适合我想做的事情。 [1] http://wiki.apache.org/solr/XsltUpdateRequestHandler I've resorted to using the UpdateRequestHandler; it's perfect for what I want to do. [1] http://wiki.apache.org/solr/XsltUpdateRequestHandler
  • 尝试将batchSize="-1"为batchSize="1"或0 。 将batchSize设置为-1是默认值,因此DIH将其设置为默认值500,并且某些驱动程序无法处理。 你可以在这里阅读更多DIH FAQ 至于你得到一些其他错误,请你发布那个错误是什么? Try setting your batchSize="-1" to batchSize="1" or 0. Setting the batchSize to -1 is the default value and thusly the DIH set ...
  • ScriptTransformer的答案是肯定的,我通过试验和错误发现。 Solr文档显示了如何使用“set”,“add”或“inc”将更新属性添加到字段节点。 如果我使用必要的更新属性创建测试XML文件,那么传递到常规更新处理程序时它可以正常工作。 但是,当传递给DIH时 - 即使没有任何转换 - 更新属性也会被完全忽略。 以下是我用来重新引入update属性并获得原子更新工作的脚本转换器的简化版本。 请注意使用Java HashMap。 var atomicTransformer = function ...
  • 我相信,您可以使用groupNames指定有序替换。 请参阅原始问题 Solr文档示例: Found a solution. Quite simple really:
    在源A上运行我的DIH会非常快,因为我们导入的数据很小,或者它仍然是耗时的,因为它必须重建整个SOLR的索引(即50,000,010条记录)。 如果您仅更新10-20条记录而不是50,000,010条记录 ,则从Source1到索引的数据导入应该很快 。 您可以通过在dataimport期间提供实体名称来执行此操作,如下所示: http://localhost:8080/solr/collection1/dataimport?command=full-import&entity=Source1 即使对于这 ...
  • 我在solrconfig.xml文件中添加了以下代码行 确保你的dist文件夹中的apache-solr-dataimporthandler-4.0.jar和apache-solr-dataimporthandler ...
  • Solr本身不提供。 但没有什么能阻止你这样做: 像这样为delta设置你的DIH sql:WHERE(last_pk_id>'$ {dataimporter.request.LAST_PK_ID}') 当你运行一些索引时,在Solr之外存储你索引的last_pk_id值,比如333。 下次需要增量索引时,请添加到您的请求中...&clean = false&LAST_PK_ID = 333 存储新的LAST_PK_ID(您可以查询solr) not provided by Solr itself. But ...
  • 您可能希望使用嵌套实体,外部实体为FileListEntityProcessor ,您的实体(实体)位于其中并使用外部实体公开的变量。 您还需要在该外部实体上将rootEntity属性设置为false,以便为每个内部实体生成文档。 基本上,您需要在现有定义中包含更多级别的实体。 或者,如果你有一些略有不同的文件,只有几个,你可以并排放置几个实体定义,DIH将全部运行它们。 You would want to use nested entities with outside entity being File ...
  • 您遇到的错误与Solr无关,而与您访问数据库的方式有关。 如果查看异常: java.sql.SQLException: Operation not allowed after ResultSet closed 。 我建议将batchSize参数更改为其他值,例如1000 。 batchSize选项用于批量检索数据库表的行,以减少内存使用(通常用于防止在运行数据导入处理程序时内存不足)。 虽然批量较小的可能较慢,但该选项并不打算影响导入过程的速度。 The error you're facing does n ...