Amazon web services 通过AWS amplify和ElasticSearch查找地理位置和其他字段
在AWS amplify的文档中,定义了如何仅通过创建自定义解析器来搜索地理位置: 但是,如何结合任何其他查询筛选器(例如某个名称)查找此位置呢。因此,在位置X中找到每个名为X的人 我有这个模板:Amazon web services 通过AWS amplify和ElasticSearch查找地理位置和其他字段,amazon-web-services,
elasticsearch,geo,aws-amplify,Amazon Web Services,
elasticsearch,Geo,Aws Amplify,在AWS amplify的文档中,定义了如何仅通过创建自定义解析器来搜索地理位置: 但是,如何结合任何其他查询筛选器(例如某个名称)查找此位置呢。因此,在位置X中找到每个名为X的人 我有这个模板: "version": "2017-02-28", "operation": "GET", "path": "$indexPath.toLowerCase()", "params": { "body": { "query": { "bool" : {
"version": "2017-02-28",
"operation": "GET",
"path": "$indexPath.toLowerCase()",
"params": {
"body": {
"query": {
"bool" : {
"must" : [
{ match : { "name": $ctx.args.params.name }},
],
"filter" : {
"geo_distance" : {
"distance" : "${distance}km",
"location" : $util.toJson($ctx.args.location)
}
}
}
}
}
}
}
使用此模式:
input paramsStringFilterInput {
ne: String
eq: String
match: String
matchPhrase: String
matchPhrasePrefix: String
multiMatch: String
exists: Boolean
wildcard: String
regexp: String
}
input ParamsInput {
name: paramsStringFilterInput
monday: Boolean
}
type ZVLConnection {
items: [ZVL]
total: Int
nextToken: String
}
type Query {
nearbyZVL(params: ParamsInput, location: LocationInput!, km: Int): ZVLConnection
}
我无法通过此查询获取此错误:
query getProfiles{
nearbyZVL(
location: {
lat:51.848388,
lon: 5.447252
},
km: 12,
params:{
name: { match: "Ramon" }
}
){
total,
items {
id
name
}
}
}
{
"data": {
"nearbyZVL": null
},
"errors": [
{
"path": [
"nearbyZVL"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Unable to parse the JSON document: 'Unexpected character ('m' (code 109)): was expecting double-quote to start field name\n at [Source: (String)\"\n{\n \"version\": \"2017-02-28\",\n \"operation\": \"GET\",\n \"path\": \"/zorgverlener/doc/_search\",\n \"params\": {\n \"body\": {\n \"query\": {\n \"bool\" : {\n \"must\" : [\n { match : { \"name\": Ramon }},\n ],\n \"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"12km\",\n \"location\" : {\"lat\":51.848388,\"lon\":5.447252}\n \"[truncated 86 chars]; line: 11, column: 28]'"
}
]
}
@ramon嘿,伙计,所以我想让它与各种搜索过滤器一起工作: 模式:
type Query {
nearByEvents(filter: SearchEventsNearbyInput, sort: SearchNearbyEventsSortInput, limit: Int, nextToken: Int): EventConnection
}
解析程序:
set( $indexPath = "/event/doc/_search" )
#set( $distance = $util.defaultIfNull($ctx.args.filter.km, 200) )
{
"version": "2017-02-28",
"operation": "GET",
"path": "$indexPath.toLowerCase()",
"params": {
"body": {
"from": #if( $context.args.nextToken ) $context.args.nextToken #else 0 #end,
"size": #if( $context.args.limit ) $context.args.limit #else 20 #end,
"sort": #if( $context.args.sort )
[#if( !$util.isNullOrEmpty($context.args.sort.field) && !$util.isNullOrEmpty($context.args.sort.direction) )
{
"$context.args.sort.field": {
"order": "$context.args.sort.direction"
}
}
#end, "_doc"]
#else
[]
#end,
"query": {
"bool": {
"must": {
"range": {
"dateTime": {
"gte": $ctx.args.filter.startDate,
"lt": $ctx.args.filter.endDate
}
}
}
,
#if( $context.args.filter.categories.size() > 0 )
"should": [
#foreach( $category in $ctx.args.filter.categories )
{
"match_phrase": {
"categories": "$category"
}
}
#if( $foreach.hasNext ),
#end
#end
],
"minimum_should_match": 2
, #end
"filter": {
"geo_distance": {
"distance" :"${distance}km",
"distance_type": "plane",
"location": $util.toJson($ctx.args.filter.location)
}
}
}
}
}
}
}
然后,我能够查询过滤器,排序和限制,同时仍然使用地理距离
希望这有帮助 你有没有想过?我正试图做同样的事情,但没有运气。。。
#set( $items = [] )
#foreach( $entry in $context.result.hits.hits )
#if( !$foreach.hasNext )
#set( $nextToken = "$entry.sort.get(0)" )
#end
$util.qr($items.add($entry.get("_source")))
#end
$util.toJson({
"items": $items,
"total": $ctx.result.hits.total,
"nextToken": $nextToken
})