php - 不能在放置映射请求中提供类型,除非include_type_name参数在具有 Elasticsearch 的流明中设置为true 7.6.2

标签 php elasticsearch lumen elasticsearch-7

我正在使用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时,会创 build 置,但映射失败并显示一条错误消息。
{
  "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
}

enter image description here

如何解决这个问题

最佳答案

您要在创建索引代码中提供类型,请从索引中删除media类型,因为不建议使用类型,有关更多信息,请参见the removal of types

请注意,在Elasticsearch 7.X中,您仍然可以通过设置types参数来采取一些解决方法以自定义include_type_name,但由于在即将发布的Elasticsearch 8.X中types将被完全删除,因此它不是首选。

为了在您的情况下使用带有自定义type的索引(例如media(默认为屏幕截图中提到的_doc))创建索引,您需要将include_type_name=true传递给this official ES blog中提到的索引创建,模板和映射API

关于php - 不能在放置映射请求中提供类型,除非include_type_name参数在具有 Elasticsearch 的流明中设置为true 7.6.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61485970/

相关文章:

java - ElasticSearch funtion_score 类似 Solr 中的查询

php - Lumen MySQL 查询未按预期处理 UTF8 值

java - Web 服务中使用的 ElasticSearch 抛出 OverlappingFileLockException

elasticsearch - Elasticsearch constant_score不支持multi_match

php - 我该如何解决 “Deprecated: Function eregi() is deprecated”错误

php - 设置文件的日期和时间

authentication - 方法 Illuminate\Auth\RequestGuard::attempt 不存在

laravel - 流明简单的路由请求不起作用

php - 积分排名系统

php - 通过XPath直接显示文本内容?