问题描述
我正在使用 https://github.com/babenkoivan/scout-elasticsearch-driver使用Laravel Scout实施Elasticsearch.伊万(Ivan)在Github上提到了这一点:
I am using https://github.com/babenkoivan/scout-elasticsearch-driver to implement Elasticsearch with Laravel Scout. Ivan mentions this at Github:
如果我在这里了解: https: //www.elastic.co/guide/zh-CN/elasticsearch/reference/master/removal-of-types.html 我要么需要使用:
If I understood right here: https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html I either need to use:
1)PUT索引?include_type_name = true
1) PUT index?include_type_name=true
或者更好
2)PUT索引/_doc/1{ "foo":"baz"}
2) PUT index/_doc/1{ "foo": "baz"}
我被卡住了,因为我不知道如何使用1)或2)
I am stucked since I have no idea how to use either 1) or 2)
如何添加参数include_type_name = true?
How can I add the parameter include_type_name=true?
如何在不使用include_type_name参数的情况下创建正确的映射?
How can I create the right mapping without using the include_type_name parameter?
class TestIndexConfigurator extends IndexConfigurator
{
use Migratable;
/**
* @var array
*/
protected $settings = [
];
protected $name = 'test';
}
推荐答案
Elasticsearch的早期版本(< = 5)每个索引支持多种类型.这意味着每种类型可能具有不同的数据映射.使用Elasticsearch 6时,已将其删除,并且您只能使用一种映射类型.
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 7(最新版本),您可以添加索引,设置映射并添加文档,如下所示:
Therefore, for Elasticsearch 7 (latest release), you can add an index, setup mappings and add document like this:
-
创建索引
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
现在,关于您使用的scout-elasticsearch-driver,在阅读了您提到的文档后,只是说您需要为每个可搜索模型创建单独的索引配置器,因为无法将多个模型存储在同一个索引中
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.
因此要创建索引,请运行
So to create the index, run
php artisan make:index-configurator MyIndexConfigurator
然后
php artisan elastic:create-index App\\MyIndexConfigurator
这将为您在elasticsearch中创建索引.
which will create the index in the elasticsearch for you.
要了解有关Elasticsearch的更多信息,建议您将Elasticsearch和kibana都安装到开发机器上,然后在kibana中使用它-界面非常好,并支持自动完成功能,以简化学习过程.
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.
这篇关于除非include_type_name参数设置为true,否则不能在放置映射请求中提供类型.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!