PUT blog { "mappings": { "dynamic":"strict", "properties": { "title":{ "type": "text" }, "age":{ "type":"long" } } } }
然后向 blog 中索引中添加数据:
PUT blog/_doc/2 { "title":"1111", "date":"2020-11-11", "age":99 }
在添加的文档中,多出了一个 date 字段,而该字段没有预定义,所以这个添加操作就回报错:
{ "error" : { "root_cause" : [ { "type" : "strict_dynamic_mapping_exception", "reason" : "mapping set to strict, dynamic introduction of [date] within [_doc] is not allowed" } ], "type" : "strict_dynamic_mapping_exception", "reason" : "mapping set to strict, dynamic introduction of [date] within [_doc] is not allowed" }, "status" : 400 }
动态映射还有一个日期检测的问题。
例如新建一个索引,然后添加一个含有日期的文档,如下:
PUT blog/_doc/1 { "remark":"2020-11-11" }
添加成功后,remark 字段会被推断是一个日期类型。
image-20201106203240406
此时,remark 字段就无法存储其他类型了。
PUT blog/_doc/1 { "remark":"javaboy" }
此时报错如下:
{ "error" : { "root_cause" : [ { "type" : "mapper_parsing_exception", "reason" : "failed to parse field [remark] of type [date] in document with id '1'. Preview of field's value: 'javaboy'" } ], "type" : "mapper_parsing_exception", "reason" : "failed to parse field [remark] of type [date] in document with id '1'. Preview of field's value: 'javaboy'", "caused_by" : { "type" : "illegal_argument_exception", "reason" : "failed to parse date field [javaboy] with format [strict_date_optional_time||epoch_millis]", "caused_by" : { "type" : "date_time_parse_exception", "reason" : "Failed to parse with all enclosed parsers" } } }, "status" : 400 }
要解决这个问题,可以使用静态映射,即在索引定义时,将 remark 指定为 text 类型。也可以关闭日期检测。
PUT blog { "mappings": { "date_detection": false } }
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。