问题描述
我的 es 映射:有一个“id”字段和一个名为“my_field”的嵌套字段,其中包含四个嵌套字段。
{
"my_index": {
"mappings": {
"dynamic": "strict","properties": {
"id": {
"type": "long"
},"my_field": {
"type": "nested","properties": {
"x": {
"type": "long"
},"y": {
"type": "long"
},"z": {
"type": "long"
},"a": {
"type": "double"
},"b": {
"type": "long"
}
}
}
}
}
}
}
我正在尝试使用嵌套查询限制“x > 15”或“a > 0.5”以及内部命中大小限制(此处为 20)获取两个文档 ID:11111 和 id:22222。
这是我的查询,但不起作用 ==,它什么都不返回...
{
"_source": false,"query": {
"bool": {
"must": {
"nested": {
"inner_hits": {
"size": 20
},"path": "my_field","query": {
"bool": {
"should": [
{
"range": {
"x": {
"from": 15,"include_lower": true,"include_upper": true,"to": null
}
}
},{
"range": {
"a": {
"from": 0.5,"to": null
}
}
}
]
}
}
}
},"should": [
{
"term": {
"id": 11111
}
},{
"term": {
"id": 22222
}
}
]
}
},"timeout": "5000ms","track_total_hits": true
}
解决方法
请在查询中使用圆点表示法来包含完整路径,例如
"range": {
"my_field.x": { "from": ... }
}