0
votes

I wrote

  def user(lat, lon, distance, start_time, end_time):
    param = {
              "query": {
                  "filter": {
                    "geo_distance": {
                      "distance": distance,
                      "distance_type": "plane",
                      "location": {
                        "lat": lat,
                        "lon": lon
                      }
                    }
                  },
                  "query": {
                    "bool": {
                      "must": [
                        {"match": {"start_time": start_time}},
                        {"match": {"end_time": end_time}}
                      ]
                    }
                  }
                }
              }
    num = 0
    results = get_data().query(param)

But TransportError(400, 'parsing_exception', 'no [query] registered for [filter]') error happens.I think the way of writing format of Elasticsearch is wrong.I used as reference,https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-distance-query.html .But I cannot find the wrong point.How should I fix this?What is wrong in my code?

1

1 Answers

0
votes

Your query needs to be like this:

param = {
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": distance,
          "distance_type": "plane",
          "location": {
            "lat": lat,
            "lon": lon
          }
        }
      },
      "must": [
        {
          "match": {
            "start_time": start_time
          }
        },
        {
          "match": {
            "end_time": end_time
          }
        }
      ]
    }
  }
}