Solr更新文档数据

使用XML更新文档

以下是用于更新现有文档中的字段的XML文件。将下面的内容保存在名称为update.xml的文件中。

<add>   
   <doc>     
      <field name = "id">001</field>     
      <field name = "first name" update = "set">Raj</field>     
      <field name = "last name" update = "add">Malhotra</field>     
      <field name = "phone" update = "add">9000000000</field>    
      <field name = "city" update = "add">Delhi</field>   
   </doc> 
</add>

正如上面看到的,写入更新数据的XML文件就类似之前用来添加文档的XML文件。 但唯一的区别是这里使用字段的一个update属性。

在这个示例中,我们将使用上述文档并尝试更新id001文档的字段。

假设XML文档(update.xml)存在于Solr的bin目录中。更新的核心是名称为my_core的索引,可以使用post工具更新如下

[web3@ubuntu:/usr/local/solr-6.4.0/bin]$ ./post -c my_core update.xml
执行上述命令后,将得到以下输出

web3@ubuntu:/usr/local/solr-6.4.0/bin$ ./post -c my_core update.xml
/usr/local/jdk1.8.0_65/bin/java -classpath /usr/local/solr-6.4.0/dist/solr-core-6.4.0.jar -Dauto=yes -Dc=my_core -Ddata=files org.apache.solr.util.SimplePostTool update.xml
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/my_core/update...
Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
POSTing file update.xml (application/xml) to [base]
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/my_core/update...
Time spent: 0:00:00.246
验证修改结果

访问Apache Solr Web界面的主页,选择核心 - my_core。 尝试通过在文本区域q中传递查询“”来检索所有文档,并执行查询。 执行时可以观察到文档已经更新了。

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3