[英]Elasticsearch and Laravel scout-elasticsearch-driver timestamps malformed error
I have successfully configured ES and the babenkoivan/scout-elasticsearch-driver, but run into this error when adding new entries to the DB: 我已经成功配置了ES和babenkoivan / scout-elasticsearch-driver,但是在向数据库添加新条目时遇到此错误:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse [updated_at.raw]"}],"type":"mapper_parsing_exception","reason":"failed to parse [updated_at.raw]","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: \"2018-07-13 07:52:02\" is malformed at \" 07:52:02\""}},"status":400}
I have set the format in the mapping like this, and according to the ES docs this format should work: 我已经在映射中设置了这种格式,根据ES文档,这种格式应该可以工作:
protected $mapping = [
'properties' => [
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-DD HH:mm:ss',
'fields' => [
'raw' => [
'type' => 'date',
'index' => 'not_analyzed'
]
]
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-DD HH:mm:ss',
'fields' => [
'raw' => [
'type' => 'date',
'index' => 'not_analyzed'
]
]
]
]
];
https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html#multiple-date-formats https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/date.html#multiple-date-formats
Is there something I'm missing here? 我在这里想念什么吗?
In your mapping you defined a custom date format ( yyyy-MM-DD HH:mm:ss
) for created_at
and updated_at
. 在映射中,您为
created_at
和updated_at
定义了自定义日期格式( yyyy-MM-DD HH:mm:ss
)。 The raw
fields instead are a date type too, but use the default format (which according the doc is date_optional_time , meaning yyyy-MM-DD'T'HH:mm:ss
). 相反,
raw
字段也是日期类型,但使用默认格式( 根据doc,它是date_optional_time ,表示yyyy-MM-DD'T'HH:mm:ss
)。
This means that the former expects 2018-07-13 07:52:02
, while the latter 2018-07-13T07:52:02
, so you indexing can't possibly avoid breaking one of the two. 这意味着前者期望
2018-07-13 07:52:02
,而后者2018-07-13T07:52:02
,因此索引无法避免打破两者之一。
Now, the use of multi-fields is meant to index values in different ways, but what you are doing is to create a new field raw with basically the same properties of the base value (they are both date types, except for the inconsistency in the format, of course). 现在,使用多字段意味着以不同的方式为值建立索引,但是您要做的是创建一个新的原始字段,该字段具有基本相同的基本值属性(它们都是日期类型,除了格式,当然)。
So, in my opinion you options are: 因此,我认为您可以选择:
if you don't have any specific use for raw you can remove it from the mapping. 如果您对raw没有任何特定用途,则可以将其从映射中删除。 Sorting and matching works well with the base field.
排序和匹配与基本字段配合良好。
"created_at": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss"}
if you need to keep the original string format (as "raw" may suggest) you can use a keyword type 如果您需要保留原始字符串格式(如“ raw”可能会建议),则可以使用关键字类型
"created_at": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss", "fields": {"raw": {"type": "keyword"}}}
if you really need the raw field as is, you have to specify a format that is consistent with the other one: 如果您确实需要原始字段,则必须指定与另一种格式一致的格式:
"created_at": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss", "fields": {"raw": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss"}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.