public async Task <IEnumerable <GetUpcomingEventsQueryResult> > GetUpcomingEvents(GetUpcomingEventsQuery getUpcomingEventsQuery)
        {
            var geoDistanceQuery = new GeoDistanceQuery();

            geoDistanceQuery.Field("location");
            geoDistanceQuery.Latitude(getUpcomingEventsQuery.Latitude);
            geoDistanceQuery.Longitude(getUpcomingEventsQuery.Longitude);
            geoDistanceQuery.Distance($"{getUpcomingEventsQuery.Radius}km");

            var statusMatchQuery = new MatchQuery(EventStatuses.ACTIVE);

            statusMatchQuery.Field("status");

            var conjunctionQuery = new ConjunctionQuery(geoDistanceQuery, statusMatchQuery);

            if (!string.IsNullOrEmpty(getUpcomingEventsQuery.Keywords))
            {
                var subjectMatchQuery = new MatchQuery(getUpcomingEventsQuery.Keywords).Fuzziness(1);

                conjunctionQuery.And(subjectMatchQuery);
            }

            var searchParams = new SearchParams()
                               .Fields("*")
                               .Limit(10)
                               .Timeout(TimeSpan.FromMilliseconds(10000));

            var searchQuery = new SearchQuery
            {
                Query        = conjunctionQuery,
                Index        = "idx_geo_events",
                SearchParams = searchParams
            };

            var queryResult = await _eventsBucket.QueryAsync(searchQuery);

            var result = new List <GetUpcomingEventsQueryResult>();

            foreach (var hit in queryResult.Hits)
            {
                result.Add(new GetUpcomingEventsQueryResult
                {
                    EventId     = Guid.Parse(hit.Id),
                    Subject     = hit.Fields["subject"],
                    UrlKey      = hit.Fields["urlKey"],
                    Description = hit.Fields["description"],
                    Date        = DateTimeOffset.Parse(hit.Fields["date"].ToString())
                });
            }

            return(result);
        }
        public async Task <IActionResult> GetUpcomingEvents([FromQuery] GetUpcomingEventsRequest request)
        {
            var query = new GeoDistanceQuery();

            query.Field("location");
            query.Latitude(request.Latitude);
            query.Longitude(request.Longitude);
            query.Distance($"{request.Radius}km");

            var searchParams = new SearchParams()
                               .Fields("*")
                               .Limit(10)
                               .Timeout(TimeSpan.FromMilliseconds(10000));

            var searchQuery = new SearchQuery
            {
                Query        = query,
                Index        = "eventsgeoindex",
                SearchParams = searchParams
            };

            var searchQueryResults = await _bucket.QueryAsync(searchQuery);

            var result = new List <GetUpcomingEventsResponse>();

            foreach (var hit in searchQueryResults.Hits)
            {
                result.Add(new GetUpcomingEventsResponse
                {
                    Subject = hit.Fields["subject"],
                    Address = hit.Fields["address"],
                    Date    = hit.Fields["date"]
                });
            }

            return(Ok(result));
        }