Mapping Set to Strict, Dynamic Introduction of [_Class] Within [_Doc] Is Not Allowed

栏目: IT技术 · 发布时间: 3年前

内容简介:这个异常非常的“有趣”,因为我GG了一圈,竟然一个相关的结果都没有。。。一开始以为自己碰到疑难杂症了,深呼吸一口打算去翻源码了。结果“非常不小心”被我在官方文档上以“_class”作为关键字检索到了相关的内容,好尴尬啊~官方在

这个异常非常的“有趣”,因为我GG了一圈,竟然一个相关的结果都没有。。。一开始以为自己碰到疑难杂症了,深呼吸一口打算去翻源码了。

结果“非常不小心”被我在官方文档上以“_class”作为关键字检索到了相关的内容,好尴尬啊~

官方在 Mapping Rules 这一章节中,提到了 Type Hints 的概念:

Mapping uses type hints embedded in the document sent to the server to allow generic type mapping. Those type hints are represented as _class attributes within the document and are written for each aggregate root.

在我这个新手看来,应该是Spring-Data-Elasticsearch库对将Elasticsearch返回的结果自动封装成POJO时需要的一个标识。很自然也很直观,对吧~

恶心就恶心在,如果你和我一样是初次使用,并且在Elasticsearch中将Index的Mapping设置成严格的静态类型,就会导致本文标题的这个异常。然后你就会开始发蒙, _class 这个属性是什么时候产生的。。。

解决这个异常的方法很简单,在我们的Mapping中增加_class属性的定义即可:

...
"mappings": {
        "dynamic": "strict",
        "properties": {
          "_class" : {
              "type" : "keyword"
            },
....

奇怪的是,全世界的开发者好像都没有碰到这个问题。。。是我确实太菜了吧可能。。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms in C, Parts 1-4

Algorithms in C, Parts 1-4

Robert Sedgewick / Addison-Wesley Professional / 1997-9-27 / USD 89.99

"This is an eminently readable book which an ordinary programmer, unskilled in mathematical analysis and wary of theoretical algorithms, ought to be able to pick up and get a lot out of.." - Steve Sum......一起来看看 《Algorithms in C, Parts 1-4》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具