How to update the document on solr 6.0?

安稳与你 提交于 2019-12-12 00:06:58

问题


I am using solr 6.0 version.

This is my data

{
    "id" : "14",
    "solrid" : "solr|school|14",
    "name" : "test update solr 14",
    "status" : "pending",
    "state" : "Andhra Pradesh",
    "board" : "CISCE",
    "updated" : "2016-05-26T02:24:25Z",
    "pincode" : "0"
}

I want to update the data on document as per id. example i want to change the name

$doc = $update->createDocument();


   $doc["id"] =$id;
            $doc["name"]="school";
            $update->addDocument($doc);
            $update->addCommit();
            $client->update($update);

This code is correct? Or i want to use other flow. PHP Solarium code.


回答1:


Yes, basically the flow is correct. You can always check the solarim examples gist at https://gist.github.com/basdenooijer/894286.

Alternatively you can do something like this:

$update = $client->createUpdate();
$document = $update->createDocument();
$document->setKey('id', $id);
foreach ($data as $field => $value) {
    if ($field == 'id') {
        continue;
    }
    $document->setField($field, $value, null, 'set');
}
$update->addDocument($document, true, 1500);
$result = $client->update($update);


来源:https://stackoverflow.com/questions/37456205/how-to-update-the-document-on-solr-6-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!