我是Elasticsearch的新手,所以我知道我忘记了一些东西,但不知道是什么。
我运行了这段代码:
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index'
];
// Create the index
$response = $client->indices()->create($params);
但是出现此错误:
{
"error": {
"root_cause": [
{
"type":"index_not_found_exception",
"reason":"no such index",
"resource.type":"index_or_alias",
"resource.id":"elasticsearch-i.php",
"index_uuid":"_na_",
"index":"elasticsearch-i.php"
}
],
"type":"index_not_found_exception",
"reason":"no such index",
"resource.type":"index_or_alias",
"resource.id":"elasticsearch-i.php",
"index_uuid":"_na_",
"index":"elasticsearch-i.php"
},
"status":404
}
答案 0 :(得分:2)
我尚未在Elasticsearch服务器本身上创建索引。
我必须先创建它,然后才能在php-api上访问它
为此,我运行:
curl -X PUT -x "" "http://127.0.0.1:9200"/test
在命令提示符下
答案 1 :(得分:1)
有几个原因不保存索引。首先检查您的Elasticsearch集群状态,然后尝试从任何客户端创建索引。
curl -X GET "localhost:9200/_cluster/health"
OR
curl -X GET "localhost:9200/_cluster/state"
OR
curl -X GET "localhost:9200/_nodes/stats"
curl
curl -X PUT "localhost:9200/twitter"
这是使用php创建的简单代码:
$client = ClientBuilder::create()->build();
$params = [
'index' => 'twitter_2'
];
$response = $client->indices()->create($params);
有关完整的详细信息,请检查https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_index_management_operations.html