Quick start Solr 之数据导入(三)

导入数据
1. 将jar包导入到solr/WEB-INF/lib下(之前已导入)

数据库连接包(这里用的是oracle数据库)

2. 修改配置文件solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
<str name="update.chain">uuid</str>
</lst>
</requestHandler>
3. 在collection1/conf下创建文件data-config.xml,内容如下,配置需要导入的数据,定义filed name名称和managed-schema filed name要一致
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@//ip:端口/PROD1"
user="用户名"
password="密码"/>
<document>
<entity name="entClassLab" pk="ID" query="SELECT ID,PRIPID, ENTNAME, LONGITUDE ||' '|| LATITUDE POSITION,LONGITUDE ||' '|| LATITUDE STATION, AREA, ENTSTATUS, LONGITUDE,LATITUDE,ENTTYPE,ESDATE, REGCAP, INDUSTRYPHY, HIGHTECH, PUBLICENT, INDUSTRY, IPR FROM ENT_CLASS_LAB">
<field column="ID" name="id"/>
<field column="PRIPID" name="pripid"/>
<field column="ENTNAME" name="entname"/>
<field column="POSITION" name="position"/>
<field column="STATION" name="station"/>
<field column="LONGITUDE" name="longitude"/>
<field column="LATITUDE" name="latitude" />
<field column="AREA" name="area"/>
<field column="ENTSTATUS" name="entstatus" />
<field column="ENTTYPE" name="enttype"/>
<field column="ESDATE" name="esdate"/>
<field column="REGCAP" name="regcap"/>
<field column="INDUSTRYPHY" name="industryphy"/>
<field column="HIGHTECH" name="hightech"/>
<field column="PUBLICENT" name="publicent"/>
<field column="INDUSTRY" name="industry"/>
<field column="IPR" name="ipr"/>
</entity>
</dataConfig>
4. 配置managed-schema相对应的filed域
<field name="entname" type="text_ik" indexed="true" stored="true"/>
<field name="position" type="location_jts" indexed="true" stored="true"/>
<field name="station" type="location_rpt" indexed="true" stored="true"/>
<field name="area" type="string" indexed="true" stored="true"/>
<field name="entstatus" type="string" indexed="true" stored="true"/>
<field name="longitude" type="string" indexed="true" stored="true"/>
<field name="latitude" type="string" indexed="true" stored="true"/>
<field name="enttype" type="string" indexed="true" stored="true"/>
<field name="esdate" type="string" indexed="true" stored="true"/>
<field name="regcap" type="string" indexed="true" stored="true"/>
<field name="industryphy" type="string" indexed="true" stored="true"/>
<field name="hightech" type="string" indexed="true" stored="true"/>
<field name="publicent" type="string" indexed="true" stored="true"/>
<field name="industry" type="string" indexed="true" stored="true"/>
<field name="ipr" type="string" indexed="true" stored="true"/>
5. 访问solr应用就能看到如下界面:

相关参数如下:
entity
entity是document下面的标签(data-config.xml)。使用这个参数可以有选择的执行一个或多个entity 。使用多个entity参数可以使得多个entity同时运行。如果不选择此参数那么所有的都会被运行。
clean
选择是否要在索引开始构建之前删除之前的索引,默认为true
commit
选择是否在索引完成之后提交。默认为true
optimize
是否在索引完成之后对索引进行优化。默认为true
debug
是否以调试模式运行,适用于交互式开发(interactive development mode)之中。
请注意,如果以调试模式运行,那么默认不会自动提交,请加参数“commit=true”
当然solr支持多表关联导入,增量导入和定时更新数据,下篇接着介绍。

猜你喜欢

转载自www.cnblogs.com/Ibelieving/p/9227617.html