I'm using version 7.13.2 of elastic search and the new version of their lib
I'm trying to make a geo_distance filter in nodejs , but the typing doesn't seem to be recognized, maybe it's because of the 'nested' type, because I tested the documentation example and it worked, follow the link: ( https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html )
the index is mapped like this:
(ps: I only left the fields that interest us)
mappings: {
properties: {
id: { type: "integer" },
profile: {
type: "nested",
properties: {
id: { type: "integer" },
address: {
type: "nested",
properties: {
id: { type: "integer" },
location: { type: "geo_point" },
}
},
},
},
}
}
the data I'm entering is these
{
"id": 1,
"profile": {
"id": 2,
"name: "Test"
"address": [{
"id": 1
"location": "-20.771, -51.70"
},
"address": [{
"id": 2
"location": "-20.772, -51.72"
}],
}
}
the search I'm doing is like this:
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",
},
},
},
},
},
},
};
the error that appears in the search is this:
Field [profile.address.location] is of unsupported type [text] for [geo_distance] query
the same search I'm making works for the documentation example, but in my case it's giving the error mentioned above
Since location
is located inside a (doubly) nested
field, your query needs to leverage the nested
query as well:
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",
},
},
}
}
}
}
},
},
},
},
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.