Elasticsearch - 如何在不损害每个链接的情况下获得过滤响应 entity/field

Elasticsearch - How to get filtered response without harming the links of each entity/field

所以假设我有一个像下面这样的映射结构

{
  "mappings": {
    "users": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

并且我已将以下内容编入索引

users/52

 {
    "user": [
        {
            "id": 52,
            "first": "John",
            "last": "Smith",
            "age": 21,
            "school": {
                "name": "STC",
                "location": "Mt LV",
                "District": "Western"
            }
        }
    ]
}

users/57

{
    "user": [
        {
            "id": 57,
            "first": "Alice",
            "last": "White",
            "age": 25,
            "school": {
                "name": "HFC",
                "location": "DEH WLA",
                "District": "Western"
            }
        }
    ]
}

如果我想使用 id 获取某些字段并且不破坏彼此之间的关系 link 怎么办?

举个例子

如果id == 57

那么 return 结构应该只包含 "first","age","school.name","school.District"

{
    "user": [
        {
            "first": "Alice",
            "age": 25,
            "school": {
                "name": "HFC",
                "District": "Western"
            }
        }
    ]
}

您应该如何在 Elasticsearch 中为此类响应编写查询?

在 Elasticsearch 中使用 response filtering。根据您的情况,GET 请求看起来像 GET /_search?user=57&filter_path=first,age,school.name,school.District