public SimpleQueryResults( Nest.ISearchResponse <T> searchResponse) { Documents = searchResponse.Documents; Took = searchResponse.Took; Total = searchResponse.Total; }
public AdvancedQueryResults( Nest.ISearchResponse <T> searchResponse) { Documents = searchResponse.Documents; Total = searchResponse.Total; Took = searchResponse.Took; Buckets = searchResponse.Aggregations?.BuildBucketResult(); }
public static FindResults <T> ToFindResults <T>(this Nest.ISearchResponse <T> response, int?limit = null) where T : class, new() { var docs = response.Hits.Take(limit ?? Int32.MaxValue).ToFindHits().ToList(); var data = response.ScrollId != null ? new DataDictionary { { ElasticDataKeys.ScrollId, response.ScrollId } } : null; return(new FindResults <T>(docs, response.Total, response.ToAggregations(), null, data)); }
public static IDictionary <string, IAggregate> ToAggregations <T>(this Nest.ISearchResponse <T> res) where T : class { return(res.Aggregations.ToAggregations()); }
private static bool ThereWasAnErrorWhileSearching(Nest.ISearchResponse <Elastic.Common.Entities.Address> search) { return(search != null && search.ConnectionStatus.Success && search.ConnectionStatus.OriginalException != null); }
public async Task <IQueryResult <T> > Query <T>(IDefinition definition) where T : class { Func <Nest.SearchDescriptor <T>, Nest.ISearchRequest> searchSelector = x => { x = x.Query(q => { foreach (var group in definition.Operations) { var option = Group.FromValue(group.Group); if (option == Group.All) { Nest.QueryContainer final = new Nest.MatchAllQuery(); foreach (var match in group.Definitions) { final = final && addOperation(q, match); } q.Bool(b => b.Must(final)); } else if (option == Group.Not) { Nest.QueryContainer final = new Nest.MatchAllQuery(); foreach (var match in group.Definitions) { final = final && addOperation(q, match); } q.Bool(b => b.Must(!final)); } else if (option == Group.Any) { Nest.QueryContainer final = new Nest.MatchAllQuery(); foreach (var match in group.Definitions) { final = final || addOperation(q, match); } q.Bool(b => b.Must(final)); } } return(q); }); return(x); }; var documents = new List <T>(); var elapsedMs = 0L; Nest.ISearchResponse <T> searchResult = await _client.SearchAsync <T>(x => { x = x.Index(typeof(T).FullName.ToLower()); x = x.SearchType(SearchType.QueryThenFetch); x = x.Scroll("4s"); return(searchSelector(x)); }).ConfigureAwait(false); if (!searchResult.IsValid) { _logger.WarnEvent("Invalid", "Elastic request: {Request}", searchResult.DebugInformation); throw new StorageException($"Invalid elastic request: {searchResult.DebugInformation}"); } do { documents.AddRange(searchResult.Documents); elapsedMs += searchResult.Took; searchResult = await _client.ScrollAsync <T>("4s", searchResult.ScrollId).ConfigureAwait(false); if (!searchResult.IsValid) { throw new StorageException($"Invalid elastic request: {searchResult.DebugInformation}"); } } while (searchResult.Documents.Any()); return(new QueryResult <T> { Records = documents.ToArray(), Total = searchResult.Total, ElapsedMs = elapsedMs }); }
public ActionResult Hledat(string id, string q, string osobaid, string ico) { var model = new Web.Models.UctySearchResult() { Query = q ?? "" }; if (string.IsNullOrEmpty(id)) { model.BU = null; } else { model.BU = HlidacStatu.Lib.Data.TransparentniUcty.BankovniUcty.Get(id); if (model.BU == null) { return(RedirectToAction("Index", "Ucty")); } } Nest.ISearchResponse <HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka> res = null; if (!string.IsNullOrEmpty(osobaid)) { res = HlidacStatu.Lib.Data.TransparentniUcty.BankovniUcty.SearchPolozkyForOsoba(osobaid, model.BU, 500); } else if (!string.IsNullOrEmpty(ico)) { res = HlidacStatu.Lib.Data.TransparentniUcty.BankovniUcty.SearchPolozkyForFirma(ico, model.BU, 500); } else if (!string.IsNullOrEmpty(model.InternalQuery) || model.Query.Length > 2) { res = HlidacStatu.Lib.Data.TransparentniUcty.BankovniUcty.SearchPolozkyRaw(model.InternalQuery ?? model.Query, model.BU, 500); } if (res != null && res.IsValid) { model.Polozky = res.Hits.Select(m => m.Source).ToArray(); } return(View(model)); }