我是 Elasticsearch 的新手,我正在使用Elasticsearch Scout Driver在我的 Laravel 项目中实现它,但是在索引中插入模型对象时出现错误。
该模型是Post,制作如下:
>>> $post = App\Models\Post::first();
=> App\Models\Post {#853
id: 1,
title: "First Post",
description: "My first post",
created_at: "2017-09-13 13:31:51",
updated_at: "2018-02-16 16:23:44",
deleted_at: null,
}
在模型类中,我声明了映射选项,我报告了我的映射选项:
// Map elements to be saved in Elasticsearch
protected $mapping = [
'properties' => [
'id' => [
'type' => 'integer',
'index' => false
],
'title' => [
'type' => 'text'
],
'description' => [
'type' => 'text'
],
'created_at' => [
'type' => 'date',
'ignore_malformed' => true,
'format' => "yyyy-MM-dd HH:mm:ss"
],
'updated_at' => [
'type' => 'date',
'ignore_malformed' => true,
'format' => "yyyy-MM-dd HH:mm:ss",
],
'deleted_at' => [
'type' => 'date',
'ignore_malformed' => true,
'format' => "yyyy-MM-dd HH:mm:ss",
]
]
];
每次我打电话$post->searchable();
将我的模型放入我的 Elasticsearch 索引时,我都会遇到这个错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Mapper for [deleted_at] conflicts with existing mapping in other types:\n[mapper [deleted_at] has different [format] values]"
}
],
"type": "illegal_argument_exception",
"reason": "Mapper for [deleted_at] conflicts with existing mapping in other types:\n[mapper [deleted_at] has different [format] values]"
},
"status": 400
}
我猜问题是财产
的null
价值。我需要,因为我使用Laravel进行管理:任何其他值都会导致 Laravel 框架的软删除(查询时不检索元素)。deleted_at
deleted_at == null
soft deletion
正如你所看到的,我试图把,ignore_malformed => true
但它对我不起作用。我试图添加另一个选项null_value => NULL
但没有成功。
我哪里错了?
如何在我的 Elasticsearch 索引中插入帖子,并将deleted_at
属性设置为null
OR设置为 date with format yyyy-MM-dd HH:mm:ss
?
谢谢
PS:我使用的是 Elasticsearch 版本 6.1.2。