elasticsearch - 具有布尔类型的多字段的文档在创建期间失败
问题描述
在 v5.5 中,我们有以下工作正常的映射
PUT multiple_datatypes
{
"mappings": {
"_doc": {
"properties": {
"user_data": {
"type": "text",
"fields": {
"numeric": {
"type": "double",
"ignore_malformed": true
},
"date": {
"type": "date",
"ignore_malformed": true
}
"logical": {
"type": "boolean",
}
}
}
}
}
}
在 6.2 中,相同的映射失败并出现错误
HTTP/1.1 400 Bad Request]\n{\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason \":\"解析[user_data.logical]失败\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"解析[user_data.logical]失败\",\ "caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"解析值失败 [auto_directorUrl] 因为只允许 [true] 或 [false]
输入数据是一个字符串“auto_directorURL”,但它失败了。ignore_malformed 标志不适用于布尔类型。但是,这在 v5.5 中有效。我发现在 v6.2 中,ES 严格执行布尔类型值作为“真”或“假”。但这在多字段中失败,因为它没有 ignore_malformed 标志。解决方案是什么?这是 BWC 休息和错误吗
解决方案
这是一个宣布的重大变化。
另一种方法是使用带有转换处理器的摄取节点将该字段的布尔值存储到另一个布尔字段中:
PUT _ingest/pipeline/boolean-pipeline
{
"description": "converts the content of the field to a boolean value",
"processors" : [
{
"convert" : {
"field" : "user_data",
"target_field" : "user_data_boolean",
"type": "boolean",
"on_failure" : [
{
"set" : {
"field" : "user_data_boolean",
"value" : false
}
}
]
}
}
]
}
然后您可以使用该管道索引数据
PUT test/doc/1?pipeline=boolean-pipeline
{
"user_data": "true"
}
PUT test/doc/2?pipeline=boolean-pipeline
{
"user_data": "auto_directorURL"
}
结果,您将获得以下索引数据,这几乎是您所期望的:
"hits" : [
{
"_index" : "test",
"_type" : "doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"user_data" : "auto_directorURL",
"user_data_boolean" : false
}
},
{
"_index" : "test",
"_type" : "doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"user_data" : "true",
"user_data_boolean" : true
}
}
]
推荐阅读
- ruby-on-rails - 在 group_by 中执行多个循环的更好方法
- typescript - 过滤数组时,Typescript 错误“在类型上找不到带有“字符串”类型参数的索引签名。
- double - 双打的 GLSL Pow 函数
- php - 谁能解释为什么我的 php 文件没有在 var/www/html 中运行?
- python - 读取 JSON 文件时不能使用“from”属性
- python - 无法通过 Postman 向 Django 发送 GET 请求
- python - 如何检查三个参数对 Python 神经网络中 3 个输出的同时影响?
- android - 在 android java 代码中查找 Xamarin 类名或命名空间
- php - PHP CSV到带有标题和ID的数组作为组键
- java - 如何合并流中的字符串并返回另一个流