如果您可以保留除嵌套字段之外的所有根字段,然后在嵌套字段中仅包含匹配的内部匹配,那么我们可以通过指定稍微复杂一些的源过滤参数来重用之前的答案,例如:
{ "_source": { "includes": [ "*" ], "excludes": [ "users" ] }, "query": { "nested": { "path": "users", "inner_hits": { <---- this is where the magic happens "_source": [ "name", "surname" ] }, "query": { "bool": { "must": [ { "term": { "users.name": "abc" } } ] } } } }}


