php - 无法在 Elasticsearch 中创建索引
问题描述
我是 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
}
解决方案
我还没有在 elasticsearch 服务器本身上创建索引。
我必须先创建它,然后才能在 php-api 上访问它
为此,我运行:
curl -X PUT -x "" "http://127.0.0.1:9200"/test
在命令提示符上
推荐阅读
- pyspark - Databricks:writeStream 不处理数据
- android-studio - Android Studio 更改为 IF 语句的自定义格式和缩进
- apollo-client - 覆盖 Apollo 内存缓存中的 id
- c++ - 为什么我不能在 C++ sort() 中使用成员函数 cmp?
- corda - Corda - 流问题有多种状态
- javascript - QuillEditor、vue 3、firebase:如何在编辑器外预览内容
- php - PHP 从给定的字符串中选择随机字符串
- python - 每次出现在 pygame 中时,动画的持续时间都会加倍
- node.js - 解决了 ✓ | 不使用 laravel mix 改变背景颜色
- java - Java Algs4:如何使用类 In 和 args[] 从控制台写入?