目前,下面的查询会删除单个字段“名称”上的重复项,但我们需要所有字段的top_hits结果:“名称”,“venueName”,“venueTown”。在不发送3个请求并将“字段”设置为“venueName”和“venueTown”的情况下,是否可以在一个查询中实现?

{
  "aggs": {
    "query": {
      "terms": {
        "field": "name"
      }
     ,
      "aggs": {
        "top": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  },
    "size": 0,
  "query": {

          "multi_match": {
            "query": "LAURA",
            "operator": "OR",
            "fields": [
              "name",
              "venueName",
              "venueTown"
            ]
          }
  }
}

最佳答案

如果我理解正确,则可以编写热门热门的多个汇总。

{
  "query": {
    "multi_match": {
      "query": "LAURA",
      "fields": [
        "name",
        "venueName",
        "venueTown",
      ]
    }
  },
  "aggs": {
    "name": {
      "terms": {
        "field": "name"
      },
      "aggs": {
        "top": {
          "top_hits": {
            "size": 1
          }
        }
      }
    },
    "venue_name": {
      "terms": {
        "field": "venueName"
      },
      "aggs": {
        "top": {
          "top_hits": {
            "size": 1
          }
        }
      }
    },
    "venue_town": {
      "terms": {
        "field": "venueTown"
      },
      "aggs": {
        "top": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

09-18 09:43