I am trying to index the mysql table in solr using DataImportHandler, but it's seems not indexing
我试图使用DataImportHandler在solr中索引mysql表,但它似乎不是索引
data-config.xml
data-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/solr_tut"
user="root"
password=""/>
<document>
<entity name="product_id"
query="select product_id,name,description from products">
</entity>
</document>
</dataConfig>
solrconfig.xml
xml
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
When i try to index in solr admin(http://localhost:8080/solr/dataimport?command=full-import
) i am getting this response
当我尝试在solr admin(http://localhost:8080/solr/dataimport?command=full-import)中索引时,我得到了这个响应
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">19</int>
</lst>
<lst name="initArgs">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</lst>
<str name="command">full-import</str>
<str name="status">idle</str>
<str name="importResponse"/>
<lst name="statusMessages">
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">4</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2014-01-10 10:38:00</str>
<str name="">
Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.
</str>
<str name="Committed">2014-01-10 10:38:00</str>
<str name="Total Documents Processed">0</str>
<str name="Time taken">0:0:0.33</str>
</lst>
<str name="WARNING">
This response format is experimental. It is likely to change in the future.
</str>
</response>
After if i search(http://localhost:8080/solr/select?q=*:*
), i am getting 0 result.
如果我搜索(http://localhost:8080/solr/select?q=*:*),我将得到0个结果。
Update-1: schema.xml
更新1:schema.xml
1 个解决方案
#1
3
You just missed the mapping of the columns in the result set to the documents fields. You need to do that within the entity
element of your data-config.xml
.
您刚刚错过了结果集中列与documents字段的映射。您需要在data-config.xml的实体元素内执行该操作。
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/solr_tut"
user="root"
password=""/>
<document>
<entity name="product_id"
query="select product_id,name,description from products">
<!-- this is the place where you map the columns of your result set
to fields of the new solr document -->
<field column="PRODUCT_ID" name="id" />
<field column="NAME" name="name" />
<field column="DESCRIPTION" name="description" />
</entity>
</document>
</dataConfig>
In your case there is one vital mapping you missed. product_id
to id
. Solr can autodetect mappings, if the column name and the name of the field in the schema are equal, as is written in the wiki
在您的例子中,有一个重要的映射您错过了。如果模式中的列名和字段名相等(如在wiki中所写),那么product_id到id. Solr可以自动检测映射
In the above example, there are mappings of fields to Solr fields. It is possible to totally avoid the field entries in entities if the names of the fields are same (case does not matter) as those in Solr schema.
在上面的示例中,有字段到Solr字段的映射。如果字段的名称与Solr模式中的字段名称相同(大小写无关),则完全可以避免实体中的字段条目。
But as said, in your situation that is not the case. product_id
and id
do differ. Since your id
field is required
those documents will not make it into the index.
但如前所述,在你的情况下不是这样的。product_id和id是不同的。由于您的id字段是必需的,这些文档不会将其放入索引中。
More information can be found in Solr's Wiki about the DataImportHandler or in the reference guide.
更多的信息可以在Solr的维基中找到,关于DataImportHandler或者参考指南。
#1
3
You just missed the mapping of the columns in the result set to the documents fields. You need to do that within the entity
element of your data-config.xml
.
您刚刚错过了结果集中列与documents字段的映射。您需要在data-config.xml的实体元素内执行该操作。
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/solr_tut"
user="root"
password=""/>
<document>
<entity name="product_id"
query="select product_id,name,description from products">
<!-- this is the place where you map the columns of your result set
to fields of the new solr document -->
<field column="PRODUCT_ID" name="id" />
<field column="NAME" name="name" />
<field column="DESCRIPTION" name="description" />
</entity>
</document>
</dataConfig>
In your case there is one vital mapping you missed. product_id
to id
. Solr can autodetect mappings, if the column name and the name of the field in the schema are equal, as is written in the wiki
在您的例子中,有一个重要的映射您错过了。如果模式中的列名和字段名相等(如在wiki中所写),那么product_id到id. Solr可以自动检测映射
In the above example, there are mappings of fields to Solr fields. It is possible to totally avoid the field entries in entities if the names of the fields are same (case does not matter) as those in Solr schema.
在上面的示例中,有字段到Solr字段的映射。如果字段的名称与Solr模式中的字段名称相同(大小写无关),则完全可以避免实体中的字段条目。
But as said, in your situation that is not the case. product_id
and id
do differ. Since your id
field is required
those documents will not make it into the index.
但如前所述,在你的情况下不是这样的。product_id和id是不同的。由于您的id字段是必需的,这些文档不会将其放入索引中。
More information can be found in Solr's Wiki about the DataImportHandler or in the reference guide.
更多的信息可以在Solr的维基中找到,关于DataImportHandler或者参考指南。