//hide private void DictionaryConstructor(string name) { var vanilla = new Dictionary <string, AggregationContainer>() { { name, Terms(name) } }; var dictionary = new AggregationDictionary(vanilla); }
/// <summary> /// Query Information Model Constractor /// </summary> internal QueryInfo() { Fields = new List <EsField <T> >(); Sort = new List <EsSort <T> >(); Source = new List <Field>(); Aggregations = new AggregationDictionary(); termDictionary = new Dictionary <string, TermsAggregation>(); }
private static void StringAggregations(AggregationDictionary aggregationDict, IEnumerable <string> propertyFieldNames) { foreach (var propertyFieldName in propertyFieldNames) { aggregationDict.Add(propertyFieldName, new TermsAggregation(propertyFieldName) { Field = string.Format("properties.{0}.keyword", propertyFieldName) }); } }
private void Accept(IAggregationVisitor visitor, AggregationDictionary aggregations) { if (!aggregations.HasAny()) { return; } foreach (var f in aggregations) { this.Accept(visitor, f.Value, AggregationVisitorScope.Bucket); } }
private static void NumericAggregations(AggregationDictionary aggregationDict, IEnumerable <string> propertyFieldNames) { foreach (var propertyFieldName in propertyFieldNames) { aggregationDict.Add(propertyFieldName + ".max", new MaxAggregation(propertyFieldName, string.Format("properties.{0}", propertyFieldName))); aggregationDict.Add(propertyFieldName + ".min", new MinAggregation(propertyFieldName, string.Format("properties.{0}", propertyFieldName))); aggregationDict.Add(propertyFieldName + ".avg", new AverageAggregation(propertyFieldName, string.Format("properties.{0}", propertyFieldName))); } }
public static AggregationDictionary AggregationBuilder(List <string> stringPropertyFieldNames, List <string> numericPropertyFieldNames) { var aggregationDict = new AggregationDictionary(); if (stringPropertyFieldNames != null && stringPropertyFieldNames.Count > 0) { StringAggregations(aggregationDict, stringPropertyFieldNames); } if (numericPropertyFieldNames != null && numericPropertyFieldNames.Count > 0) { NumericAggregations(aggregationDict, numericPropertyFieldNames); } return(aggregationDict); }
/// <summary> /// Gets the simple aggregation "query" /// </summary> /// <returns>An AggregationDictionary containing the "query"</returns> /// <param name="facetConfig">Configuration for the field to aggregate</param> /// <param name="query"></param> private AggregationDictionary GetAggQuery(R4RAPIOptions.FacetConfig facetConfig, ResourceQuery query) { // If we *really* need the parentKey for this facet, then we must add it to the aggregation. // however, we may not really need it. var keyLabelAggregate = new TermsAggregation($"{facetConfig.FilterName}_key") { Field = new Field($"{facetConfig.FilterName}.key"), //Set the field to rollup Size = 999, //Use a large number to indicate unlimted (def is 10) // Now, we need to get the labels for the keys and thus // we need to add a sub aggregate for this term. // Normally you would do this for something like city/state rollups Aggregations = new TermsAggregation($"{facetConfig.FilterName}_label") { Field = new Field($"{facetConfig.FilterName}.label") } }; AggregationDictionary aggBody = keyLabelAggregate; // This facet requires a parent and thus needs a filter aggregate // to wrap the keyLabelAggregate if (!String.IsNullOrWhiteSpace(facetConfig.RequiresFilter)) { aggBody = new FilterAggregation($"{facetConfig.FilterName}_filter") { Filter = this.GetQueryForFilterField($"{facetConfig.FilterName}.parentKey", query.Filters[facetConfig.RequiresFilter]), Aggregations = keyLabelAggregate }; } //Start with a nested aggregation var agg = new NestedAggregation($"{facetConfig.FilterName}_agg") { Path = new Field(facetConfig.FilterName), //Set the path of the nested agg // Add the sub aggregates (bucket keys) Aggregations = aggBody }; return(agg); }
private static async Task Main() { var aggs = new AggregationDictionary { { "startDates", new TermsAggregation("startDates") { Field = "startedOn" } }, { "endDates", new DateHistogramAggregation("endDates") { Field = "endedOn" } } }; var a = new SearchRequest() { From = 10, Size = 20, Query = new QueryContainer(new MatchAllQuery()), Aggregations = aggs, PostFilter = new QueryContainer(new TermQuery { Field = "state", Value = "Stable" }) }; var client = new ElasticClient(); client.Update <Person>("a", d => d.Index("test").Script(s => s.Source("script").Params(new Dictionary <string, object?> { { "null", new Person { FirstName = null, LastName = "test-surname" } } }))); var people = new List <Person>() { new Person { FirstName = "Steve", LastName = "Gordon" }, new Person { FirstName = "Steve", LastName = "Gordon" }, new Person { FirstName = "Steve", LastName = "Gordon" }, new Person { FirstName = "Steve", LastName = "Gordon" }, new Person { FirstName = "Steve", LastName = "Gordon" }, }; //using var bulk = client.BulkAll(people, r => r.Index("testing-v7")); //var result = bulk.Wait(TimeSpan.FromSeconds(60), a => { Console.WriteLine(a.Items.Count); }); //var a1 = result.TotalNumberOfRetries; //var b1 = result.TotalNumberOfFailedBuffers; using var bulk2 = client.BulkAll(people, r => r); var result2 = bulk2.Wait(TimeSpan.FromSeconds(60), a => { Console.WriteLine(a.Items.Count); }); var a12 = result2.TotalNumberOfRetries; var b12 = result2.TotalNumberOfFailedBuffers; //var responseBulk = client.Bulk(new BulkRequest //{ // Operations = new List<IBulkOperation> //{ // new BulkIndexOperation<Person>(new Person()) { Index = "people" } , // new BulkIndexOperation<Person>(new Person()) { Index = "people", IfSequenceNumber = -1, IfPrimaryTerm = 0 } //} //}); var response = client.Index(new Person(), e => e.Index("test")); var settingsResponse = await client.Indices.CreateAsync("a", i => i.Settings(s => s.Analysis(a => a.TokenFilters(tf => tf .Shingle("my-shingle", s => s.MinShingleSize(2)) .Snowball("my_snowball", s => s.Version("v1")))))); //var c1 = new ElasticClient(new ConnectionSettings(new Uri("https://azure.es.eastus.azure.elastic-cloud.com:9243")).BasicAuthentication("a", "b").ThrowExceptions()); //var r1 = await c1.PingAsync(); #pragma warning disable IDE0039 // Use local function Func <BoolQueryDescriptor <Person>, IBoolQuery> test = b => b.Name("thing");
public TBucketAggregation Aggregations(AggregationDictionary aggregations) => Assign(aggregations, (a, v) => a.Aggregations = v);
public SearchBuilder <T> AddAggregation(AggregationDictionary aggregations) { _Request.Aggregations = aggregations; return(this); }