elasticsearch 嵌套聚合查询中的嵌套聚合

7uzetpgm  于 7个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(99)

在Elastic Search 7.1中有以下(缩写)文档。重点是questions.influencerReponse.selectAllThatApplyResponses路径。

{
  "questions": [
    {
      "questionId": "79cfc6e7-731e-4d83-9dd6-82f4f39fff03",
      "questionKind": "select_all_that_apply",
      "questionText": "Have you heard of any of the following charities?",
      "questionOptions": {
        "1": "Plan International",
        "2": "Young Women's Trust",
        "3": "Women For Refugee Women",
        "4": "The FPA"
      },
      "influencerReponse": {
        "questionId": "79cfc6e7-731e-4d83-9dd6-82f4f39fff03",
        "questionKind": "select_all_that_apply",
        "text": null,
        "questionOrder": 3,
        "order": null,
        "shortAnswerResponse": null,
        "viewerSentimentResponse": null,
        "yesNoResponse": null,
        "selectAllThatApplyResponses": [
          {
            "key": "2",
            "value": "Young Women's Trust"
          }
        ]
      }
    }
  ]
}

字符串
我想得到关键字或值的聚合,两者都是关键字类型。我以前完成了,但不是在selectAllThatApplyResponses嵌套类型的级别。
这就是我到目前为止,抛出下面的错误。

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "sponsorshipId": {
                            "value": "33c7140f-23ae-46f2-a0fe-49e2251114e4"
                        }
                    }
                }
            ]
        }
    },
    "track_total_hits": true,
    "size": 0,
    "aggs": {
        "select_all_that_apply_responses": {
            "nested": {
                "path": "questions"
            },
            "aggs": {
                "filter_types": {
                    "filter": {
                        "bool": {
                            "must": [
                                {
                                    "match": {
                                        "questions.questionId": "79cfc6e7-731e-4d83-9dd6-82f4f39fff03"
                                    }
                                }
                            ]
                        }
                    },
                    "aggs": {
                        "select_all_that_apply_nested": {
                            "nested": {
                                "path": "questions.influencerReponse.selectAllThatApplyResponses"
                            },
                            "aggs": {
                                "terms": {
                                    "field": "questions.influencerReponse.selectAllThatApplyResponses.key"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


我收到下面的错误。

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [terms]",
                "line": 42,
                "col": 46
            }
        ],
        "type": "parsing_exception",
        "reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [terms]",
        "line": 42,
        "col": 46
    },
    "status": 400
}

yqkkidmi

yqkkidmi1#

最后一个terms agg也需要一个名称--我将其命名为select_all_that_apply_nested_terms

...

  "select_all_that_apply_nested":{
    "nested":{
      "path":"questions.influencerReponse.selectAllThatApplyResponses"
    },
    "aggs":{
      "select_all_that_apply_nested_terms":{
        "terms":{
          "field":"questions.influencerReponse.selectAllThatApplyResponses.key"
        }
      }
    }
  }

...

字符串

相关问题