术语聚合嵌套在另一个术语聚合中

时间:2018-03-19 15:01:47

标签: nest elasticsearch-5

您如何在NEST中实施以下请求? 我正在努力将“条款”汇总放在另一个“条款”中。

http://localhost:9200/my_index/responses/_search

{
    "size":0,
    "aggs":{
        "FILTER":{
            "filter":{"term":{"field":{"value":"INPUT_VARIABLE_OF_THE_METHOD"}}},
            "aggs":{
                "TERMS_ROWS":{
                    "terms":{
                        "field":"row"
                    },
                    "aggs": {
                        "TERMS_COLUMNS": {
                            "terms": {
                                "field": "column"
                            }
                        }
                    }
                }
            }
        }
    }
}

使用Elasticsearch 5.4 NEST API版本5.3.0

我的映射:

{
"responses": {
   "dynamic": "strict",
   "_parent": {
      "type": "panelists"
   },
   "_routing": {
      "required": true
   },
      "properties": {
         "column": {
            "type": "text",
            "analyzer": "index_analyzer_text_value",
            "fielddata": true
         },
         "field": {
            "type": "keyword"
         },
         "row": {
            "type": "text",
            "analyzer": "index_analyzer_text_value",
            "fielddata": true
         }
  }
}

我的设置:

{
    "hoard_v0.2_2018-03-19_6dcb7ba5eea448b99f21837a52b5699c": {
        "settings": {
            "index": {
                "mapping": {
                    "total_fields": {
                        "limit": "10000"
                    }
                },
                "number_of_shards": "8",
                "provided_name": "hoard_v0.2_2018-03-19_6dcb7ba5eea448b99f21837a52b5699c",
                "creation_date": "1521447172612",
                "analysis": {
                    "analyzer": {
                        "index_analyzer_text_value": {
                            "filter": [
                                "lowercase"
                            ],
                            "type": "custom",
                            "tokenizer": "keyword"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "TmEBCNHXT_uN5N6q5XbNtw",
                "version": {
                    "created": "5040099"
                }
            }
        }
    }
}

使用Elasticsearch 5.4 NEST API版本5.3.0

谢谢!

1 个答案:

答案 0 :(得分:0)

发现它!

var columnAggregation = new TermsAggregation("COLUMN_TERMS")
                {
                    Fie`enter code here`ld = "column",
                    Size = GetSize(termsItem.Limit)
                };

searchRequest.Aggregations(a2 => a2
                            .Filter("FILTER", fAgg => fAgg
                                .Filter(f => f
                                    .Term("field", termsItem.Field)
                                 )
                                .Aggregations(a3 => a3
                                    .Terms("TERMS_ROWS", a4 => a4
                                        .Field("row")
                                        .Aggregations( a5 => a5
                                            .Terms("TERMS_COLUMNS", a6 => columnAggregation)
                                        )
                                    )
                                )
                            )
                )