不能在 put 映射请求中提供类型,除非在 elastic search 7.6.2 的 lumen 中将 include_type_name 参数设置为 true
Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true in lumen with elastic search 7.6.2
我正在使用 https://github.com/basemkhirat/elasticsearch 包。
在 es.php 文件中,我有以下 索引
'indices' => [
'media' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 2,
'analysis' => [
'filter' => [
'custom_english_stemmer' => [
'type' => "stemmer",
'name' => "english"
],
"english_stop" => [
'type' => "stop",
'stopwords' => "_english_"
]
],
"analyzer" => [
'custom_lowercase_analyzer' => [
// 'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'english_stop',
"custom_english_stemmer"
]
]
]
]
],
'mappings' => [
'properties' => [
'id' => [
'type' => 'long',
'index' => false,
'doc_values' => false,
],
'title' => [
'type' => 'text',
"analyzer" => 'custom_lowercase_analyzer'
]
]
]
]
]
现在,当执行 php artisan es:indices:create
时,设置已创建,但映射失败并显示错误消息。
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
}
],
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
},
"status": 400
}
如何解决这个问题
您正在创建索引代码中提供类型,从索引中删除 media
类型,因为类型已弃用,请参阅 the removal of types 了解更多信息。
请注意,在 Elasticsearch 7.X 中,您仍然可以通过使用 include_type_name
参数来做一些变通来获得自定义 types
,但它不是首选,因为 types
将被完全删除在即将推出的 Elasticsearch 8.X.
为了在您的情况下使用自定义 type
创建索引,例如 media
(默认为屏幕截图中提到的 _doc
),您需要通过 include_type_name=true
索引创建、模板和映射 API,如 this official ES blog
中所述
我正在使用 https://github.com/basemkhirat/elasticsearch 包。
在 es.php 文件中,我有以下 索引
'indices' => [
'media' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 2,
'analysis' => [
'filter' => [
'custom_english_stemmer' => [
'type' => "stemmer",
'name' => "english"
],
"english_stop" => [
'type' => "stop",
'stopwords' => "_english_"
]
],
"analyzer" => [
'custom_lowercase_analyzer' => [
// 'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'english_stop',
"custom_english_stemmer"
]
]
]
]
],
'mappings' => [
'properties' => [
'id' => [
'type' => 'long',
'index' => false,
'doc_values' => false,
],
'title' => [
'type' => 'text',
"analyzer" => 'custom_lowercase_analyzer'
]
]
]
]
]
现在,当执行 php artisan es:indices:create
时,设置已创建,但映射失败并显示错误消息。
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
}
],
"type": "illegal_argument_exception",
"reason": "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
},
"status": 400
}
如何解决这个问题
您正在创建索引代码中提供类型,从索引中删除 media
类型,因为类型已弃用,请参阅 the removal of types 了解更多信息。
请注意,在 Elasticsearch 7.X 中,您仍然可以通过使用 include_type_name
参数来做一些变通来获得自定义 types
,但它不是首选,因为 types
将被完全删除在即将推出的 Elasticsearch 8.X.
为了在您的情况下使用自定义 type
创建索引,例如 media
(默认为屏幕截图中提到的 _doc
),您需要通过 include_type_name=true
索引创建、模板和映射 API,如 this official ES blog