Elasticsearch的格式错误

时间:2018-01-30 03:05:18

标签: python elasticsearch

我写了

  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)

但是TransportError(400,'parsing_exception','没有[查询]注册[filter]')错误发生。我认为编写Elasticsearch格式的方式是错误的。我用作参考,https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-geo-distance-query.html。但是我找不到错误的一点。我该如何解决这个问题?我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

您的查询必须如下:

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
          }
        }
      ]
    }
  }
}
相关问题