我使用的是弹性搜索的7.13.2版本和他们库的新版本
我试图在nodejs中制作一个geo_distance过滤器,但似乎无法识别类型,可能是因为"嵌套"类型,因为我测试了文档示例并成功了,请点击链接:(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html)
索引映射如下:
(ps:我只留下了我们感兴趣的字段(
mappings: {
properties: {
id: { type: "integer" },
profile: {
type: "nested",
properties: {
id: { type: "integer" },
address: {
type: "nested",
properties: {
id: { type: "integer" },
location: { type: "geo_point" },
}
},
},
},
}
}
我输入的数据是这些
{
"id": 1,
"profile": {
"id": 2,
"name: "Test"
"address": [{
"id": 1
"location": "-20.771, -51.70"
},
"address": [{
"id": 2
"location": "-20.772, -51.72"
}],
}
}
我正在做的搜索是这样的:
let params: RequestParams.Search = {
index: index,
body: {
query: {
bool: {
must: [
{
match_all: {},
},
],
should: [],
filter: {
geo_distance: {
distance: "5mi",
"profile.address.location": {
lat: "-20.78",
lon: "-51.70",
},
},
},
},
},
},
};
搜索中出现的错误是:
字段〔profile.address.location〕的类型〔text〕不受支持[geo_distance]查询
我正在为文档示例进行的相同搜索,但在我的情况下,它给出了上面提到的错误
由于location
位于(双重(nested
字段内,因此您的查询也需要利用nested
查询:
let params: RequestParams.Search = {
index: index,
body: {
query: {
bool: {
must: [
{
match_all: {},
},
],
should: [],
filter: {
nested: {
path: "profile",
query: {
nested: {
path: "profile.address",
query: {
geo_distance: {
distance: "5mi",
"profile.address.location": {
lat: "-20.78",
lon: "-51.70",
},
},
}
}
}
}
},
},
},
},
};