我有弹性搜索此查询他们的名字让地方:按距离排序上ElasticSearch
GET places/fastfood/_search
{
"from" : 0, "size" : 10,
"query": {
"bool": {
"must": [
{ "regexp": { "name": ".*name.*"} },
{ "term" : { "location_id" : id } }
]
}
}
}
如果姓名和身份证被替换,以配合我需要什么。 现在我想获取与名称和ID匹配的位置,但距离选定的位置更近。假设我没有在提供的location_id(城市,地区)中使用麦当劳,我应该选择离该地点最近的麦当劳。
我在每个城市/地区称为位置的字段,这是一个纬度,经度,定义为geo_spot的字符串。然后也有经纬度定义为长。就像这样:
"location": "33.785400,-84.38480",
"latitude": "33.785400",
"longitude": "-84.384800",
所以我试图通过位置添加排序,像这样的,但我得到的错误,什么是错的:
GET places/fastfood/_search
{
"from" : 0, "size" : 10,
"query": {
"bool": {
"must": [
{ "regexp": { "name": ".*name.*"} },
{ "term" : { "location_id" : location_id } }
]
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 26.112,
"lon": -73.998
},
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
}
我做错了什么?我应该改变什么?
的错误是这样的: { “错误”:“SearchPhaseExecutionException [未能执行相位[查询],所有失败碎片; shardFailures {[n6y6tjWFRrCP5MXNhEV-YA] [places_v1] [0]:RemoteTransportException [[潮] [inet [/ xxxx:y]] [indices:data/read/search [phase/query]]];嵌套:SearchParseException [[places_v1] [0]:query [+ name:/。hosp。/+ location_id :[10到10]],从[0],大小[10]:解析失败[无法解析源[{\ r \ n \“从\”:0,\“size \”:10,\ r \ n \“query \”:{\ r \ n \“bool \”:{\ r \ n \“must \”:[\ r \ n {\“regexp \”:{\“name \”:\“ 。 hosp。 \“}},\ r \ n {\”term \“:{\”location_id \“:10}} \ r \ n] \ r \ n} \ r \ n},\ r \ n \”sort \“:[\ r \ n {\ r \ n \”_ geo_distance \“:{\ r \ n \”location \“:{\ r \ n \”lat \“:26.112,\ r \ n \ \“:-73.998 \ r \ n},\ r \ n \”order \“:\”asc \“,\ r \ n \”unit \“:\”km \“,\ r \ n \”distance_type \“:\”plane \“\ r \ n} \ r \ n} \ r \ n} \ n]]];嵌套:JsonParseException [意外关闭标记'}':预期']'(对于ARRAY,来源:[B @ 4ac877f6; line:10,column:5])\ n at [Source:UNKNOWN; line:23,column:2]];} {[n6y6tjWFRrCP5MXNhEV-YA] [places_v1] [1]:RemoteTransportException [ [Boomer] [inet [/ xxxx:y]] [indices:data/read/search [phase/query]]];嵌套:SearchParseException [[places_v1] [1]:query [+ name:/。hosp。/+ location_id:[10 TO 10]],从[0],大小[10]:解析失败[无法解析源[{\ r \ n \“from \”:0,\“size \”: \ r \ n \“query \”:{\ r \ n \“bool \”:{\ r \ n \“must \”:[\ r \ n {\“regexp \”:{\“name \ : \”。 hosp。 \“}},\ r \ n {\”term \“:{\”location_id \“:10}} \ r \ n] \ r \ n} \ r \ n},\ r \ n \”sort \“:[\ r \ n {\ r \ n \”_ geo_distance \“:{\ r \ n \”location \“:{\ r \ n \”lat \“:26.112,\ r \ n \ \“:-73.998 \ r \ n},\ r \ n \”order \“:\”asc \“,\ r \ n \”unit \“:\”km \“,\ r \ n \”distance_type \“:\”plane \“\ r \ n} \ r \ n} \ r \ n} \ n]]];嵌套:JsonParseException [意外关闭标记'}':预期']'(对于ARRAY,来源:[B @ 19f9b52f; line:10,column:5])\ n at [Source:UNKNOWN; line:23,column:2]];} {[7i0nOGiFRl-OYX8XvL_bSQ] [places_v1] [2]:SearchParseException [ [位置_v1] [2]:查询[+ name:/。hosp。/+ location_id:[10 TO 10]],from [0],size [10]:解析失败[Failed to parse source [{\ r \ n \“from \”:0,\“size \”:10,\ r \ n \“query \”:{\ r \ n \“bool \”:{\ r \ n \“must \”: [\ r \ n {\“regexp \”:{\“name \”:\“。 hosp。 \“}},\ r \ n {\”term \“:{\”location_id \“:10}} \ r \ n] \ r \ n} \ r \ n},\ r \ n \”sort \“:[\ r \ n {\ r \ n \”_ geo_distance \“:{\ r \ n \”location \“:{\ r \ n \”lat \“:26.112,\ r \ n \ \“:-73.998 \ r \ n},\ r \ n \”order \“:\”asc \“,\ r \ n \”unit \“:\”km \“,\ r \ n \”distance_type \“:\”plane \“\ r \ n} \ r \ n} \ r \ n} \ n]]];嵌套:JsonParseException [意外关闭标记'}':预期']'(对于ARRAY,来源:[B @ 427094b6; line:10,column:5])\ n at [Source:[B @ 427094b6; line:23,column:2]];} {[n6y6tjWFRrCP5MXNhEV-YA] [places_v1] [3] :RemoteTransportException [[Boomer] [inet [/ xxxX:Y]] [指数:数据/读取/搜索[相位/查询]]];嵌套:SearchParseException [[places_v1] [3]:query [+ name:/。 hosp。/+ location_id:[10 TO 10]],from [0],size [10]:解析失败[解析来源[{\ r \ n \':\':0,\“size \”:10 ,\ r \ n \“query \”:{\ r \ n \“bool \”:{\ r \ n \“must \”:[\ r \ n {\“regexp \”:{\ “:\”。hosp。 \“}},\ r \ n {\”term \“:{\”location_id \“:10}} \ r \ n] \ r \ n} \ r \ n} ,\ r \ n \“sort \”:[\ r \ n {\ r \ n \“_ geo_distance \”:{\ r \ n \“location \”:{\ r \ n \“lat \”:26.112 ,\ r \ n \“lon \”:-73.998 \ r \ n},\ r \ n \“order \”:\“asc \”,\ r \ n \“unit \”:\“km \ ,\ r \ n \“distance_type \”:\“plane \”\ r \ n} \ r \ n} \ r \ n} \ n]]];嵌套:JsonParseException [意外关闭标记'}':预期']'(对于源自[Source:[B @ 4f781e6c; line:10,column:5]的ARRAY)\ n在[Source:UNKNOWN;行:23,列:2]]; } {[n6y6tjWFRrCP5MXNhEV-YA] [places_v1] [4]:RemoteTransportException [[Boomer] [inet [/x.x.x.xyy]] [indices:data/read/search [phase/query]]];嵌套:SearchParseException [[places_v1] [4]:query [+ name:/。 hosp。/+ location_id:[10 TO 10]],from [0],size [10]:解析失败[解析来源[{\ r \ n \':\':0,\“size \”:10 ,\ r \ n \“query \”:{\ r \ n \“bool \”:{\ r \ n \“must \”:[\ r \ n {\“regexp \”:{\ “:\”。hosp。 \“}},\ r \ n {\”term \“:{\”location_id \“:10}} \ r \ n] \ r \ n} \ r \ n} ,\ r \ n \“sort \”:[\ r \ n {\ r \ n \“_ geo_distance \”:{\ r \ n \“location \”:{\ r \ n \“lat \”:26.112 ,\ r \ n \“lon \”:-73.998 \ r \ n},\ r \ n \“order \”:\“asc \”,\ r \ n \“unit \”:\“km \ ,\ r \ n \“distance_type \”:\“plane \”\ r \ n} \ r \ n} \ r \ n} \ n]]];嵌套:JsonParseException [意外的关闭标记'}':预期的']'(对于数据源[B @ 586764c7; line:10,column:5]开始的ARRAY)在[Source:UNKNOWN;行:23,列:2]]; }]”, ‘状态’:400 }
你能告诉我你是怎么找到 –
关闭排序只是看看到底的错误日志:'JsonParseException [意外关闭标记'}':预计']'' – paqash