在我的应用程序中,我使用的是 mongoosastic 。我创建了映射和架构,但是当我看到映射结果时,它会将位置geo_point属性更改为对象类型,因此可能会在我使用查询进行搜索时给我错误:
错误:嵌套:QueryParsingException [[userprofiles] 找不到 geo_point 字段 [位置]];}]"
我提前查询休息客户端
创建映射:
"mappings": {
"userprofile": {
"properties": {
"address": {
"type": "string"
},
"timing": {
"type": "object",
"properties": {
"open": {
"type": "string"
},
"close": {
"type": "string"
}
},
"location": {
"type": "geo_point"
}
}
}
}
}
用户架构
var UserProfileSchema = new Schema({
userId: String,
username: String,
address: {
type: String,
es_indexed: true
},
number: {
type: Number,
es_indexed: true
},
location: {
lat: Number,
lon: Number
},
timing: {
open: String,
close: String
}
});
搜索查询:
{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "20km",
"location" : {
"lat" : 37.9174,
"lon" : -122.3050
}
}
}
}
}
}