gpt4 book ai didi

elasticsearch - Mongoosastic,我如何进行地理距离查询

转载 作者:行者123 更新时间:2023-11-29 02:56:54 26 4
gpt4 key购买 nike

对于 Mongoose ,我的模式看起来像这样:

var articleSchema = new Schema({
Name: {type: String, es_indexed: true},
geo_with_lat_lon: {
geo_point: {
type: String,
es_type: 'geo_point',
es_lat_lon: true
},
lat: {type: Number},
lon: {type: Number}
},
...
});

我添加一个新文档:

var artikel = new global.DBModel.article({
Name:"Test",
geo_with_lat_lon:{lon:-70,lat:40}
});
artikel.save(...);

现在我想按距离过滤。我的查询如下所示:

global.DBModel.article.search({
"bool": {
"must": {
"match_all": {}
},
"filter" :{
"geo_distance": {
"distance": "200km",
"geo_with_lat_lon": {
"lat": 40,
"lon": -70
}
}
}
}
}, {...}

但我总是得到错误

{
"error": {
"root_cause": [
{
"type": "query_parsing_exception",
"reason": "failed to find geo_point field [geo_with_lat_lon]",
"index": "articles",
"line": 1,
"col": 127
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "articles",
"node": "YdQHw7nSRc-T0LwItupmmw",
"reason": {
"type": "query_parsing_exception",
"reason": "failed to find geo_point field [geo_with_lat_lon]",
"index": "articles",
"line": 1,
"col": 127
}
}
]
},
"status": 400 }

我的问题是:如何按距离正确过滤?

最佳答案

谢谢 Paradise228,是映射。

这项工作:

...geo_with_lat_lon: {
geo_point: {
es_indexed: true,
type: String,
es_type: 'geo_point',
es_lat_lon: true
},
lat: {type: Number},
lon: {type: Number}
},...

使用此映射:

global.DBModel.store.createMapping(function (err, mapping) {
if (err) {
console.log('error creating mapping (you can safely ignore this)');
console.log(err);
} else {
console.log('mapping created!');
console.log(mapping);
}
});

关于elasticsearch - Mongoosastic,我如何进行地理距离查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36495548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com