改进语法并遵循以下步骤: 1) 将错误报告设置为 ON
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
session_start();
2) 需要'供应商/autoload.php';(使用作曲家安装)
3) 创建对象
$client = new Elasticsearch\Client();
$elasticaClient = new Elastica\Client();
$reque=new Elastica\Request($elasticaClient);
4) 程序示例
$index = $elasticaClient->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$type->addDocument(new Elastica\Document(1, array('username' => 'ruflin')));
$index->refresh();
$query = array(
'query' => array(
'query_string' => array(
'query' => 'ruflin',
)
)
);
//$typee =$reque->GET;
$path = $index->getName() . '/' . $type->getName() . '/_search';
$response = $elasticaClient->request($path, $reque::GET, $query);
$responseArray = $response->getData();
echo "<pre>";
print_r($responseArray);
参考链接
作曲家
b) https://getcomposer.org/doc/01-basic-usage.md
H) https://www.digitalocean.com/community/articles/how-to-install-and-use-composer-on-your -vps-运行-ubuntu