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. $data =array(
    10. 'name'=>'bfiretest',
    11. 'age'=> '20'
    12. );
    13. $typestr = "bfire";
    14. $indexstr = "abc";
    15. $document->setId($id);
    16. $document->setData($data);
    17. $document->setType($typestr);
    18. $document->setIndex($indexstr);
    19. $arr = array($document);
    20. //添加
    21. /**
    22. * Uses _bulk to send documents to the server
    23. *
    24. * Array of \Elastica\Document as input. Index and type has to be
    25. * set inside the document, because for bulk settings documents,
    26. * documents can belong to any type and index
    27. *
    28. * @param array|\Elastica\Document[] $docs Array of Elastica\Document
    29. * @return \Elastica\Bulk\ResponseSet Response object
    30. * @throws \Elastica\Exception\InvalidException If docs is empty
    31. * @link http://www.elasticsearch.org/guide/reference/api/bulk.html
    32. */
    33. $reindex = $client->addDocuments($arr);
    34. echo 'in try ';
    35. } catch (Exception $e) {
    36. echo 'in error';
    37. var_dump($e);
    38. }