首页 > 解决方案 > 如何在没有分布式更新处理器的情况下执行 solr 原子更新?

问题描述

我在 kubernetes 中运行一个 solr 集群,我的组织管理我们自己的分片,而不是让 solr 自动分发文档。因此我们DistributedUpdateProcessorFactoryNoOpDistributingUpdateProcessorFactory. solrconfig.xml这发生在我的应用程序代码中,但我可以通过 shell 的简单卷曲重现该行为:

# send an update to a document in shard 0 that adds a value to each field
curl -X POST --header "Content-Type:application/json" --data "[{'id': 'my_doc_id', 'my_field1': {add: ['foo']}, 'my_field2': {add: ['bar']}]" "http://solr-0.solr-headless.default.svc.cluster.local:8983/solr/my_collection/update?commit=false"

# commit the update to the shard (along with updates to other docs I might have sent)
curl -X GET "http://solr-0.solr-headless.default.svc.cluster.local:8983/solr/my_collection/update?commit=true"

Wheremy_field1my_field2are 都是多值字符串字段(我基本上想存储从我正在处理的一些数据中提取的字符串列表)。

solr 给出的响应是:

{
  "responseHeader":{
    "status":400,
    "QTime":3},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"RunUpdateProcessor has received an AddUpdateCommand containing a document that appears to still contain Atomic document update operations, most likely because DistributedUpdateProcessorFactory was explicitly disabled from this updateRequestProcessorChain",
    "code":400}}

所以我的问题是,为什么在没有分布式更新处理器的情况下禁止原子更新,有没有办法解决这个问题并将原子更新显式发送到各个分片?

标签: solrlucenesolrcloud

解决方案


我的猜测是,由于原子更新需要先读取文档,更改字段然后重新索引文档,因此 RunUpdateProcessor 仅接收已更改的文档而没有任何更新/添加命令。

这种转换是 的责任DistributedUpdateProcessorFactory,因为在正常设置中,它必须从包含它的节点中检索文档,并应用更新,然后将其提交给RunUpdateProcessor

您可以通过使用乐观并发特性来自己实现此功能_version_,或者创建一个自定义替换,DistributedUpdateProcessorFactory通过从索引中获取更新请求来解决更新请求。

旧的 wiki 说DistributedUpdateProcessor对于单核实例来说是无操作的,但似乎不再是这种情况了。

但是如果你在没有集群设置的情况下运行,DistributedUpdateProcessorFactory 不会做任何与分发相关的事情——也就是说,只要你将 Solr 实例配置为独立的,那应该可以正常工作。这可能是架构问题 + solr 配置,而不是更新处理器的问题。


推荐阅读