【问题标题】:Solr: How to update a document with unique IDSolr:如何更新具有唯一 ID 的文档
【发布时间】:2014-11-07 16:40:26
【问题描述】:

你能帮忙吗?我必须通过其唯一标识符更新 Solr 文档。比如说,我有一个类似的文件:

    {
      "text": "qwe",
      "id": "01a3aa6db06d39e8",
      "_version_": 1471599607983112200
    }

我想更新“短语”字段,所以我将以下内容发布到 127.0.0.1:8983/solr/update/?commit=true:

    [
      {
        "id" : "01a3aa6db06d39e8",
        "text" : {"set":"qwe. updated"}
      }
    ]

Solr 说 400 Bad Request 并返回以下内容:

    {
      "responseHeader":
        {
          "status":400,"QTime":0},
          "error":{"msg":"Document contains multiple values for uniqueKey field: id=[01a3aa6db06d39e8, 0000000000000000]","code":400}
        }
    }

如何正确更新包含唯一键的文档?

【问题讨论】:

  • 您能否从您的 schema.xml 中发布您的<field name="id" … />
  • ... ...
  • 您应该有一个带有name="id" 的字段。可以发一下吗?
  • name="id" 是否有多个字段?如果没有,您能否将您的 schema.xml 和 solrconfig.xml 发布到某个 pastebin 中?

标签: solr


【解决方案1】:

试试这个。

{"id":"01a3aa6db06d39e8","text":"hello world , this is an update"}

如果你想让文本像mongodb这样的多维数组,在solr中是无法容纳的,但是有办法做到这一点,有点乱。

如果您正在使用脚本来更新文档,并且我认为您正在使用循环,则在 PHP 上的 while 循环中包含提交和实例化:

while($row    = mysqli_fetch_assoc($result))
{
    $client = new SolrClient($options);

    $doc = new SolrInputDocument();
    $doc->addField('id', $row['id']);       
    $doc->addField('date', '2015-06-01T00:00:0.0Z');
    $doc->addField('name', $row['name']);       
    $updateResponse = $client->addDocument($doc);
}   
$client->commit();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多