我正在使用gocb根据地理位置查询文档。到目前为止,NewGeoDistanceQuery可以很好地处理索引。现在我需要根据地理位置距离对结果进行排序。根据here中的文档,它说我需要在查询中传递排序参数!但是NewGeoDistanceQuery没有这样的功能。所以我搜索了开发工具包,发现了NewSearchSortGeoDistance,这正是我要找的,但我对如何组合它们感到困惑。
location := cbft.NewGeoDistanceQuery(in.Lat, in.Lon, fmt.Sprintf("%skm", in.Distance))
sort := cbft.NewSearchSortGeoDistance("address", in.Lat, in.Lon).Unit("km")
conjunctionQuery = cbft.NewConjunctionQuery(location, sort)我尝试了上面的解决方案,但得到了这个错误
{"error":"rest_index: Query, indexName: restaurant-geo-search, err: bleve: QueryBleve parsing searchRequest, err: unknown query type","request":{"ctl":{"timeout":75000},"query":{"conjuncts":[{"distance":"2km","location":[90.404272,23.793993]},{"by":"geo_distance","field":"address","location":[90.404272,23.793993],"unit":"km"}]},"size":100},"status":"fail"}我也尝试过单独使用NewSearchSortGeoDistance,但出现了相同的错误。对此有什么帮助吗?
发布于 2019-04-29 16:04:50
我已经在https://forums.couchbase.com/t/any-example-for-combining-geo-location-search-query-with-distance-filter-sorting/21155上回答了,但只是想把所有的信息也放在这里:
我认为这里的问题是您试图使用排序顺序作为查询,而不是作为排序标准。我想你想要的可能是gocb.NewSearchQuery(indexName, location).Sort(sort)。这将采用排序标准并将其放入sort字段下的JSON请求中,如您在我们的文档中所见。
https://stackoverflow.com/questions/55887601
复制相似问题