laravel 不能在 put 映射请求中提供类型,除非 include_type_name 参数设置为 true
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55857956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true
提问by alin
I am using https://github.com/babenkoivan/scout-elasticsearch-driverto implement Elasticsearch with Laravel Scout. Ivan mentions this at Github:
我正在使用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.
在 Elasticsearch 6.0.0 或更高版本中创建的索引可能只包含一个映射类型。在 5.x 中创建的具有多种映射类型的索引将继续像以前在 Elasticsearch 6.x 中一样运行。Elasticsearch 7.0.0 中将完全删除映射类型。
If I understood right here: https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.htmlI either need to use:
如果我在这里理解:https: //www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html我要么需要使用:
1) PUT index?include_type_name=true
1) PUT 索引?include_type_name=true
or, better
或更好
2) PUT index/_doc/1 { "foo": "baz" }
2) PUT index/_doc/1 { "foo": "baz" }
I am stucked since I have no idea how to use either 1) or 2)
我被卡住了,因为我不知道如何使用 1) 或 2)
How can I add the parameter include_type_name=true?
如何添加参数include_type_name=true?
How can I create the right mapping without using the include_type_name parameter?
如何在不使用 include_type_name 参数的情况下创建正确的映射?
class TestIndexConfigurator extends IndexConfigurator
{
use Migratable;
/**
* @var array
*/
protected $settings = [
];
protected $name = 'test';
}
回答by WebMajstr
Earlier versions of Elasticsearch (<= 5) supported multiple types per index. That meant that you could have different data mappings for each type. With Elasticsearch 6, this was removed and you can only have single mapping type.
早期版本的 Elasticsearch (<= 5) 支持每个索引的多种类型。这意味着您可以为每种类型使用不同的数据映射。在 Elasticsearch 6 中,这被删除了,你只能有一个映射类型。
Therefore, for Elasticsearch 7 (latest release), you can add an index, setup mappings and add document like this:
因此,对于 Elasticsearch 7(最新版本),您可以像这样添加索引、设置映射和添加文档:
Create an index
PUT user
Add mapping
PUT user/_mapping { "properties": { "name": { "type": "keyword" }, "loginCount": { "type": "long" } } }
Add document(s)
PUT user/_doc/1 { "name": "John", "loginCount": 4 }
Check data in the index
GET user/_search
创建索引
PUT user
添加映射
PUT user/_mapping { "properties": { "name": { "type": "keyword" }, "loginCount": { "type": "long" } } }
添加文件
PUT user/_doc/1 { "name": "John", "loginCount": 4 }
检查索引中的数据
GET user/_search
Now, regarding the scout-elasticsearch-driver that you use, after reading the documentation you mentioned, it is simply saying that you need to create separate index configurator for each searchable model, as multiple models cannot be stored inside the same index.
现在,关于您使用的 scout-elasticsearch-driver,在阅读您提到的文档后,只是说您需要为每个可搜索模型创建单独的索引配置器,因为多个模型不能存储在同一个索引中。
So to create the index, run
所以要创建索引,运行
php artisan make:index-configurator MyIndexConfigurator
php artisan make:index-configurator MyIndexConfigurator
and then
进而
php artisan elastic:create-index App\\MyIndexConfigurator
php artisan elastic:create-index App\\MyIndexConfigurator
which will create the index in the elasticsearch for you.
这将为您在 elasticsearch 中创建索引。
To learn more about elasticsearch, I suggest you install both elasticsearch and kibana to your development machine and then play around with it in kibana - the interface is quite nice and supports autocomplete to ease the learning curve.
要了解有关 elasticsearch 的更多信息,我建议您将 elasticsearch 和 kibana 安装到您的开发机器上,然后在 kibana 中使用它 - 界面非常好,并支持自动完成以简化学习曲线。
回答by Gautham
When I tried GET product/default/_mapping
in Kibana console.
当我GET product/default/_mapping
在 Kibana 控制台中尝试时。
I kept getting this error.
我一直收到这个错误。
"Types cannot be provided in get mapping requests, unless include_type_name is set to true"
“无法在获取映射请求中提供类型,除非 include_type_name 设置为 true”
This is happening in elastic search 7.3.0. Looks like the above command is no longer supported in latest versions of elastic search.
这发生在弹性搜索 7.3.0 中。看起来最新版本的弹性搜索不再支持上述命令。
It worked for me when I remove the default from the above command.
当我从上述命令中删除默认值时,它对我有用。
GET product/_mapping