public virtual async Task <GetResponse <T> > GetAsync(GetRequest request, CancellationToken cancellationToken)
        {
            // Validate parameters.
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Get the Ids.
            IReadOnlyCollection <string> ids = request.Ids
                                               .Select(id => id.ToString())
                                               .Distinct()
                                               .ToReadOnlyCollection();

            // Get the response.
            IMultiGetResponse response = await ElasticClient.MultiGetAsync(
                d => d
                .Index(Index.Name)
                .Type <T>()
                .GetMany <T>(ids),
                cancellationToken).ConfigureAwait(false);

            // Get the hits.
            IReadOnlyCollection <Hit <T> > hits = response
                                                  .Hits
                                                  .Select(d => d.ToHit <object, T>())
                                                  .ToReadOnlyCollection();

            // Create the response and return.
            return(new GetResponse <T> {
                Request = request,
                TotalHits = hits.Count,
                Hits = hits
            });
        }
        public override async Task <MultiIndexGetResponse> MultiIndexGetAsync(MultiIndexGetRequest request, CancellationToken cancellationToken)
        {
            // Validate parameters.
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Get all of the index types.
            IReadOnlyDictionary <string, Type> indexes =
                await MapIndexNamesToTypesAsync(request.Ids.Select(g => g.Key), cancellationToken)
                .ConfigureAwait(false);

            // Create the request.
            IMultiGetResponse response = await _elasticClient
                                         .MultiGetAsync(descriptor => request.Ids.Aggregate(descriptor, (d, g) => {
                // The type.
                Type type = OpenMultiIndexGetDescriptorReducer.MakeGenericType(indexes[g.Key]);

                // Create the type.
                var reducer = (IMultiIndexGetDescriptorReducer)Activator.CreateInstance(type);

                // Reduce.
                return(reducer.Reduce(d, g));
            }), cancellationToken)
                                         .ConfigureAwait(false);

            // Map the results and return.
            return(new MultiIndexGetResponse {
                Request = request,
                TotalHits = response.Hits.Count,
                Hits = response
                       .Hits
                       .Select(h => h.ToHit <object, object>())
                       .ToReadOnlyCollection()
            });
        }
Exemplo n.º 3
0
 public static MultiGetHit <T> Get <T>(this IMultiGetResponse response, Guid?id) where T : class
 {
     return(response.Get <T>(id.ToString()));
 }
Exemplo n.º 4
0
 public static ElasticMultiGetResponse SuccessResponse(IMultiGetResponse response)
 {
     return(new ElasticMultiGetResponse {
         Success = true, Response = response
     });
 }