【问题标题】:Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true不能在 put 映射请求中提供类型,除非 include_type_name 参数设置为 true
【发布时间】:2019-09-15 09:33:03
【问题描述】:

我正在使用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) 放置索引/_doc/1 { “富”:“巴兹” }

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

如何添加参数 include_type_name=true?

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

class TestIndexConfigurator extends IndexConfigurator
{
    use Migratable;
    /**
     * @var array
     */
    protected $settings = [
    ];
    protected $name = 'test';
}

【问题讨论】:

标签: laravel elasticsearch


【解决方案1】:

早期版本的 Elasticsearch (

因此,对于 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 和 kibana 安装到您的开发机器上,然后在 kibana 中使用它 - 界面非常好,并且支持自动完成以简化学习曲线。

【讨论】:

    【解决方案2】:

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

    我一直收到这个错误。

    "获取映射请求中不能提供类型,除非 include_type_name 设置为 true"

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

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

    GET product/_mapping
    

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 2017-07-03
      • 2019-09-06
      • 2019-07-01
      • 1970-01-01
      相关资源
      最近更新 更多