Php 为什么在Elasticsearch 7中创建索引时创建映射会导致文档索引时映射更新被拒绝?

Php 为什么在Elasticsearch 7中创建索引时创建映射会导致文档索引时映射更新被拒绝?,php,laravel-scout,elasticsearch-7,Php,Laravel Scout,Elasticsearch 7,我目前正在尝试将数据库中条目的日期字段作为Elasticsearch索引中的“文本”处理。我想通过在索引创建命令的主体中添加一个“mappings”字段来实现这一点,但在过去几天中,当我试图让它工作时,遇到了一系列越来越令人沮丧的问题 使用此搜索的项目将使用php编码,并使用Laravel框架。该项目使用Laravel Scout,我创建了一个自定义驱动程序,以便扩展Scout以使用Elasticsearch实现 此外,我还向php artisan添加了一个命令,允许创建Elasticsearc

我目前正在尝试将数据库中条目的日期字段作为Elasticsearch索引中的“文本”处理。我想通过在索引创建命令的主体中添加一个“mappings”字段来实现这一点,但在过去几天中,当我试图让它工作时,遇到了一系列越来越令人沮丧的问题

使用此搜索的项目将使用php编码,并使用Laravel框架。该项目使用Laravel Scout,我创建了一个自定义驱动程序,以便扩展Scout以使用Elasticsearch实现

此外,我还向php artisan添加了一个命令,允许创建Elasticsearch索引。此命令类具有默认分析和筛选器,但也可以基于每个模型检查为其创建索引的模型是否定义了自定义分析、筛选器或映射,并相应地合并了数组的各个部分

在本例中,我希望用于索引的映射是:

        'mappings' => [
            'date_detection' => 'false',
            'properties' => [
                'startdate' => [
                    'type' => 'text'
                ]
            ]
        ]
这不起作用。最初,我只是刷新索引(通常使用Artisan::call重新创建要自动刷新的模型的索引)并重新导入映射时,不会发生任何更改,而且我会遇到错误,因为我试图查询一个字段上的文本,该字段是“日期”格式的“日期”。当我尝试分离刷新和索引创建时,将使用更新的映射创建索引,但在尝试导入文档时会导致错误:

  Elasticsearch\Common\Exceptions\BadRequest400Exception 

  {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [registrations] as the final mapping would have more than 1 type: [_doc, registrations]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [registrations] as the final mapping would have more than 1 type: [_doc, registrations]"},"status":400}

  at vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632
    628|             $exception = new ScriptLangNotSupportedException($responseBody. $statusCode);
    629|         } elseif ($statusCode === 408) {
    630|             $exception = new RequestTimeout408Exception($responseBody, $statusCode);
    631|         } else {
  > 632|             $exception = new BadRequest400Exception($responseBody, $statusCode);
    633|         }
    634| 
    635|         $this->logRequestFail($request, $response, $exception);
    636| 

      +9 vendor frames 
  10  app/Engines/ElasticSearchEngine.php:33
      Elasticsearch\Client::index([])

      +1 vendor frames 
  12  app/Engines/ElasticSearchEngine.php:34
      Illuminate\Support\Collection::each(Object(Closure))
我尝试将映射设置为
'dynamic'=>false
,这样当文档被索引时,映射就不会更新,因为在自定义映射中没有我定义的所有字段,我得到了相同的错误。我尝试将所有字段添加到映射中,与我在自动生成映射后检查映射时的显示完全相同,因为我没有定义自定义映射,只是更改了“star date”字段的属性,我得到了相同的错误。我甚至尝试完全按照自动生成映射时的样子复制映射,这样文档索引就没有理由在将动态映射设置为false和不设置为false的情况下更新映射,并得到相同的错误。 对于代码的相关部分,creation index命令的handle()如下所示:

    if (!class_exists($model = $this->argument('model'))) {
        return $this->error("No such model, {$model}, exists");
    }

    $model = new $model;

    try {
        $this->client->indices()->create([
            'index' => $model->searchableAs(),
            'body' => array_merge([
                'settings' => [
                    'index' => [
                        'analysis' => [
                            'filter' => $this->getFilters($model),
                            'analyzer' => $this->getAnalyzers($model)
                        ]
                    ]
                ]
            ], $this->getMappings($model))
        ]);
    } catch (\Exception $exception) {
        return $this->error($exception->getMessage());
    }
引擎中的update()命令(发生错误的地方)如下所示

public function update($models)
{
    $models->each(function ($model) {
        $params = $this->getRequestBody($model, [
            'id' => $model->id,
            'body' => $model->toSearchableArray()
        ]);

        $this->client->index($params);
    });
}
虽然我在网上看到了很多关于冲突映射错误的问题,但我看到的所有问题都与ES6有关,其中必须在“映射”中指定映射类型作为字段,或者使用我已经尝试过的方法解决。有没有人知道是什么导致了这个问题和/或我应该在我的代码中寻找解决这个问题的方法?我已经没有主意了

提前感谢大家的帮助