繁体   English   中英

Elasticsearch node.js geo_distance过滤器

[英]Elasticsearch node.js geo_distance filter

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

根据http://www.elastic.co/guide/zh-CN/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)");
});

Thx Jhilden为您提供帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM