【问题标题】:Python generate json: bool malformed query, expected END_OBJECT but found FIELD_NAMEPython 生成 json:bool 格式错误的查询,应为 END_OBJECT 但找到 FIELD_NAME
【发布时间】:2021-04-27 03:13:57
【问题描述】:

当我使用以下 json 请求弹性搜索时,我遇到了问题,我有这个错误:[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME] 我试图在许多网站上查看,但没有一个给我回复

{

    "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"
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}

【问题讨论】:

    标签: json elasticsearch


    【解决方案1】:

    您缺少}。查询部分必须关闭,然后聚合部分才应该启动。

    结构应该是

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

    将您的查询修改为 -

    {
      "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"
                  }
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

    • @Sacha 不客气! :) 并且请不要忘记接受答案 :)
    • @Sacha 如果它帮助您解决了您的问题,请您接受并投票赞成答案吗?
    猜你喜欢
    • 2018-02-10
    • 2018-04-25
    • 2021-04-22
    • 2020-02-26
    • 1970-01-01
    • 2018-01-30
    • 2022-10-25
    • 2022-01-14
    • 2017-12-01
    相关资源
    最近更新 更多