2014-02-25 92 views
1

我想更新solr中某個文檔的特定字段。但是,儘管如此,文檔的其他 字段將變爲空。在solr中更新文檔

CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://mydomain:8983/solr/index_socialmedia/"); 
    List<SolrInputDocument> solrInputDocsList = new ArrayList<SolrInputDocument>(); 

    SolrInputDocument solrInputDoc = new SolrInputDocument(); 

    solrInputDoc.addField("id","427832898745234516478592"); 
    solrInputDoc.addField("city","Kolkata"); 


    solrInputDocsList.add(solrInputDoc); 

    server.add(solrInputDocsList); 
    server.commit(); 

在上面的代碼中,「id」字段是唯一字段。 我該如何解決這個問題。

回答

0

在你的Solr schema.xml中

+0

這不是** uniqueKey **的問題。 Vijay在他的問題中提到過。「**」id「字段是唯一字段**」 – buddy86

0

哪個Solr的版本設置<uniqueKey>id</uniqueKey>您使用的? 如果它低於4.0,solr不支持單個字段更新(部分更新) 因此在您的情況下,現有的舊文檔被刪除並且新文檔被插入相同的ID (原因Solr不支持單個字段或部分更新是lucene如果您在使用Solr的4.0不支持部分更新)

你可以參考這個solrj api for partial document update

1

我試着用下面的代碼片段。它能夠進行部分更新。嘗試這個。

SolrServer server = new HttpSolrServer("http://mydomain:8983/solr/index_socialmedia/"); 

SolrInputDocument solrInputDoc = new SolrInputDocument(); 
Map<String, String> update = new HashMap<String, String>(); 
update.put("set", "Kolkata"); 

solrInputDoc.addField("id","427832898745234516478592"); 
solrInputDoc.addField("city", update); 

server.commit(); 
+0

非常感謝。它正在更新。但是,我必須在Slor 4.4中更新680萬條記錄,並且每個分片有兩個分割7GB RAM的雲環境。大約有100萬條記錄正在更新,之後,由於內存不足,其中一個碎片崩潰。任何線索? –

+0

如果答案解決了您的問題,請將其標記爲已接受的答案。 – buddy86