1

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 Answer 1

1

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"
              }
            }
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Sacha you're welcome! :) And please don't forget to accept the answer as well :)
@Sacha can you please accept and upvote the answer, if it helped you resolve your issue 🙂

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.