elasticsearch,geopoints,Geolocation,elasticsearch,Geopoints" /> elasticsearch,geopoints,Geolocation,elasticsearch,Geopoints" />

Geolocation ElasticSearch中的地理排序和距离计算不起作用

Geolocation ElasticSearch中的地理排序和距离计算不起作用,geolocation,elasticsearch,geopoints,Geolocation,elasticsearch,Geopoints,更新我还更新了映射,以包括示例所示的pin。此外,这里还有一个临时实例,其中包含一些要处理的数据: 我一直在跟踪调查。使用此请求: $.ajax({ url: 'https://21991e47cdc7caa8000.qbox.io/profiles/lead/_search', method: 'GET', data: { sort: [{ _geo_distance: {

更新我还更新了映射,以包括示例所示的pin。此外,这里还有一个临时实例,其中包含一些要处理的数据:

我一直在跟踪调查。使用此请求:

$.ajax({
        url: 'https://21991e47cdc7caa8000.qbox.io/profiles/lead/_search', 
        method: 'GET', 
        data: {
            sort: [{
                _geo_distance: {
                    "pin.location": [49.8998, -97.1375], 
                    order: "asc", 
                    unit: "km"
                }
            }]
        }, 
        success: function(response) {
            console.log(response);
        }
    });
不返回计算的距离或按距离排序的距离。我还尝试过使用
“location”

以下是我的映射:


有什么想法吗?

给出的示例使用的是
pin.location
,而不是
location
lead.location

另外,
pin.location
是一个长度为2的数组,而不是一个使用时带有两个字段的对象。这似乎与我的直觉相反,因为大多数其他api调用中的
location
字段都是您正在使用的对象

试试这个:

$.ajax({
    url: "https://myhostedes.com/profiles/lead/_search", 
    method: "GET", 
    data: {
        "sort": [{
            "_geo_distance": {
                "pin.location": [49.8998, -97.1375], 
                "order": "asc", 
                "unit": "km"
            }
        }]
    }, 
    success: function(response) {
        console.log(response);
    }
});

注意:我目前没有访问elastisearch实例的权限,因此我还无法运行此实例。

我已设法使其工作,请查看区别

在查询之前,我将数据转换为json,并添加了一些配置(将数据类型更改为json,将请求类型更改为POST),因为我们知道GET请求通常没有正文,只有POST请求有正文

var request = {
    sort: [{
        _geo_distance: {
            "pin.location": [
            49.8998, -97.1375],
            order: "asc",
            unit: "km"
        }
    }]
};


$.ajax({
    url: 'https://21991e47cdc7caa8000.qbox.io/profiles/lead/_search',
    type: 'POST',
    crossDomain: true,
    dataType: 'json',
    data: JSON.stringify(request),
    success: function (response) {
        console.log(JSON.stringify(response));

    }
});
希望这有帮助


我已经测试过了,它应该也适用于您。

不起作用。我想知道我是否真的需要实体上的pin属性?现在我只有位置…假设pin是他们正在使用的示例实体--这来自他们的文档:“例如,让我们以“pin”为例”我们想索引它的位置,也许还有一些与它相关的标签。这里的映射也显示了“pin”:我已经包含了一个指向ES服务器的链接,您可以在那里尝试。如果您可以得到一个在那里工作的请求,它也应该对我有效。看起来应该有效:我同意……我的服务器上的请求对您有效吗?