不能在 put 映射请求中提供类型,除非 include_type_name 参数设置为 true

ali*_*lin 16 elasticsearch laravel

我正在使用https://github.com/babenkoivan/scout-elasticsearch-driver通过 Laravel Scout 实现 Elasticsearch。Ivan 在 Github 上提到了这一点:

在 Elasticsearch 6.0.0 或更高版本中创建的索引可能只包含一个映射类型。在 5.x 中创建的具有多种映射类型的索引将继续像以前在 Elasticsearch 6.x 中一样运行。Elasticsearch 7.0.0 中将完全删除映射类型。

如果我在这里理解:https : //www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html我要么需要使用:

1) PUT 索引?include_type_name=true

或更好

2) PUT index/_doc/1 { "foo": "baz" }

我被卡住了,因为我不知道如何使用 1) 或 2)

如何添加参数include_type_name=true?

如何在不使用 include_type_name 参数的情况下创建正确的映射?

class TestIndexConfigurator extends IndexConfigurator
{
    use Migratable;
    /**
     * @var array
     */
    protected $settings = [
    ];
    protected $name = 'test';
}
Run Code Online (Sandbox Code Playgroud)

Web*_*str 17

早期版本的 Elasticsearch (<= 5) 支持每个索引的多种类型。这意味着您可以为每种类型使用不同的数据映射。在 Elasticsearch 6 中,这被删除了,你只能有一个映射类型。

因此,对于 Elasticsearch 7(最新版本),您可以像这样添加索引、设置映射和添加文档:

现在,关于您使用的 scout-elasticsearch-driver,在阅读您提到的文档后,只是说您需要为每个可搜索模型创建单独的索引配置器,因为多个模型不能存储在同一个索引中。

所以要创建索引,运行

php artisan make:index-configurator MyIndexConfigurator

进而

php artisan elastic:create-index App\\MyIndexConfigurator

这将为您在 elasticsearch 中创建索引。

要了解有关 elasticsearch 的更多信息,我建议您将 elasticsearch 和 kibana 安装到您的开发机器上,然后在 kibana 中使用它 - 界面非常好,并支持自动完成以简化学习曲线。


小智 5

当我GET product/default/_mapping在 Kibana 控制台中尝试时。

我一直收到这个错误。

“无法在获取映射请求中提供类型,除非 include_type_name 设置为 true”

这发生在弹性搜索 7.3.0 中。看起来最新版本的弹性搜索不再支持上述命令。

当我从上述命令中删除默认值时,它对我有用。

GET product/_mapping
Run Code Online (Sandbox Code Playgroud)