将数据库edbstore的edbtore schema下的customers表导入到solr
1. 首先查看customers表字段信息
edbstore=> \d customers Table "edbstore.customers" Column | Type | Modifiers ----------------------+-----------------------+---------------------------------------------------------------- customerid | integer | not null default nextval('customers_customerid_seq'::regclass) firstname | character varying(50) | not null lastname | character varying(50) | not null address1 | character varying(50) | not null address2 | character varying(50) | city | character varying(50) | not null state | character varying(50) | zip | integer | country | character varying(50) | not null region | smallint | not null email | character varying(50) | phone | character varying(50) | creditcardtype | integer | not null creditcard | character varying(50) | not null creditcardexpiration | character varying(50) | not null username | character varying(50) | not null password | character varying(50) | not null age | smallint | income | integer | gender | character varying(1) |
2. 新建core,名称为edbstore
3. 修改solrconfig.xml文件,添加如下
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler>
4. 新建data-config.xml文件,内容如下所示
<dataConfig> <dataSource name="source1" type="JdbcDataSource" driver="org.postgresql.Driver" url="jdbc:postgresql://172.16.101.66:5432/edbstore" user="edbstore" password="edbstore" /> <document> <entity name="file1" datasource="source1" query="SELECT * FROM edbstore.customers"> <field column="customerid" name="id" /> <field column="firstname" name="firstname" /> <field column="lastname" name="lastname" /> <field column="address1" name="address1" /> <field column="address2" name="address2" /> <field column="city" name="city" /> <field column="state" name="state" /> <field column="zip" name="zip" /> <field column="country" name="country" /> <field column="region" name="region" /> <field column="email" name="email" /> <field column="phone" name="phone" /> <field column="creditcardtype" name="creditcardtype" /> <field column="creditcard" name="creditcard" /> <field column="creditcardexpiration" name="creditcardexpiration" /> <field column="username" name="username" /> <field column="password" name="password" /> <field column="age" name="age" /> <field column="income" name="income" /> <field column="gender" name="gender" /> </entity> </document> </dataConfig>
5. 将以下信息添加到schema.xml文件
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> --> <field name="firstname" type="string" indexed="true" stored="true" /> <field name="lastname" type="string" indexed="true" stored="true" /> <field name="address1" type="string" indexed="true" stored="true" /> <field name="address2" type="string" indexed="true" stored="true" /> <field name="city" type="string" indexed="true" stored="true" /> <field name="state" type="string" indexed="true" stored="true" /> <field name="zip" type="int" indexed="true" stored="true" /> <field name="country" type="string" indexed="true" stored="true" /> <field name="region" type="int" indexed="true" stored="true" /> <field name="email" type="string" indexed="true" stored="true" /> <field name="phone" type="string" indexed="true" stored="true" /> <field name="creditcardtype" type="int" indexed="true" stored="true" /> <field name="creditcard" type="string" indexed="true" stored="true" /> <field name="creditcardexpiration" type="string" indexed="true" stored="true" /> <field name="username" type="string" indexed="true" stored="true" /> <field name="password" type="string" indexed="true" stored="true" /> <field name="age" type="int" indexed="true" stored="true" /> <field name="income" type="int" indexed="true" stored="true" /> <field name="gender" type="string" indexed="true" stored="true" />
6. 下载postgresql jdbc驱动
https://jdbc.postgresql.org/download.html
注意版本要和本地的JDK版本兼容
将驱动文件postgresql-42.2.6.jre6.jar复制到tomcat的solr lib目录,重启tomcat
7. 执行DIH导入
8. 查看导入的document
===================来自一泽涟漪的博客,转载请标明出处 www.cnblogs.com/ilifeilong===================