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 } }
Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。