Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ new ParentAggregation("name_of_parent_agg", typeof(CommitActivity)) <1>
}
----
<1> `join` field is determined from the _child_ type. In this example, it is `CommitActivity`

<2> sub-aggregations are on the type determined from the `join` field. In this example, a `Project` is a parent of `CommitActivity`

[source,javascript]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(1)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -43,7 +43,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 1,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits") &&
new DerivativeAggregation("commits_derivative", "commits")
Expand All @@ -58,7 +58,7 @@ new DateHistogramAggregation("projects_started_per_month")
"date_histogram": {
"field": "startedOn",
"interval": "month",
"min_doc_count": 1
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(1)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -48,7 +48,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 1,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new MovingAverageAggregation("commits_moving_avg", "commits")
Expand All @@ -69,7 +69,7 @@ new DateHistogramAggregation("projects_started_per_month")
"date_histogram": {
"field": "startedOn",
"interval": "month",
"min_doc_count": 1
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(1)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm.Field(p => p.NumberOfCommits))
.MovingAverage("commits_moving_avg", mv => mv
Expand All @@ -47,7 +47,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 1,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new MovingAverageAggregation("commits_moving_avg", "commits")
Expand All @@ -69,7 +69,7 @@ new DateHistogramAggregation("projects_started_per_month")
"date_histogram": {
"field": "startedOn",
"interval": "month",
"min_doc_count": 1
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(1)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand Down Expand Up @@ -54,7 +54,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 1,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new MovingAverageAggregation("commits_moving_avg", "commits")
Expand All @@ -81,7 +81,7 @@ new DateHistogramAggregation("projects_started_per_month")
"date_histogram": {
"field": "startedOn",
"interval": "month",
"min_doc_count": 1
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -46,6 +47,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits") &&
new MovingAverageAggregation("commits_moving_avg", "commits")
Expand All @@ -63,7 +65,8 @@ new DateHistogramAggregation("projects_started_per_month")
"projects_started_per_month": {
"date_histogram": {
"field": "startedOn",
"interval": "month"
"interval": "month",
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -48,6 +49,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new MovingAverageAggregation("commits_moving_avg", "commits")
Expand All @@ -67,7 +69,8 @@ new DateHistogramAggregation("projects_started_per_month")
"projects_started_per_month": {
"date_histogram": {
"field": "startedOn",
"interval": "month"
"interval": "month",
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -55,6 +56,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new MovingFunctionAggregation("commits_moving_avg", "commits")
Expand All @@ -73,7 +75,8 @@ new DateHistogramAggregation("projects_started_per_month")
"projects_started_per_month": {
"date_histogram": {
"field": "startedOn",
"interval": "month"
"interval": "month",
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
.Interval(DateInterval.Month)
.MinimumDocumentCount(1)
.MinimumDocumentCount(0)
.Aggregations(aa => aa
.Sum("commits", sm => sm
.Field(p => p.NumberOfCommits)
Expand All @@ -44,7 +44,7 @@ new DateHistogramAggregation("projects_started_per_month")
{
Field = "startedOn",
Interval = DateInterval.Month,
MinimumDocumentCount = 1,
MinimumDocumentCount = 0,
Aggregations =
new SumAggregation("commits", "numberOfCommits")
&& new SerialDifferencingAggregation("second_difference", "commits")
Expand All @@ -62,7 +62,7 @@ new DateHistogramAggregation("projects_started_per_month")
"date_histogram": {
"field": "startedOn",
"interval": "month",
"min_doc_count": 1
"min_doc_count": 0
},
"aggs": {
"commits": {
Expand Down
2 changes: 0 additions & 2 deletions docs/aggregations/writing-aggregations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ return s => s
);
----
<1> a list of aggregation functions to apply

<2> Using LINQ's `Aggregate()` function to accumulate/apply all of the aggregation functions

[[handling-aggregate-response]]
Expand Down Expand Up @@ -276,6 +275,5 @@ var maxPerChild = childAggregation.Max("max_per_child");
maxPerChild.Should().NotBeNull(); <2>
----
<1> Do something with the average per child. Here we just assert it's not null

<2> Do something with the max per child. Here we just assert it's not null

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ var pool = new CloudConnectionPool(cloudId, credentials); <2>
var client = new ElasticClient(new ConnectionSettings(pool));
----
<1> a username and password that can access Elasticsearch service on Elastic Cloud

<2> `cloudId` is a value that can be retrieved from the Elastic Cloud web console

This type of pool, like its parent the `SingleNodeConnectionPool`, is hardwired to opt out of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ the whole coordination of the request is deferred to a new instance in a `using`
var pipeline = new RequestPipeline(
settings,
DateTimeProvider.Default,
new MemoryStreamFactory(),
new RecyclableMemoryStreamFactory(),
new SearchRequestParameters());

pipeline.GetType().Should().Implement<IDisposable>();
Expand All @@ -41,7 +41,7 @@ var requestPipelineFactory = new RequestPipelineFactory();
var requestPipeline = requestPipelineFactory.Create(
settings,
DateTimeProvider.Default, <1>
new MemoryStreamFactory(),
new RecyclableMemoryStreamFactory(),
new SearchRequestParameters());

requestPipeline.Should().BeOfType<RequestPipeline>();
Expand All @@ -58,7 +58,7 @@ var transport = new Transport<IConnectionSettingsValues>(
settings,
requestPipelineFactory,
DateTimeProvider.Default,
new MemoryStreamFactory());
new RecyclableMemoryStreamFactory());

var client = new ElasticClient(transport);
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ audit = await audit.TraceUnexpectedException(
);
----
<1> set up a cluster with 10 nodes

<2> where node 2 on port 9201 always throws an exception

<3> The first call to 9200 returns a healthy response

<4> ...but the second call, to 9201, returns a bad response

Sometimes, an unexpected exception happens further down in the pipeline. In this scenario, we
Expand Down Expand Up @@ -101,9 +98,7 @@ audit = await audit.TraceUnexpectedException(
);
----
<1> calls on 9200 set up to throw a `HttpRequestException` or a `WebException`

<2> calls on 9201 set up to throw an `Exception`

<3> Assert that the audit trail for the client call includes the bad response from 9200 and 9201

An unexpected hard exception on ping and sniff is something we *do* try to recover from and failover to retrying on the next node.
Expand Down Expand Up @@ -148,8 +143,6 @@ audit = await audit.TraceUnexpectedException(
);
----
<1> `InnerException` is the exception that brought the request down

<2> The hard exception that happened on ping is still available though

<3> An exception can be hard to relate back to a point in time, so the exception is also available on the audit trail

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ var audit = new Auditor(() => VirtualClusterWith
);
----
<1> Always succeed on ping

<2> ...but always fail on calls with a 401 Bad Authentication response

Now, let's make a client call. We'll see that the first audit event is a successful ping
Expand All @@ -102,9 +101,7 @@ audit = await audit.TraceElasticsearchException(
);
----
<1> First call results in a successful ping

<2> Second call results in a bad response

<3> The reason for the bad response is Bad Authentication

When a bad authentication response occurs, the client attempts to deserialize the response body returned;
Expand Down Expand Up @@ -138,7 +135,6 @@ audit = await audit.TraceElasticsearchException(
);
----
<1> Always return a 401 bad response with a HTML response on client calls

<2> Assert that the response body bytes are null

Now in this example, by turning on `DisableDirectStreaming()` on `ConnectionSettings`, we see the same behaviour exhibited
Expand Down Expand Up @@ -173,6 +169,5 @@ audit = await audit.TraceElasticsearchException(
);
----
<1> Response bytes are set on the response

<2> Assert that the response contains `"nginx/"`

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ audit = await audit.TraceCall(
);
----
<1> Set the maximum number of retries to 3

<2> The client call trace returns an `MaxRetriesReached` audit after the initial attempt and the number of retries allowed

In our previous example we simulated very fast failures, but in the real world, a call might take upwards of a second.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ await audit.TraceCalls(
);
----
<1> The first call goes to 9200, which succeeds

<2> The 2nd call does a ping on 9201 because its used for the first time. This fails

<3> So we ping 9202. This _also_ fails

<4> We then ping 9203 because we haven't used it before and it succeeds

<5> Finally, we assert that the connection pool has two nodes that are marked as dead

All nodes are pinged on first use, provided they are healthy
Expand All @@ -125,6 +121,5 @@ await audit.TraceCalls(
);
----
<1> Pings on nodes always succeed

<2> A successful ping on each node

Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ audit = await audit.TraceCalls(
);
----
<1> disable sniffing

<2> first call is a successful ping

<3> sniff on startup call happens here, on the second call

<4> No sniff on startup again

Now, let's disable pinging on the request
Expand All @@ -93,7 +90,6 @@ audit = await audit.TraceCall(
);
----
<1> disable ping

<2> No ping after sniffing

Finally, let's demonstrate disabling both sniff and ping on the request
Expand All @@ -115,6 +111,5 @@ audit = await audit.TraceCall(
);
----
<1> disable ping and sniff

<2> no ping or sniff before the call

Loading