无论才能、知识多么卓著,如果缺乏热情,则无异纸上画饼充饥,无补于事。

6.X版本中java实体FieldType.Nested映射不生效的问题

Elasticsearch | 作者 niujiang777 | 发布于2021年11月12日 | 阅读数:3400

springboot2.2整合ES6.8遇到的问题
索引有用到嵌套类型nested,java类中,注解了类型
@Field(type = FieldType.Nested, includeInParent = true,index = true, store = true)
private List<Param> params;
但是创建完之后,类型并没有生效,查询索引的结果
"params": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
params并没有type,在通过索引搜索的时候,控制台报异常
AggregationExecutionException[[nested] nested path [params] is not nested]
在网上查了资料,说的是springboot和es的对象映射有BUG,nested类型的无法正常映射,建议用手动通过json映射解决。
我创建了json文件
{
"mappings": {
"goods": {
"id": {
。。。。。。。
params": {
"type": "nested",
"properties": {
"name": {
"type": "keyword",
"fielddata": true,
"index":"not_analyzed"
},
"value": {
"type": "keyword",
"fielddata": true,
"index":"not_analyzed"
}
}
}
。。。。。。。。。
并且在java映射类上加上注解
@Mapping(mappingPath = "goodsIndex.json")
但是没有用,创建的索引params还是没有type,搜索异常依旧。
求大神指点迷津。
已邀请:

nofearinmyheat - 新时代农民工

赞同来自: niujiang777

创建索引json没问题,数据insert可以也转成json导入,应该是没问题的;嵌套对象索引的查询需要指定path,查询确定是正确的吗

要回复问题请先登录注册