java - 如何将字符串列表或整数列表从spring boot保存到elasticsearch
问题描述
我只想从我的 Spring Boot 应用程序传递一个整数列表/字符串列表以保存在我的弹性搜索数据存储中。我正在通过邮递员发送请求,但它给出了以下错误。
"status": 500,
"error": "Internal Server Error",
"message": "Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [abPath] tried to parse field [null] as object, but found a concrete value]"
我的模型类abPath类变量配置如下
@Field( type = FieldType.Integer, store = true)
private List<Integer> abPath;
我的 Postman 请求属性设置如下
"abPath": [1, 2, 3]
如果我将“abPath”设置为空,则请求完成且没有任何错误
之后我找到了一种保存方法如下
public class AB{
private Integer abId;
// constructor and getter setter
}
//then i update my model
@Field( type = FieldType.Nested)
private List<AB> abPath;
//then postman request updated as follows
"abPath" : [{"abId" : 1}, {"abId" : 2}]
然后请求完成,没有任何错误..
我想知道的是,
这是将整数列表或字符串列表保存到elasticsearch中的方法吗?
还有其他更好的方法吗?
我可以保存整数列表或字符串列表而不像我一样将值包装到任何其他对象中吗?
解决方案
在我看来,您实施的方式是一个好方法。使用这种方法,我们甚至可以查询内部字段。我也以同样的方式管理它。
推荐阅读
- javascript - 在服务器端渲染 (Node/Express) 中反应 Cookie
- slack - 清除机制/从松弛中批量删除消息
- android - 如何为每个父级更改可扩展列表视图中的图像?
- javascript - 多个 3 列布局的目标中间子级
- c# - 使用 c#、NPOI 和 XSSF 工作簿计算 .xlsx 工作簿工作表的最简单方法是什么?
- symfony - 基于用户角色的登录后重定向
- c# - 实体框架 6:删除具有多对多关系的实体
- docker - 用户定义的 docker 网络中的 Docker 容器 - 只能从主机访问
- javascript - 单击时切换颜色链接颜色
- entity-framework - EF6 可以在 lambda 查询后更新模型/表吗?