我正在使用https://github.com/babenkoivan/scout-elasticsearch-driverLaravel Scout实现Elasticsearch。Ivan在Github上提到:
在Elasticsearch 6.0.0或更高版本中创建的索引只能包含单个映射类型。在5.x中创建的具有多个映射类型的索引将继续在Elasticsearch 6.x中运行。Elasticearch 7.0.0中将完全删除映射类型。
如果我在这里理解正确的话:https://www . elastic . co/guide/en/elastic search/reference/master/remove-of-types . html我要么需要使用:
或者,更好:
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的早期版本(
因此,对于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,在阅读了您提到的文档后,它只是说您需要为每个可搜索的模型创建单独的索引配置器,因为多个模型不能存储在同一个索引中。
因此,要创建索引,请运行
< code > PHP artisan make:index-configurator MyIndexConfigurator
然后呢?
< code > PHP artisan elastic:create-index App \ \ MyIndexConfigurator
这将在弹性搜索中为您创建索引。
要了解有关 elasticsearch 的更多信息,我建议您在开发机器上同时安装 elasticsearch 和 kibana,然后在 kibana 中使用它 - 界面非常好,支持自动完成以简化学习曲线。
当我在 Kibana 控制台中尝试 GET 产品/默认/_mapping
时。
我一直收到此错误。
除非include_type_name设置为true,否则无法在get映射请求中提供类型
这在弹性搜索 7.3.0 中发生。看起来最新版本的弹性搜索不再支持上述命令。
当我从上面的命令中删除默认值时,它对我起了作用。
GET product/_mapping
我收到了同样的错误,如“除非include_type_name参数设置为true,否则无法在put映射请求中提供类型”
您必须在对象中添加“include_type_name:true”
在代码上方修复此问题
let type = true
return await esClient.indices.putMapping({
index:indexName,
type:mappingType,
body:mapping,
include_type_name:type
});