我正在尝试过滤geo_point
嵌套在对象(Location)中的(geo_coordinates),该对象嵌套在查询对象(MyObject)的数组中。
问题是对象 MyObject 的映射没有将 geo_coordinates 字段视为 geo_point:
// Index mapping for object MyObject
"myobjects": {
"mappings": {
"myobject": {
"properties": {
"locations": {
"type": "nested",
"include_in_parent": true,
"properties": {
"geo_coordinates": {
"properties": {
"lat": { "type": "double" },
"lon": { "type": "double" }
}
},
}
[...]
// Index mapping for object Location
"locations": {
"mappings": {
"location": {
"properties": {
"geo_coordinates": {
"type": "geo_point"
},
}
}
}
猫鼬对象 MyObject 如下所示:
var MyObjectSchema = new Schema(
[...]
locations: {
type: [{ type: Schema.Types.ObjectId, ref: 'Location', es_schema: LocationSchema.schema}],
es_type: 'nested',
es_include_in_parent: true
},
[...]
)
猫鼬对象位置如下所示:
var LocationSchema = new Schema(
[...]
geo_coordinates: {
type: {
geo_point: {
type: String,
es_type: 'geo_point',
es_lat_lon: true
},
lat: {type: Number, default: 0},
lon: {type: Number, default: 0}
},
es_type: 'geo_point'
}
[...]
);
我的查询如下所示:
// POST http://ES-endpoint/locations/_search
{
"query": {
"filtered" : {
"query": {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "20000km",
"locations.geo_coordinates" : {
"lat" : 40,
"lon" : -70
}}}}}}
我必须错过一些东西,但是什么?
PS:使用 Kibana 浏览索引时,两个对象的 geo_location 数据相同:
"geo_coordinates": {
"lat": x.xxxx,
"lon": y.yyy
}