public static SearchDescriptor <T> WithPagination <T>( this SearchDescriptor <T> descriptor, int pageIndex, int pageSize) where T : class { return(descriptor .From((pageIndex - 1) * pageSize) .Size(pageSize)); }
public async Task <IEnumerable <DatasetInfo> > GetDatasetsForTagsAsync(string ownerId, string repositoryId, string[] tags, int skip = 0, int take = 25, bool matchAll = false, bool showHidden = false) { if (tags == null) { throw new ArgumentNullException(nameof(tags)); } var search = new SearchDescriptor <DatasetInfo>().Query(q => QueryHelper.FilterRepositoryByTags(ownerId, repositoryId, tags, matchAll, showHidden)); var rawQuery = ""; #if DEBUG using (var ms = new MemoryStream()) { _client.RequestResponseSerializer.Serialize(search, ms); rawQuery = Encoding.UTF8.GetString(ms.ToArray()); Console.WriteLine(rawQuery); } #endif var searchResponse = await _client.SearchAsync <DatasetInfo>(search .From(skip).Size(take)); if (!searchResponse.IsValid) { throw new DatasetStoreException( $"Error retrieving datasets for repository {ownerId}/{repositoryId} with tags {string.Join(", ", tags)}. Cause: {searchResponse.DebugInformation}"); } if (searchResponse.Total < 1) { throw new DatasetNotFoundException($"No datasets found for repository {ownerId}/{repositoryId} with tags {string.Join(", ", tags)}."); } return(searchResponse.Documents); }
private async Task <IEnumerable <T> > GetListWithUpdatedData(ISearchResponse <T> result) { IEnumerable <T> listOfResultsToBeModified = new List <T>(); var resultHits = result.Hits.Count; for (int i = 0; i < resultHits; i += 1000) { SearchDescriptor <T> queryCommandToRegisters = new SearchDescriptor <T>(); queryCommandToRegisters.From(i).Size(1000); var response = await BasicQuery(queryCommandToRegisters); var registerToBeModified = await _logElasticMappers.MapElasticResults(response, "", true); listOfResultsToBeModified = listOfResultsToBeModified.Concat(registerToBeModified.Records).ToList(); } var checkDate = listOfResultsToBeModified.FirstOrDefault(); if (checkDate != null) { var lastDateResource = (DateTime)checkDate.GetType().GetProperty("DateTimeLogged").GetValue(checkDate); if (!(lastDateResource.Day.Equals(DateTime.Now.Day - 1) && lastDateResource.Month.Equals(DateTime.Now.Month) && lastDateResource.Year.Equals(DateTime.Now.Year))) { listOfResultsToBeModified = _logElasticMappers.UpdateDate(listOfResultsToBeModified); } } return(listOfResultsToBeModified); }
public SearchDescriptor <User> QueryMoreUsersByState(string state) { var searchDescriptor = new SearchDescriptor <User>().Index(_indexName); searchDescriptor.Query(q => q.Term(r => r.State, state)); searchDescriptor.From(5); searchDescriptor.Size(100); return(searchDescriptor); }
public SearchDescriptor <User> QuerySortByState() { var searchDescriptor = new SearchDescriptor <User>().Index(_indexName); searchDescriptor.Sort(q => q.Field("state", SortOrder.Descending)); searchDescriptor.From(0); searchDescriptor.Size(100); return(searchDescriptor); }
public static SearchDescriptor <T> AddPaging <T>(this SearchDescriptor <T> descriptor, SearchOptions options) where T : class { if (options != null) { var size = options.Size; var from = (options.Page - 1) * options.Size; descriptor.From(from).Size(size); } return(descriptor); }
public void EventList_Test() { var search = new SearchDescriptor <EventReceiver>(); search .From(0) .Size(10); var receiver = _eventReceiverDao.List(search); Assert.Equal(0, receiver.Count); }
private static string Search(ElasticClient client) { SearchDescriptor <OrderSearch> searchDescriptor = new SearchDescriptor <OrderSearch>(); searchDescriptor.From(0) .Size(10) .Query(Query); var requestjson = client.RequestResponseSerializer.SerializeToString(searchDescriptor); var searchResponse = client.Search <OrderSearch>(searchDescriptor); var orders = searchResponse.Documents; return(JsonConvert.SerializeObject(orders.ToArray())); }
public IEnumerable <Airport> GetAirport(AirportRequest request) { var searchCriterias = new SearchDescriptor <EsAirport>(); searchCriterias .From(request.StartingIndex) .Size(request.ResponseSize) .Source(src => src.Includes(i => i.Fields(EsHelpers.GenerateFields(request)))) .Query(q => q.Bool(b => b.Must(EsHelpers.QueryGenerator(request)))); var jsonResponse = dataAccess.AirportElasticClient.Search <object>(searchCriterias); return(CreateAirportResponse(jsonResponse.Documents)); }
private SearchDescriptor <Recipe> Filter(SearchDescriptor <Recipe> search, string ingredients, string effects, string types) { var updatedSearch = search .From(0) .Size(1000) .Sort(i => i.Descending("hearts").Ascending("type.keyword").Ascending("name.keyword")); return(updatedSearch.Query(query => query .Bool(b => b .Must(bm => { QueryContainer container = null; if (!String.IsNullOrWhiteSpace(ingredients)) { foreach (var val in ingredients.Split(",")) { container &= bm.Term(t => t.Field("ingredients.keyword").Value(val)); } } if (!String.IsNullOrWhiteSpace(effects)) { QueryContainer effectContainer = null; foreach (var val in effects.Split(",")) { effectContainer |= bm.Match(t => t.Field("effects").Query(val)); } container &= effectContainer; } if (!String.IsNullOrWhiteSpace(types)) { QueryContainer typeContainer = null; foreach (var val in types.Split(",")) { typeContainer |= bm.Term(t => t.Field("type.keyword").Value(val)); } container &= typeContainer; } return container; }) ) )); }
public IReadOnlyCollection <EventReceiver> List(int from, int size, string tag) { var search = new SearchDescriptor <EventReceiver>(); search .From(from) .Size(size) .Query(q => q .Match(m => m .Field(f => f.Tag) .Query(tag) ) ); return(_receiverDao.List(search)); }
public IEnumerable <BusinessIndexModel> SearchBusiness(string name, int countryId = 0, int page = 1, int pageSize = 10) { int offset = pageSize * (page - 1); var query = new SearchDescriptor <BusinessIndexModel>(); var filter = SearchBusinessQueryFilter(name, countryId); query.Query(q => filter); //query.Type<BusinessIndexModel>(); //query.TypedKeys(false); query.From(offset); query.Size(pageSize); query.Sort(f => f.Descending(x => x.Name)); ISearchResponse <BusinessIndexModel> sr = client.Search <BusinessIndexModel>(query); return(sr.Documents); }
public async Task <IEnumerable <DatasetInfo> > SearchDatasetsAsync(string searchString, int skip, int take) { if (searchString == null) { throw new ArgumentNullException(nameof(searchString)); } var terms = searchString.Split(' '); var searchClauses = new List <QueryContainer> { new TermsQuery { Field = "tags", Terms = searchString.Split(' '), Boost = 2.0 }, new TermsQuery { Field = "csvwMetadata.dc:title", Terms = terms, Boost = 1.5 }, new TermsQuery { Field = "csvwMetadata.dc:description", Terms = terms } }; var search = new SearchDescriptor <DatasetInfo>().Query(q => new BoolQuery { Should = searchClauses }); #if DEBUG using (var ms = new MemoryStream()) { _client.RequestResponseSerializer.Serialize(search, ms); var rawQuery = Encoding.UTF8.GetString(ms.ToArray()); Console.WriteLine(rawQuery); } #endif var searchResponse = await _client.SearchAsync <DatasetInfo>(search .From(skip).Size(take)); if (!searchResponse.IsValid) { throw new DatasetStoreException( $"Error retrieving datasets for search string repository {searchString}. Cause: {searchResponse.DebugInformation}"); } if (searchResponse.Total < 1) { throw new DatasetNotFoundException($"No datasets found for search string '{searchString}'."); } return(searchResponse.Documents); }
public SearchDescriptor <T> DescribeSearch(SearchDescriptor <T> search) { search.Index(indexName).Type(typeName); type.DescribeSearch(search, Parameters); if (!string.IsNullOrEmpty(Parameters["count"])) { search.Size(int.Parse(Parameters["count"])); } else { search.Size(OpenSearchEngine.DEFAULT_COUNT); } if (!string.IsNullOrEmpty(Parameters["startIndex"])) { search.From(int.Parse(Parameters["startIndex"]) - 1); } return(search); }
public ElasticResponse <T>[] ExecuteSearchRequestWithScroll <T>(SearchDescriptor <T> searchDescriptor) where T : class { var scrollTime = new Time(2000); var searchDescriptorWithScroll = searchDescriptor.From(0).Size(10).Scroll(scrollTime); var results = new List <ElasticResponse <T> >(); try { var client = GetElasticClient(); var response = client.Search <T>(s => searchDescriptorWithScroll); if (!response.ApiCall.Success) { return new[] { ElasticResponse <T> .FailResponse(response.ApiCall.OriginalException.Message) } } ; results.Add(ElasticResponse <T> .SuccessResponse(response)); do { var currentResponse = response; response = client.Scroll <T>(scrollTime, currentResponse.ScrollId); if (!response.ApiCall.Success) { return new[] { ElasticResponse <T> .FailResponse(response.ApiCall.OriginalException.Message) } } ; results.Add(ElasticResponse <T> .SuccessResponse(response)); } while (response.IsValid && response.Documents.Any()); return(results.ToArray()); } catch { return(new[] { ElasticResponse <T> .FailResponse(ServerErrorMessage) }); } }
public SearchDescriptor <T> Convert(Criteria criteria, string index) { if (criteria == null) { return(new SearchDescriptor <T>()); } var searchDescriptor = new SearchDescriptor <T>(); searchDescriptor.From(criteria.Offset ?? 0); searchDescriptor.Size(criteria.Limit ?? 1000); if (criteria.HasFilters()) { searchDescriptor.Query(q => QueryByCriteria(criteria)); } if (criteria.HasOrder()) { searchDescriptor.Sort(s => CreateSortDescriptor(s, criteria)); } searchDescriptor.Index(index); return(searchDescriptor); }
/// <summary> /// Searches the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="searchType">Type of the search.</param> /// <param name="entities">The entities.</param> /// <param name="fieldCriteria">The field criteria.</param> /// <param name="size">The size.</param> /// <param name="from">From.</param> /// <param name="totalResultsAvailable">The total results available.</param> /// <returns></returns> public override List <IndexModelBase> Search(string query, SearchType searchType, List <int> entities, SearchFieldCriteria fieldCriteria, int?size, int?from, out long totalResultsAvailable) { List <IndexModelBase> documents = new List <IndexModelBase>(); totalResultsAvailable = 0; if (_client != null) { ISearchResponse <dynamic> results = null; List <SearchResultModel> searchResults = new List <SearchResultModel>(); QueryContainer queryContainer = new QueryContainer(); // add and field constraints var searchDescriptor = new SearchDescriptor <dynamic>().AllIndices(); if (entities == null || entities.Count == 0) { searchDescriptor = searchDescriptor.AllTypes(); } else { var entityTypes = new List <string>(); foreach (var entityId in entities) { // get entities search model name var entityType = new EntityTypeService(new RockContext()).Get(entityId); entityTypes.Add(entityType.IndexModelType.Name.ToLower()); // check if this is a person model, if so we need to add two model types one for person and the other for businesses // wish there was a cleaner way to do this if (entityType.Guid == SystemGuid.EntityType.PERSON.AsGuid()) { entityTypes.Add("businessindex"); } } searchDescriptor = searchDescriptor.Type(string.Join(",", entityTypes)); // todo: consider adding indexmodeltype to the entity cache } QueryContainer matchQuery = null; if (fieldCriteria != null && fieldCriteria.FieldValues?.Count > 0) { foreach (var match in fieldCriteria.FieldValues) { if (fieldCriteria.SearchType == CriteriaSearchType.Or) { matchQuery |= new MatchQuery { Field = match.Field, Query = match.Value, Boost = match.Boost }; } else { matchQuery &= new MatchQuery { Field = match.Field, Query = match.Value }; } } } switch (searchType) { case SearchType.ExactMatch: { if (!string.IsNullOrWhiteSpace(query)) { queryContainer &= new QueryStringQuery { Query = query, AnalyzeWildcard = true }; } // special logic to support emails if (query.Contains("@")) { queryContainer |= new QueryStringQuery { Query = "email:" + query, Analyzer = "whitespace" }; // analyzer = whitespace to keep the email from being parsed into 3 variables because the @ will act as a delimitor by default } // special logic to support phone search if (query.IsDigitsOnly()) { queryContainer |= new QueryStringQuery { Query = "phone:*" + query + "*", AnalyzeWildcard = true }; } // add a search for all the words as one single search term queryContainer |= new QueryStringQuery { Query = query, AnalyzeWildcard = true, PhraseSlop = 0 }; if (matchQuery != null) { queryContainer &= matchQuery; } if (size.HasValue) { searchDescriptor.Size(size.Value); } if (from.HasValue) { searchDescriptor.From(from.Value); } searchDescriptor.Query(q => queryContainer); results = _client.Search <dynamic>(searchDescriptor); break; } case SearchType.Fuzzy: { results = _client.Search <dynamic>(d => d.AllIndices().AllTypes() .Query(q => q.Fuzzy(f => f.Value(query) .Rewrite(RewriteMultiTerm.TopTermsN)) ) ); break; } case SearchType.Wildcard: { bool enablePhraseSearch = true; if (!string.IsNullOrWhiteSpace(query)) { QueryContainer wildcardQuery = null; // break each search term into a separate query and add the * to the end of each var queryTerms = query.Split(' ').Select(p => p.Trim()).ToList(); // special logic to support emails if (queryTerms.Count == 1 && query.Contains("@")) { wildcardQuery |= new QueryStringQuery { Query = "email:*" + query + "*", Analyzer = "whitespace" }; enablePhraseSearch = false; } else { foreach (var queryTerm in queryTerms) { if (!string.IsNullOrWhiteSpace(queryTerm)) { wildcardQuery &= new QueryStringQuery { Query = queryTerm + "*", Analyzer = "whitespace", Rewrite = RewriteMultiTerm.ScoringBoolean }; // without the rewrite all results come back with the score of 1; analyzer of whitespaces says don't fancy parse things like check-in to 'check' and 'in' } } // add special logic to help boost last names if (queryTerms.Count > 1) { QueryContainer nameQuery = null; nameQuery &= new QueryStringQuery { Query = "lastName:" + queryTerms.Last() + "*", Analyzer = "whitespace", Boost = 30 }; nameQuery &= new QueryStringQuery { Query = "firstName:" + queryTerms.First() + "*", Analyzer = "whitespace" }; wildcardQuery |= nameQuery; } // special logic to support phone search if (query.IsDigitsOnly()) { wildcardQuery |= new QueryStringQuery { Query = "phoneNumbers:*" + query, Analyzer = "whitespace" }; } } queryContainer &= wildcardQuery; } // add a search for all the words as one single search term if (enablePhraseSearch) { queryContainer |= new QueryStringQuery { Query = query, AnalyzeWildcard = true, PhraseSlop = 0 }; } if (matchQuery != null) { queryContainer &= matchQuery; } if (size.HasValue) { searchDescriptor.Size(size.Value); } if (from.HasValue) { searchDescriptor.From(from.Value); } searchDescriptor.Query(q => queryContainer); var indexBoost = GlobalAttributesCache.Value("UniversalSearchIndexBoost"); if (indexBoost.IsNotNullOrWhiteSpace()) { var boostItems = indexBoost.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (var boostItem in boostItems) { var boostParms = boostItem.Split(new char[] { '^' }); if (boostParms.Length == 2) { int boost = 1; Int32.TryParse(boostParms[1], out boost); searchDescriptor.IndicesBoost(b => b.Add(boostParms[0], boost)); } } } results = _client.Search <dynamic>(searchDescriptor); break; } } totalResultsAvailable = results.Total; // normalize the results to rock search results if (results != null) { foreach (var hit in results.Hits) { IndexModelBase document = new IndexModelBase(); try { if (hit.Source != null) { Type indexModelType = Type.GetType($"{ ((string)((JObject)hit.Source)["indexModelType"])}, { ((string)((JObject)hit.Source)["indexModelAssembly"])}"); if (indexModelType != null) { document = (IndexModelBase)((JObject)hit.Source).ToObject(indexModelType); // return the source document as the derived type } else { document = ((JObject)hit.Source).ToObject <IndexModelBase>(); // return the source document as the base type } } if (hit.Explanation != null) { document["Explain"] = hit.Explanation.ToJson(); } document.Score = hit.Score; documents.Add(document); } catch { } // ignore if the result if an exception resulted (most likely cause is getting a result from a non-rock index) } } } return(documents); }
/// <summary> /// Filter search template, services for many kinds of searching, such as brand, patent, and so on. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pg_index"></param> /// <param name="pg_size"></param> /// <param name="des"></param> /// <param name="keyfun">function to create key-search-querycontainer</param> /// <param name="filterfun">function to create filter-querycontainer</param> /// <returns></returns> private static ISearchResponse <T> FSearch_Template <T>(int pg_index, int pg_size, SearchDescriptor <T> des, Func <QueryContainerDescriptor <T>, QueryContainer> keyfun, Func <QueryContainerDescriptor <T>, QueryContainer> filterfun) where T : class => Client_Get().Search <T>(des.From(pg_index * pg_size).Take(pg_size).Query(q => keyfun(q) & filterfun(q)));
public SearchResult <Suggestion> QuickSearch(string q, SearchParameters parameters) { int limit = parameters.Limit == 0 ? 10 : parameters.Limit; int from = (parameters.PageNumber - 1) * limit; SearchDescriptor <object> descriptor = new SearchDescriptor <object>(); descriptor = descriptor.From(from).Size(limit); IList <FilterContainer> filters = new List <FilterContainer>(); FilterDescriptor <object> baseFilter = new FilterDescriptor <object>(); filters.Add(baseFilter.Term("accountID", parameters.AccountId)); if (parameters != null && parameters.IsPrivateSearch && parameters.PrivateModules.IsAny() && (parameters.PrivateModules.Contains(Entities.AppModules.Campaigns) || parameters.PrivateModules.Contains(Entities.AppModules.Forms))) { filters.Add(baseFilter.Term("ownerId", parameters.DocumentOwnerId.ToString())); //if(parameters.PrivateModules.Count() > 0 && //parameters.PrivateModules.Contains(Entities.AppModules.Campaigns) ) // filters.Add(baseFilter.Term("status", 109)); } if (filters.Count > 1) { descriptor = descriptor.Filter(f => f.And(filters.ToArray())); } else { descriptor = descriptor.Filter(f => f.Term("accountID", parameters.AccountId)); } //descriptor = descriptor.Filter(f => f.Term("accountID", parameters.AccountId)); string[] selectedIndices = null; Type[] types = null; if (parameters != null && parameters.Types.IsAny()) { selectedIndices = parameters.Types.Where(t => indices.ContainsKey(t)).Select(t => indices[t]).Distinct().ToArray(); types = parameters.Types.Distinct().ToArray(); } else { selectedIndices = indices.Select(c => c.Value).Distinct().ToArray(); types = indices.Select(c => c.Key).Distinct().ToArray(); } descriptor = descriptor.Indices(selectedIndices).IndicesBoost(b => b .Add("contacts" + this.accountId, 3.5).Add("campaigns" + this.accountId, 3.0).Add("opportunities", 2.5)); descriptor = descriptor.Types(types); if (!string.IsNullOrEmpty(q)) { string queryString = q + "*" + " " + q; if (parameters != null && parameters.PrivateModules.IsAny()) { string createdByTerm = string.Empty; string createdByTermValue = string.Empty; string ownerIdTerm = string.Empty; string ownerIdTermValue = string.Empty; if (parameters.PrivateModules.Contains(Entities.AppModules.Campaigns) || parameters.PrivateModules.Contains(Entities.AppModules.Forms)) { createdByTerm = "createdBy"; createdByTermValue = parameters.DocumentOwnerId.ToString(); } if (parameters.PrivateModules.Contains(Entities.AppModules.Contacts) || parameters.PrivateModules.Contains(Entities.AppModules.Opportunity)) { ownerIdTerm = "ownerId"; ownerIdTermValue = parameters.DocumentOwnerId.ToString(); } IList <string> contactIndices = new List <string>(); if (parameters.PrivateModules.Contains(Entities.AppModules.Contacts)) { contactIndices.Add("contacts" + this.accountId); } //if (parameters.PrivateModules.Contains(Entities.AppModules.Opportunity)) commented by Ram on 2nd May 2018 CR NEXG-3001 // contactIndices.Add("opportunities"); commented by Ram on 2nd May 2018 CR NEXG-3001 //if (parameters.PrivateModules.Contains(Entities.AppModules.Campaigns)) commented by Ram on 2nd May 2018 CR NEXG-3001 // contactIndices.Add("campaigns" + this.accountId); commented by Ram on 2nd May 2018 CR NEXG-3001 if (parameters.PrivateModules.Contains(Entities.AppModules.Forms)) { contactIndices.Add("forms"); } //descriptor = descriptor.Query(qr=>qr.Filtered(flt=>flt.Query(qs=>qs.in))) // descriptor = descriptor.Query(qu => qu.Indices(i => i.Indices(contactIndices) //.NoMatchQuery(nm => nm.Term(createdByTerm, createdByTermValue)).NoMatchQuery(nm => nm.Term(ownerIdTerm, ownerIdTermValue)).Query(qr => qr.QueryString(qs => qs.Query(q)))));//Term(ownerIdTerm, ownerIdTermValue) //modified descriptor = descriptor.Query(qu => qu.Indices(i => i.Indices(contactIndices). NoMatchQuery(nm => nm.QueryString(qs => qs.Query(queryString))). Query(que => que.Bool(b => b.Must( s => s.Bool(bo => bo.Should(sh => sh.Term(createdByTerm, createdByTermValue), sh => sh.Term(ownerIdTerm, ownerIdTermValue))), s => s.QueryString(qs => qs.Query(queryString).OnFieldsWithBoost(o => o.Add("firstName", 5).Add("lastName", 5).Add("emails.emailId", 5).Add("companyName", 3.5).Add("_all", 2)))))))); } else { descriptor = descriptor.Query(query => query.QueryString(qs => qs.Query(queryString).OnFieldsWithBoost(o => o.Add("firstName", 5).Add("lastName", 5).Add("emails.emailId", 5).Add("companyName", 3.5).Add("_all", 2)))); } } /* * Don't show archived campaigns, search by account id, don't show unsubscribed email * */ descriptor = descriptor.Filter(f => f.And(query => !query.Term("campaignStatus", CampaignStatus.Archive), query => query.Term("accountID", parameters.AccountId))); var result = this.ElasticClient().Search <object>(body => descriptor); string qe = result.ConnectionStatus.ToString(); Logger.Current.Verbose(qe); var searchResult = convertToSuggestions(result.Documents, parameters); searchResult.TotalHits = result.Total; return(searchResult); }
/// <summary> /// Search templat, services for many kinds of searching, such as brand, patent, and so on. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pg_size"></param> /// <param name="des"></param> /// <param name="qfun"></param> /// <param name="pg_index"></param> /// <returns></returns> private static ISearchResponse <T> Search_Template <T>(int pg_size, SearchDescriptor <T> des, Func <QueryContainerDescriptor <T>, QueryContainer> qfun, int pg_index = 0) where T : class => Client_Get().Search <T>(des.From(pg_index * pg_size).Take(pg_size).Query(qfun));
public static async Task Run() { var product1 = new Product { ID = Guid.NewGuid(), Name = "高露洁牙膏", Price = 20, Desc = "一种牙膏", Producer = "高露洁", Tags = new List <string> { "高效美白", "修复牙齿" } }; var product2 = new Product { ID = Guid.NewGuid(), Name = "佳洁士牙膏", Price = 30, Desc = "一种", Producer = "佳洁士", Tags = new List <string> { "高效美白" } }; var product3 = new Product { ID = Guid.NewGuid(), Name = "冷酸灵牙膏", Price = 40, Desc = "一种牙膏", Producer = "冷酸灵", Tags = new List <string> { "修复牙齿" } }; var elasticsearchHelper = new ElasticsearchHelper <Product, Guid>("http://116.55.251.31:9200"); await elasticsearchHelper.InsertDocumentAsync(product1); await elasticsearchHelper.InsertDocumentAsync(product2); await elasticsearchHelper.InsertDocumentAsync(product3); SearchDescriptor <Product> query = elasticsearchHelper.GetNewQuery(); query = query.From(0).Size(10).Query(q => q.Match(m => m.Field(f => f.Name).Query("牙膏"))); await Task.Delay(2000); await Search(elasticsearchHelper, query); product1.Name = product1.Name + "1"; product2.Name = product2.Name + "1"; product3.Name = product3.Name + "1"; await elasticsearchHelper.UpdateDocumentAsync(product1); await elasticsearchHelper.UpdateDocumentAsync(product2); await elasticsearchHelper.UpdateDocumentAsync(product3); await Task.Delay(2000); await Search(elasticsearchHelper, query); await elasticsearchHelper.DeleteDocumentAsync(product1.ID); await elasticsearchHelper.DeleteDocumentAsync(product2.ID); await elasticsearchHelper.DeleteDocumentAsync(product3.ID); await Task.Delay(2000); await Search(elasticsearchHelper, query); }