Elastic Search - 使用 NEST 创建查询

Elastic Search - Creating Query with NEST

鉴于查询:

GET places/_search
    {
      "query": {
        "match_all": {}
      },
      "size": 0,
      "aggs": {
        "filtered_cells": {
          "filter": {
            "geo_bounding_box": {
              "loc": {
                "top_left": {
                  "lat": 53.480950,
                  "lon": -2.2374300
                },
                "bottom_right": {
                  "lat": 51.5085300,
                  "lon": -0.1257400
                }
              }
            }
          },
          "aggs": {
            "cells": {
              "geohash_grid": {
                "field": "loc",
                "precision": "precision"
              },
              "aggs": {
                "center_lat": {
                  "avg": {
                    "script": "doc['loc'].lat"
                  }
                },
                "center_lon": {
                  "avg": {
                    "script": "doc['loc'].lon"
                  }
                }
              }
            }
          }
        }
      }
    }

我正在尝试将此查询移动到我正在开发的一段代码中,但我在使用 NEST 库构建上述查询时遇到问题。

这是我目前的情况:

var s = new SearchDescriptor<FacebookGraphResponse>()
                .MatchAll()
                .From(0)
                .Size(10)
                .Filter(filter => filter
                    .GeoBoundingBox(f => f.Loc, 53.480950, -2.2374300, 51.5085300, -0.1257400)
                );

有没有人能就我如何将此查询转换为 nest 提供任何意见,因为我目前很困惑。

非常感谢

解决了!

var s = new SearchDescriptor<FacebookGraphResponse>()
                .MatchAll()
                .Size(0)
                .Aggregations(aggs => aggs
                    .Filter("filtered_cells", f => f
                        .Filter(f1 => f1
                            .GeoBoundingBox(bb => bb.Loc, -2.2374300, 53.480950, -0.1257400, 51.5085300))
                        .Aggregations(a => a
                            .GeoHash("cells", geo => geo
                                .GeoHashPrecision(GeoHashPrecision.Precision10)
                                .Field("loc")
                                .Aggregations(a1 => a1
                                    .Average("center_lat", x => x.Script("doc['loc'].lat"))
                                    .Average("center_lon", x => x.Script("doc['loc'].lon")))))));