$_config = array(
'host' =>'192.168.1.60', // host
'port' => 39200,
);
$client = new Elastica\Client($_config);
try {
$document = new Elastica\Document();
$id = '23';
$data =array(
'name'=>'bfiretest',
'age'=> '20'
);
$typestr = "bfire";
$indexstr = "abc";
$document->setId($id);
$document->setData($data);
$document->setType($typestr);
$document->setIndex($indexstr);
$arr = array($document);
//添加
/**
* Uses _bulk to send documents to the server
*
* Array of \Elastica\Document as input. Index and type has to be
* set inside the document, because for bulk settings documents,
* documents can belong to any type and index
*
* @param array|\Elastica\Document[] $docs Array of Elastica\Document
* @return \Elastica\Bulk\ResponseSet Response object
* @throws \Elastica\Exception\InvalidException If docs is empty
* @link http://www.elasticsearch.org/guide/reference/api/bulk.html
*/
$reindex = $client->addDocuments($arr);
echo 'in try ';
} catch (Exception $e) {
echo 'in error';
var_dump($e);
}