1
votes

i have a probleme with elastic search when i request it with the following json, i have this error: [bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME] i've tried to look on many site but none of them give me a response

{

    "query":{
        "bool":{
            "must":[
                {
                    "match":{
                        "group_issuer_name":"bnp"
                    }
                },
                {
                    "match":{
                        "asset_country":"France"
                    }
                }
            ]
        },
        "aggs":{
            "by_ptf_name":{
                "terms":{
                    "field":"ptf_name.keyword"
                },
                "aggs":{
                    "by_ptf_id":{
                        "terms":{
                            "field":"ptf_id.keyword"
                        },
                        "aggs":{
                            "sum_of_asset_exposure":{
                                "sum":{
                                    "field":"asset_exposure"
                                }
                            },
                            "min_of_ptf_total_asset":{
                                "min":{
                                    "field":"ptf_total_asset"
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}
1

1 Answers

1
votes

You are missing }. The query part must be closed and then the aggregation part should start.

The structure should be

{
  "query": {},
  "aggregation": {}
}

Modify your query as -

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "group_issuer_name": "bnp"
          }
        },
        {
          "match": {
            "asset_country": "France"
          }
        }
      ]
    }
  },                                    // note this
  "aggs": {
    "by_ptf_name": {
      "terms": {
        "field": "ptf_name.keyword"
      },
      "aggs": {
        "by_ptf_id": {
          "terms": {
            "field": "ptf_id.keyword"
          },
          "aggs": {
            "sum_of_asset_exposure": {
              "sum": {
                "field": "asset_exposure"
              }
            },
            "min_of_ptf_total_asset": {
              "min": {
                "field": "ptf_total_asset"
              }
            }
          }
        }
      }
    }
  }
}