【问题标题】:Getting error on Elastic Search query [ImageURL] query malformed, no start_object after query nameElastic Search 查询 [ImageURL] 查询格式错误,查询名称后没有 start_object
【发布时间】:2019-10-15 20:42:32
【问题描述】:

我有以下请求 JSON 用于 ES 查询。它给了我以下错误:

[ImageURL] 查询格式错误,查询名称后没有 start_object

当我在bool 下添加must_not 时。如果我删除must_not,它工作正常。我想获取“ImageURL”不为空的记录

我哪里做错了?请帮忙

{
        "from": 0,
        "size": 45,
        "query": {
            "bool": {
                "must": {
                    "match_all": {}
                },
                "filter": [
                    [{
                        "term": {
                            "PostStatusInd": 1
                        }
                    }, {
                        "term": {
                            "PostCountry": "PAK"
                        }
                    }], {
                        "range": {
                            "RecModDate": {
                                "gte": "2019-07-07 00:00:00"
                            }
                        }
                    }, {
                        "range": {
                            "PostPriceAmt": {
                                "gte": "0",
                                "lte": "100000000"
                            }
                        }
                    }, {
                        "geo_distance": {
                            "distance": "41000km",
                            "Location": {
                                "lat": "33.6895939",
                                "lon": "73.0435789"
                            }
                        }
                    }
                ],
                "must_not": {
                    "ImageURL": null
                }
            }
        },
        "sort": [{
            "RecModDate": {
                "order": "desc"
            }
        }]
    }

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:
    you missed writing the term/match function within must_not query
    
    Try the below query
    
    {
            "from": 0,
            "size": 45,
            "query": {
                "bool": {
                    "must": {
                        "match_all": {}
                    },
                    "filter": [
                        [{
                            "term": {
                                "PostStatusInd": 1
                            }
                        }, {
                            "term": {
                                "PostCountry": "PAK"
                            }
                        }], {
                            "range": {
                                "RecModDate": {
                                    "gte": "2019-07-07 00:00:00"
                                }
                            }
                        }, {
                            "range": {
                                "PostPriceAmt": {
                                    "gte": "0",
                                    "lte": "100000000"
                                }
                            }
                        }, {
                            "geo_distance": {
                                "distance": "41000km",
                                "Location": {
                                    "lat": "33.6895939",
                                    "lon": "73.0435789"
                                }
                            }
                        }
                    ],
                    "must_not": {
                      "term":{
                        "ImageURL": null
                      }
                    }
                }
            },
            "sort": [{
                "RecModDate": {
                    "order": "desc"
                }
            }]
        }
    

    【讨论】:

      【解决方案2】:

      “存在”对我有用

      {
          "from": 0,
          "size": 45,
          "query": {
              "bool": {
                  "must": {
                      "exists": {
                          "field": "ImageURL"
                      }
                  },
                  "filter": [
                      [{
                          "term": {
                              "PostStatusInd": 1
                          }
                      }, {
                          "term": {
                              "PostCountry": "PAK"
                          }
                      }], {
                          "range": {
                              "RecModDate": {
                                  "gte": "2019-07-07 00:00:00"
                              }
                          }
                      }, {
                          "range": {
                              "PostPriceAmt": {
                                  "gte": "0",
                                  "lte": "100000000"
                              }
                          }
                      }, {
                          "geo_distance": {
                              "distance": "41000km",
                              "Location": {
                                  "lat": "33.6895939",
                                  "lon": "73.0435789"
                              }
                          }
                      }
                  ]
              }
          },
          "sort": [{
              "RecModDate": {
                  "order": "desc"
              }
          }]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-10
        • 1970-01-01
        • 2021-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-15
        相关资源
        最近更新 更多