1. $_config = array(
    2. 'host' =>'192.168.1.60', // host
    3. 'port' => 39200,
    4. );
    5. $client = new Elastica\Client($_config);
    6. try {
    7. $document = new Elastica\Document();
    8. $id = '23';
    9. $time = time();
    10. $data =array(
    11. 'name'=>'test 叶问 dd ',
    12. 'age'=> '9999',
    13. 'test'=>'just for test ',
    14. 'time'=>$time
    15. );
    16. $typestr = "bfire";
    17. $indexstr = "abc";
    18. $document->setId($id);
    19. $document->setData($data);
    20. $document->setType($typestr);
    21. $document->setIndex($indexstr);
    22. $arr = array($document);
    23. //添加
    24. //$reindex = $client->addDocuments($arr);
    25. //更新
    26. //$reindex = $client->updateDocument($id, $document, $indexstr, $typestr);
    27. /**
    28. * Bulk deletes documents
    29. *
    30. * @param array|\Elastica\Document[] $docs
    31. * @return \Elastica\Bulk\ResponseSet
    32. * @throws \Elastica\Exception\InvalidException
    33. */
    34. $reindex = $client->deleteDocuments($arr);
    35. echo 'in try ';
    36. } catch (Exception $e) {
    37. echo 'in error';
    38. var_dump($e);
    39. }
    40. echo 'all the end';