elasticsearch - 查询嵌套字段时 Elasticsearch 返回错误
问题描述
我在弹性搜索中有一些索引数据,我正在尝试使用邮递员使用以下请求获取数据。
{
"_source": ["_id"],
"query": {
"nested" : {
"path" : "data",
"query" : {
"bool" : {
"must" : [
{ "match" : {"data.id": "3456"} }
]
}
},
"score_mode" : "avg"
}
}
}
但我得到了例外
[nested] nested object under path [data] is not of nested type
我的映射定义就像
{
"property": {
"mappings": {
"property": {
"properties": {
"data": {
"properties": {
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"point": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
},
"popId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
知道为什么会这样吗?
解决方案
Fielddata
是一个对象,所以它应该是nested类型。
请尝试以下映射配置:
PUT property
{
"mappings": {
"property": {
"properties": {
"point": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
},
"popId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data": {
"type": "nested",
"properties": {
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
您必须删除索引并使用新的映射配置重新创建它。
如果您不想删除数据,这可能会有所帮助
希望能帮助到你
推荐阅读
- python - Python,用于过滤元素的正则表达式以列表中的样式结尾
- javascript - 上周使用 javascript 的开始日期和结束日期没有给出所需的结果
- ios - 我无法在 UICollectionView 中显示图像
- javascript - 我们如何在 Salesforce Lightning UI 中使用 JS 的 web worker?
- c# - dotnet 在 VSTS 中仅发布解决方案中的一个项目
- c# - 如何在 iis 上的 android 客户端和 c# 服务器之间进行通信?
- javascript - Vue.js + Element-ui 上传:如何调用 ClearFiles 或 Abort 方法
- python - 如何在 TF Lite 中添加预处理步骤
- amazon-web-services - 对 AWS 数据库的成本感到困惑
- c# - 如何确保 Networkstream 在返回 C# 之前读取所有数据