在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 \”,\“原因\“:\”无法解析[user_data.logical] \“}],\” type \“:\” mapper_parsing_exception \“,\”原因\“:\”无法解析[user_data.logical] \“,\ “ caused_by \”:{\“ type \”:\“ illegal_argument_exception \”,\“ reason \”:\“由于仅允许[true]或[false],无法解析值[auto_directorUrl]
输入数据为字符串“ auto_directorURL”,但失败。ignore_malformed标志不适用于布尔类型。但是,这在v5.5中有效。我发现在v6.2中,ES严格将布尔类型值强制为“ true”或“ false”。但这在多字段中失败,因为它没有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 } } ]