开发者

Indexing and searching MySQL with solr

(I have put ' in the XML below to make it display)

Hi all I want to index my MySQL db table with solr. I have installed the necessary java components/adaptors etc. My database is called 'test_db' and the table in it is called 'table_tb'. The table contains 2 columns (fields)

-Field 1 is called 'ID' and is an autoincremented primary key integer -Field 2 is called 'COLA' and is text

The table has two rows (records) ID=1 and ID=2 with some text against each corresponding to the second column. I have setup the following conf files (they are in the correct directories):

data-config.xml

<dataConfig>
  <dataSource type="JdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost/test_db"
              user="username"
              password="db_pwd"/>

<document name="doc">

<entity name="test_tb" query="select ID from test_tb">
        <field column="ID" name="ID" />
        <field column="COLA" name="COLA" />
</entity>

  </document>
</dataConfig>

solrconfig.xml

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

schema.xml

 <fields>
        <field name="ID" type="int" indexed="true" stored="true" required="true"/>
        <field name="COLA" type="string" indexed="true" stored="true" required="true"/>
 </fields>

 <uniqueKey>ID</uniqueKey>

"[URL]:8983/solr/dataimport?command=full-import" in my browser I get the following outputs:

(1) browser output (xml)

<response>
−
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</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">2</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2010-08-03 16:15:51</str>
−
<str name="">

Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.
</str>
<str name="Committed">2010-08-03 16:15:51</str>
<str name="Optimized">2010-08-03 16:15:51</str>
<str name="Total Documents Processed">0</str>
<str name="Total Documents Failed">2</str>
<str name="Time taken ">0:0:0.32</str>
</lst>
−
<str name="WARNING">
This response format is experimental.  It is likely to change in the future.
</str>
</response>

Suggesting 2 records were read but not indexed

Server-side output

WARNING: Error creating document : SolrInputDocument[{ID=ID(1.0)={1}}]
org.apache.solr.common.SolrException: Document [null] 开发者_如何学运维missing required field: id


WARNING: Error creating document : SolrInputDocument[{ID=ID(1.0)={2}}]
org.apache.solr.common.SolrException: Document [null] missing required field: id

Does anyone know what I am doing wrong?

Thanks in advance for any help!!!


A field 'id' was present elsewhere in the document. I commented this out and it worked.


You need to have synchronized: scheme.xml and what is in data-config.xml (definition of fields needs to be the same)


<entity name="test_tb" query="select ID from test_tb">
        <field column="ID" name="ID" />
        <field column="COLA" name="COLA" />
</entity>

it should be query="select * from test_tb" i think.

if you execute the query select id from test_tb you will get only one column while you want two.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜