1
votes

Could you please help. I have to update a Solr document by its unique identifier. Say, I have a document like:

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

I want to update the field "phrase", so I POST the following to 127.0.0.1:8983/solr/update/?commit=true:

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

Solr says 400 Bad Request and returns the following:

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

How the document containing a unique key can be properly updated?

1
Can you please post your <field name="id" … /> from your schema.xml? - lxg
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> ... <field name="text" type="text_en" indexed="true" stored="true"/> ... <dynamicField name="*_en" type="text_en" indexed="true" stored="true" multiValued="true"/> - Maksim
You should have a field with name="id". Can you post that one please? - lxg
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> - Maksim
Could it be that you have more than one field with name="id"? If not, could you please post your schema.xml and solrconfig.xml to some pastebin? - lxg

1 Answers

0
votes

Try this one.

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

If you want to make text as a multidimensional array like mongodb, that cannot be accommodate in solr but there are ways to it, a bit messy.

If you are using a script to update a doc and I think you are using a loop include the commit and the instantiate inside the while loop like this one on PHP:

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();