node.js - Elasticsearch node.js geo_distance 过滤器

标签 node.js filter elasticsearch geolocation

我在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 的帮助。

关于node.js - Elasticsearch node.js geo_distance 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30172504/

相关文章:

javascript - 过滤多个输入字段

java - spring aop 相对于过滤器的优势是什么,两者在应用程序中看起来相似

angularjs - 如何将过滤器传递给 AngularJS 中的指令

node.js - 为什么第一个函数调用的执行速度比所有其他顺序调用快两倍?

node.js - 监视 MongoDB 集合上的更新(数据库层上的更新后 Hook )

javascript - NodeJS setInterval错误

elasticsearch - 函数评分查询elasticsearch解析错误

java - Elasticsearch : Can't get Native (Java) Script working

elasticsearch - 如何在Kibana 4中创建复杂的过滤器?

javascript - 数据导入 MySQL -> 值与无值