我在Solr中有以下索引数据。我想添加一个额外的字段" Location"在使用SolrJ的索引数据中。我怎么能这样做?
"response":{"numFound":3061,"start":3059,"docs":[
{
"Id":12345,
"Name":"Rajeev Kumar",
"_version_":1223434645768768687},
{
"Id":67890,
"Name":"Rohit Kumar",
"_version_":1246457656544545434}]
}}
更新后应该看起来像这样 -
"response":{"numFound":3061,"start":3059,"docs":[
{
"Id":12345,
"Name":"Rajeev Kumar",
"Location" : <some value>,
"_version_":1223434645768768687},
{
"Id":67890,
"Name":"Rohit Kumar",
"Location": <some value>,
"_version_":1246457656544545434}]
}}
我尝试过这样的事情 -
public static void main(String[] args) throws SolrServerException, IOException {
String urlString = "http://localhost:8983/solr/gettingstarted";
HttpSolrClient solr = new HttpSolrClient.Builder(urlString).build();
solr.setParser(new XMLResponseParser());
SolrInputDocument document = new SolrInputDocument();
HashMap<String, Object> value = new HashMap<String, Object>();
value.put("set","Delhi");
document.addField("Location", value);
solr.commit();
}
但问题是这是创建一个新文档而不是更新旧文档。提前感谢您的帮助。
答案 0 :(得分:2)
您必须在文档值中包含id部分,否则Solr无法找到要更新的原始文档。这应该是uniqueKey字段。
document.addField("Id", 12345);
您无法在一个请求中对多个文档执行更新,因此每个文档都必须自行更新。