Skip to content

Instantly share code, notes, and snippets.

@vojty
Last active August 29, 2015 13:59
Show Gist options
  • Save vojty/10647458 to your computer and use it in GitHub Desktop.
Save vojty/10647458 to your computer and use it in GitHub Desktop.
Apache Solr 4.0+ Update document
<?php
// https://wiki.apache.org/solr/UpdateJSON
$data = array(
array(
'id' => $id,
'field' => array(
'set' => 'value', // set is keyword
)
)
);
$json = json_encode($data);
$ch = curl_init('http://localhost:8985/solr/collection1/update?commit=true');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json))
);
$result = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment