我在 Solr 中有以下索引数据。我想使用 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();
}
但问题是这是创建一个新文档而不是更新旧文档。感谢您提前提供帮助。
最佳答案
您必须在文档值中包含 id 部分,否则 Solr 无法找到要更新的原始文档。这应该是一个 uniqueKey 字段。
document.addField("Id", 12345);
您无法在一个请求中对多个文档执行更新,因此每个文档都必须自行更新。
关于java - 使用 SolrJ 更新 Solr 中的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46152074/