2016-11-06 48 views
0

我需要爲Solr索引中的每個文檔添加一個新字段。Solr:如何向所有文檔添加新字段

這個新字段不需要被搜索。它只需要存儲在Solr中並返回到搜索結果中。

新字段的值可以根據id字段來計算(和其他信息是不存在的Solr索引)。

什麼是最快的,最簡單的方式來實現這一目標?

回答

1

嘗試Solr Schema API

curl http://localhost:8983/solr/yourcollection/schema -X POST -H 'Content-type:application/json' --data-binary '{ 
    "add-field" : { 
    "name":"myfield", 
    "type":"string", 
    "stored":true 
    } 
}' 

填補這一領域的現有文檔的價值只能用重新索引操作AFAIK完成。

+0

不幸的是,這並沒有解決我的問題。索引時新字段的值不可用。它來自其他來源,除索引數據外。 – bpgergo

+0

在這種情況下,您可能只需要更新您的字段,只要您有可用的價值。您可以通過[Solr Atomic Updates](https://cwiki.apache.org/confluence/display/solr/Updating+Parts+of+Documents#UpdatingPartsofDocuments-AtomicUpdates)執行此操作。例如:'curl http:// localhost:8983/solr/yourcollection/update?commitWithin = 3000 -d'[{「id」:「your_doc_id」,「myfield」:{「set」,「field value」}} ]'' –

相關問題