'Amplify Geolocation aware search not working
I am trying to integrate GeoLocation aware searching via AWS OpenSearch in Amplify dynamoDB graphQL. OpenSearch Instance that created using amplify cli i followed these steps to achieve geolocation wise items list from dynamoDB
Failed to receive data accroding to geolocation.
Schema.graphql
type User
@model
@searchable {
id: ID!
full_name: String
email: String
phoneNumber: String
location: Location
}
type Query {
nearbyUsers(
location: LocationInput!,
m: Int #Radius | Distance criteria to get users under perimeter
): NearbyUserConnection
}
type NearbyUserConnection {
items: [User]
total: Int
nextToken: String
}
type Location {
lat: Float
lon: Float
}
Query.nearbyusers.req.vtl
## Query.nearbyUsers.req.vtl
## Objects of type User will be stored in the /bikepoint index
#set( $indexPath = "/user/doc/_search" )
#set( $distance = $util.defaultIfNull($ctx.args.m, 500) )
#set( $limit = $util.defaultIfNull($ctx.args.limit, 10) )
{
"version": "2017-02-28",
"operation": "GET",
"path": "$indexPath.toLowerCase()",
"params": {
"body": {
"from" : 0,
"size" : ${limit},
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "${distance}m",
"pin.location" : $util.toJson($ctx.args.location)
}
}
}
},
"sort": [{
"_geo_distance": {
"location": $util.toJson($ctx.args.location),
"order": "asc",
"unit": "m",
"distance_type": "arc"
}
}]
}
}
}```
**opensearch Error Logs**
> [**,958][DEBUG][o.e.a.s.TransportSearchAction] [****] [****][user][0]:
> Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH,
> indices=[user],
> indicesOptions=IndicesOptions[ignore_unavailable=false,
> allow_no_indices=true, expand_wildcards_open=true,
> expand_wildcards_closed=false, expand_wildcards_hidden=false,
> allow_aliases_to_multiple_indices=true, forbid_closed_indices=true,
> ignore_aliases=false, ignore_throttled=true], types=[doc],
> routing='null', preference='null', requestCache=null, scroll=null,
> maxConcurrentShardRequests=0, batchedReduceSize=512,
> preFilterShardSize=null, allowPartialSearchResults=true,
> localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1,
> ccsMinimizeRoundtrips=true,
> source={"size":10,"query":{"bool":{"must":[{"match_all":{"boost":1.0}}],"filter":[{"geo_distance":{"location":[**],"distance":10.0,"distance_type":"arc","validation_method":"STRICT","ignore_unmapped":false,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}},
> cancelAfterTimeInterval=null}] lastShard [true]
> RemoteTransportException[[****][__IP__][__PATH__[__PATH__]]]; nested:
> QueryShardException[failed to find geo_point field [location]];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
