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'=>'9999',
    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. //更新
    23. /**
    24. * Update document, using update script. Requires elasticsearch >= 0.19.0
    25. *
    26. * @param int $id document id
    27. * @param array|\Elastica\Script|\Elastica\Document $data raw data for request body
    28. * @param string $index index to update
    29. * @param string $type type of index to update
    30. * @param array $options array of query params to use for query. For possible options check es api
    31. * @return \Elastica\Response
    32. * @link http://www.elasticsearch.org/guide/reference/api/update.html
    33. */
    34. $reindex = $client->updateDocument($id, $document, $indexstr, $typestr);
    35. echo 'in try ';
    36. } catch (Exception $e) {
    37. echo 'in error';
    38. var_dump($e);
    39. }
    40. echo 'all the end';