$_config = array(
'host' =>'192.168.1.60', // host
'port' => 39200,
);
$client = new Elastica\Client($_config);
try {
$document = new Elastica\Document();
$id = '23';
$time = time();
$data =array(
'name'=>'test 叶问 dd ',
'age'=> '9999',
'test'=>'just for test ',
'time'=>$time
);
$typestr = "bfire";
$indexstr = "abc";
$document->setId($id);
$document->setData($data);
$document->setType($typestr);
$document->setIndex($indexstr);
$arr = array($document);
//添加
//$reindex = $client->addDocuments($arr);
//更新
//$reindex = $client->updateDocument($id, $document, $indexstr, $typestr);
/**
* Bulk deletes documents
*
* @param array|\Elastica\Document[] $docs
* @return \Elastica\Bulk\ResponseSet
* @throws \Elastica\Exception\InvalidException
*/
$reindex = $client->deleteDocuments($arr);
echo 'in try ';
} catch (Exception $e) {
echo 'in error';
var_dump($e);
}
echo 'all the end';