本文介绍了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','没有为[过滤器]注册的[查询]')错误.我认为Elasticsearch的书写格式错误.我用作参考, https://www.elastic.co/guide/zh_cn/elasticsearch/reference/5.2/query-dsl-geo-distance-query.html .但是我找不到错误的地方.该如何解决?代码中的错误是什么?

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?

推荐答案

您的查询必须像这样:

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

这篇关于Elasticsearch的格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 06:17