partial_fields执行nested过滤/查询时是否可以使用该参数?
例如,此查询将仅返回我要查找的字段hits:
{
"query": {
"filtered": {
"query": {
"ids": {
"type": "users",
"values": [
"111"
]
}
},
"filter": {
"nested": {
"path": "entitlements",
"filter": {
"bool": {
"must": [
{
"term": {
"program": "program-a"
}
}
]
}
},
"inner_hits": {
"size": 999
}
}
}
}
},
"partial_fields": {
"partial": {
"include": [
"entitlements.accountNumber",
"entitlements.name",
"entitlments.numbers"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是该inner_hits部分没有返回任何字段.
"inner_hits": {
"entitlements": {
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "myGreatIndex",
"_type": "users",
"_id": "111",
"_nested": {
"field": "entitlements",
"offset": 0
},
"_score": 1,
"fields": {
"partial": [
{}
]
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法申请这个inner_hits?
在该inner_hits部分中,您可以使用源过滤.partial_fields将为外命中和工作_source的inner_hits.
所以你可以这样指定inner_hits:
"inner_hits": {
"size": 999,
"_source": [
"accountNumber",
"name",
"numbers"
]
}
Run Code Online (Sandbox Code Playgroud)
但请注意,在inner_hits结果中,您仍会获得一个空partial数组,但您需要的字段将显示在该_source部分中.
另外值得注意的是,如果您partial_fields使用不合格的名称指定(见下文),则部分字段将显示在inner_hits结果中,但不再显示在外部命中中.所以你需要找出最适合你的方法.
"partial_fields": {
"partial": {
"include": [
"accountNumber",
"name",
"numbers"
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3851 次 |
| 最近记录: |