Elasticsearch node.js geo_distance 过滤器

Elasticsearch node.js geo_distance filter

我在 nodejs 应用程序中使用 elasticsearch 模块,以便通过 geo_points 查找文档。

根据 http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search,我正在尝试这样做 :

client.search({
  index: 'myindex',
  type: 'mytype',
  body: {
    filtered : {
        query : {
            match_all : {}
        },
        filter : {
            geo_distance : {
                distance : "200km",
                coordiates : {
                    lat : 40,
                    lon : -70
                }
            }
        }
    }
  }
}).then(function (resp) {
    var hits = resp.hits.hits;
    console.log(hits, "items");
}).catch(function (error) {
    console.log("Error on geo_distance");
});

但我总是遇到搜索解析错误。

有人知道吗?

感谢

最后,我找到了正确的语法/参数:

client.search({
  index: 'myindex',
  type: 'mytype',
  body: {
      from: from,
      size: size,
      query: {
        filtered: {
                filter: {
                    geo_distance: {
                        distance: '100000km',
                        coordiates: {
                            lat: 0.0,
                            lon: 0.0
                        }
                    }
                }
            }
        }
  }
}).then(function (resp) {
    var hits = resp.hits.hits;
    console.log(hits.length, "items around");
}).catch(function (error) {
    console.log("Error on geo_distance (coordiates)");
});

感谢 Jhilden 的帮助。