gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:51:37 24 4
gpt4 key购买 nike

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

Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. Indices created in 5.x with multiple mapping types will continue to function as before in Elasticsearch 6.x. Mapping types will be completely removed in Elasticsearch 7.0.0.

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

  1. PUT index?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';
}

最佳答案

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

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

  • 创建索引

    PUT user
  • 添加映射

    PUT user/_mapping 
    {
    "properties": {
    "name": {
    "type": "keyword"
    },
    "loginCount": {
    "type": "long"
    }
    }
    }
  • 添加文档

    PUT user/_doc/1
    {
    "name": "John",
    "loginCount": 4
    }

  • 检查索引中的数据

    GET user/_search

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

所以要创建索引,运行

php artisan make:index-configurator MyIndexConfigurator

然后

php artisan elastic:create-index App\\MyIndexConfigurator

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

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

关于laravel - 不能在 put 映射请求中提供类型,除非 include_type_name 参数设置为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55857956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com