簡體   English   中英

使用 java 將數據導入 Solr

[英]Import Data to Solr using java

我試圖使用java將數據上傳到solr服務器。
是否可以這樣做或直接從java創建集合和上傳數據,或者有什么方法可以這樣做。

我使用 DIH 和 Tika 找到了兩個選項。

任何建議都會有所幫助。

您可以嘗試 solrj api: https ://wiki.apache.org/solr/Solrj。 它可用於上傳/搜索 solr 實例。

如果您在 Cloud (ZooKeeper) 模式下運行 Solr,那么使用 solrj 您可以創建集合。 但是在集合創建命令之前上傳 SolrCloud 要使用的配置。

如果您使用的是獨立模式,則手動創建集合。

使用SOLRJ在 solr 服務器上上傳文檔的示例代碼:

SolrServer server = new HttpSolrServer("http://localhost:8983/solr/CORE_NAME/");
        SolrInputDocument doc = new SolrInputDocument();


        doc.addField("id", "1");
        doc.addField("Name", "John");
        doc.addField("RollNo", "101");

        server.add(doc);
        UpdateResponse updateResponse = server.commit();
        System.out.println(updateResponse.getStatus());

確保您在schema.xml 中有以下條目,該條目將位於Core 的conf文件夾中。

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="Name" type="text_general" indexed="true" stored="true"/>
<field name="RollNo" type="text_general" indexed="true" stored="true"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM