Search code examples
pythonpython-3.xelasticsearchelasticsearch-5

BadRequestError(400, 'x_content_parse_exception', '[1:263] [bool] failed to parse field [filter]')


I have this query ,

search = {
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "created_at": {
              "gte":"2013-12-31T07:14:22+00:00",
              "lt":"2015-12-31T07:14:22+00:00"
            }
          }
        },
        {
          "geo_bounding_box": {
          "coordinates": {
            "top_left": {
              "lat": -105.03197389,
              "lon": 39.93687082
            },
            "bottom_right": {
              "lat":40.01724753,
              "lon": -105.282502
            }
          }
          }
        }
          {
              "match": {
                  "text": "Story"
              }
          }
      ]
    }
  }
}

The Goal of this query is trying to find tweets published during a certain time interval, withen a certain bounding box and having a certain word.

but I don't know what I should put inside geo_bounding_box part, I tried smothing random and it's returning a 0 hits. then I took a look to my data and pick 2 points I put them in the query up but it's not working and returning

BadRequestError(400, 'x_content_parse_exception', '[1:263] [bool] failed to parse field [filter]')

where is the problem, and how sould I write the geo_bounding_box points ?


Solution

  • The "geo_shape" fields are matched using the geo-bounding box query in a way that intersects a bounding box.

    The coordinates for the top left and bottom right are included in the latitude and longitude values that are provided. Refer to the official elasticsearch documentation for further information documentation

    Apart from this, the query is a bit malformed, the modified query should be :

    {
        "query": {
            "bool": {
                "filter": [
                    {
                        "range": {
                            "created_at": {
                                "gte": "2013-12-31T07:14:22+00:00",
                                "lt": "2015-12-31T07:14:22+00:00"
                            }
                        }
                    },
                    {
                        "geo_bounding_box": {
                            "coordinates": {
                                "top_left": {
                                    "lat": -105.03197389,
                                    "lon": 39.93687082
                                },
                                "bottom_right": {
                                    "lat": 40.01724753,
                                    "lon": -105.282502
                                }
                            }
                        }
                    },
                    {
                        "match": {
                            "text": "Story"
                        }
                    }
                ]
            }
        }
    }