首页 > 解决方案 > 需要帮助以启用弹性搜索查询的排序和分页

问题描述

我对弹性搜索比较陌生。我正在尝试对具有多个聚合的以下 ES 查询启用分页和排序。我尝试了复合 agg,它对排序没有帮助。以下是查询:

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "customerId.keyword": "{{customerId_value}}"
          }
        },
        {
          "query_string": {
            "query": "*{{search_query}}*",
            "minimum_should_match": "75%",
            "fields": [
              "neName.keyword^3",
              "productFamily.keyword^2",
              "productId.keyword^2",
              "ipAddress.keyword^2",
              "swVersion.keyword^2"
            ]
          }
        },
        {
          "range": {
            "lastReset": {
              "to": "now",
              "from": "{{range}}"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "unique_devices": {
      "terms": {
        "field": "neInstanceId.keyword",
        "size": 10000
      },
      "aggs": {
        "device_stats": {
          "stats": {
            "field": "lastReset"
          }
        },
        "required_fields": {
          "top_hits": {
            "size": 1,
            "_source": {
              "includes": [
                "neInstanceId",
                "neName",
                "productFamily",
                "productId",
                "swVersion",
                "ipAddress",
                "serialNumber"
              ]
            }
          }
        }
      }
    }
  }
}

期望:对所有字段进行分页和排序。感谢任何回应。

标签: elasticsearch

解决方案


推荐阅读