以下Elasticsearch(版本7.4.0)嵌套聚合查询的等效Java代码是什么?

时间:2019-11-09 05:53:24

标签: json java-8 elasticsearch-aggregation elasticsearch-query elasticsearch-7

Given是一个Elasticsearch(版本7.4.0)查询,在嵌套字段上聚合。我查看了所有文档,但找不到任何可以解释将使用的等效Java函数的内容。

架构如下:

"mappings": {
        "_doc": {
            "dynamic": "false",
            "properties": {
                "id": {
                    "type": "text"
                },
                "name": {
                    "type": "text",
                    "fielddata": True
                },

                "amenities": {
                    "type": "nested",
                    "fielddata": True,
                    "properties": {
                        "id": {
                            "type": "long"
                        },
                        "name": {
                            "type": "text"
                        }
                    }
                }}

对此的Elasticsearch查询如下:

{

"aggs": {

    "amenities": {
        "nested": {
            "path": "amenities"
        },
        "aggs": {
            "amn": {
                "terms": {
                    "field": "amenities.name.raw"
                },
                "aggs": {
                "id": {"top_hits": {"size": 1, "_source": {"include": ["amenities.id"]}}}
                }
            }
        }
    }
}
}

与Java(JDK-1.8)中的上述查询等效吗?

0 个答案:

没有答案