首页 > 解决方案 > 无法在 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
}

标签: phpelasticsearcherror-handling

解决方案


我还没有在 elasticsearch 服务器本身上创建索引。

我必须先创建它,然后才能在 php-api 上访问它

为此,我运行:

curl -X PUT -x  "" "http://127.0.0.1:9200"/test

在命令提示符上


推荐阅读