[英]Correct syntax for “must not” search rule on Laravel Scout Elasticsearch “babenkoivan/scout-elasticsearch-driver” package
[英]Elasticsearch and Laravel scout-elasticsearch-driver timestamps malformed error
我已經成功配置了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}
我已經在映射中設置了這種格式,根據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/zh-CN/elasticsearch/reference/current/date.html#multiple-date-formats
我在這里想念什么嗎?
在映射中,您為created_at
和updated_at
定義了自定義日期格式( yyyy-MM-DD HH:mm:ss
)。 相反, raw
字段也是日期類型,但使用默認格式( 根據doc,它是date_optional_time ,表示yyyy-MM-DD'T'HH:mm:ss
)。
這意味着前者期望2018-07-13 07:52:02
,而后者2018-07-13T07:52:02
,因此索引無法避免打破兩者之一。
現在,使用多字段意味着以不同的方式為值建立索引,但是您要做的是創建一個新的原始字段,該字段具有基本相同的基本值屬性(它們都是日期類型,除了格式,當然)。
因此,我認為您可以選擇:
如果您對raw沒有任何特定用途,則可以將其從映射中刪除。 排序和匹配與基本字段配合良好。
"created_at": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss"}
如果您需要保留原始字符串格式(如“ raw”可能會建議),則可以使用關鍵字類型
"created_at": {"type": "date", "format": "yyyy-MM-DD HH:mm:ss", "fields": {"raw": {"type": "keyword"}}}
如果您確實需要原始字段,則必須指定與另一種格式一致的格式:
"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.