Skip to content

Commit cb95fdc

Browse files
Update documentation (#8537) (#8544)
Co-authored-by: Florian Bernd <git@flobernd.de>
1 parent 23a8dac commit cb95fdc

17 files changed

+264
-652
lines changed

README.md

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Repository for **Elastic.Clients.Elasticsearch** the official .NET client for
44
[Elasticsearch](https://github.com/elastic/elasticsearch).
5-
*Older branches include both previous clients, **NEST** and **Elasticsearch.Net**.*
65

76
**[Download the latest version of Elasticsearch](https://www.elastic.co/downloads/elasticsearch)**
87
or
@@ -61,40 +60,13 @@ for comprehensive information on installation, configuration and usage.
6160

6261
The API reference documentation is available [here](https://elastic.github.io/elasticsearch-net).
6362

64-
## Versions
65-
66-
### Elasticsearch 8.x Clusters
67-
68-
We have released the next generation of the .NET client for Elasticsearch, which
69-
aligns with v8 of Elasticsearch. We have renamed this library
70-
`Elastic.Clients.Elasticsearch`, and the packages are published on
71-
[NuGet](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch/). The
72-
8.0.x versions do not offer complete feature parity with the existing `NEST`
73-
client. We therefore recommend you thoroughly review our
74-
[release notes and migration guidance](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/release-notes-8.0.0.html)
75-
before attempting to migrate existing applications to the
76-
`Elastic.Clients.Elasticsearch` library.
77-
78-
Until the new client supports all endpoints and features your application
79-
requires, you may continue to use the latest `7.17.x` client to communicate with
80-
Elasticsearch v8 servers. Please review
81-
[our documentation](https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.17/connecting-to-elasticsearch-v8.html),
82-
which describes how to enable compatibility mode and secure communications with
83-
a v8 cluster.
84-
85-
### Elasticsearch 7.x Clusters
86-
87-
We recommend using the latest `7.17.x`
88-
[NEST client](https://www.nuget.org/packages/Nest) to communicate with
89-
Elasticsearch v7 servers.
90-
9163
## Contributing
9264

9365
See [CONTRIBUTING.md](./CONTRIBUTING.md)
9466

9567
## Copyright and License
9668

97-
This software is Copyright (c) 2014-2022 by Elasticsearch BV.
69+
This software is Copyright (c) 2014-2025 by Elasticsearch BV.
9870

9971
This is free software, licensed under
10072
[The Apache License Version 2.0](https://github.com/elastic/elasticsearch-net/blob/main/LICENSE.txt).

docs/reference/_options_on_elasticsearchclientsettings.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ The following is a list of available connection configuration options on `Elasti
2020
`Base64ApiKey` for Elastic Cloud style encoded api keys
2121
```
2222

23-
2423
`ClientCertificate`
2524
: Use the following certificates to authenticate all HTTP requests. You can also set them on individual request using `ClientCertificates`.
2625

@@ -34,7 +33,6 @@ The following is a list of available connection configuration options on `Elasti
3433

3534
For Core CLR, this setting applies to the `MaxConnectionsPerServer` property on the `HttpClientHandler` instances used by the `HttpClient` inside the default `IConnection` implementation.
3635

37-
3836
`DeadTimeout`
3937
: The time to put dead nodes out of rotation (this will be multiplied by the number of times they’ve been dead).
4038

@@ -43,13 +41,11 @@ The following is a list of available connection configuration options on `Elasti
4341

4442
The client by default will use the value of a property named `Id` on a CLR type as the `_id` to send to {{es}}. Adding a type will disable this behaviour for that CLR type. If `Id` inference should be disabled for all CLR types, use `DefaultDisableIdInference`.
4543

46-
4744
`DefaultFieldNameInferrer`
4845
: Specifies how field names are inferred from CLR property names.
4946

5047
By default, the client camel cases property names. For example, CLR property `EmailAddress` will be inferred as "emailAddress" {{es}} document field name.
5148

52-
5349
`DefaultIndex`
5450
: The default index to use for a request when no index has been explicitly specified and no default indices are specified for the given CLR type specified for the request.
5551

@@ -82,7 +78,6 @@ The following is a list of available connection configuration options on `Elasti
8278

8379
For Desktop CLR, sets `ServicePointManager`.`SetTcpKeepAlive`.
8480

85-
8681
`EnableTcpStats`
8782
: Enable statistics about TCP connections to be collected when making a request.
8883

@@ -110,8 +105,8 @@ The following is a list of available connection configuration options on `Elasti
110105
`OnRequestCompleted`
111106
: Allows you to register a callback every time a an API call is returned.
112107

113-
`OnRequestDataCreated`
114-
: An action to run when the `RequestData` for a request has been created.
108+
`OnBeforeRequest`
109+
: An action to run before a request is made.
115110

116111
`PingTimeout`
117112
: The timeout in milliseconds to use for ping requests, which are issued to determine whether a node is alive.
@@ -121,7 +116,6 @@ The following is a list of available connection configuration options on `Elasti
121116

122117
Note: this is not a guarantee you will always get prettified json.
123118

124-
125119
`Proxy`
126120
: If your connection has to go through proxy, use this method to specify the proxy url.
127121

@@ -148,7 +142,6 @@ The following is a list of available connection configuration options on `Elasti
148142

149143
Reasons for such exceptions could be search parser errors, index missing exceptions, and so on.
150144

151-
152145
`TransferEncodingChunked`
153146
: Whether the request should be sent with chunked Transfer-Encoding.
154147

@@ -171,5 +164,3 @@ var settings= new ElasticsearchClientSettings()
171164

172165
var client = new ElasticsearchClient(settings);
173166
```
174-
175-

docs/reference/aggregations.md

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,124 +7,127 @@ mapped_pages:
77

88
This page demonstrates how to use aggregations.
99

10-
1110
## Top-level aggreggation [_top_level_aggreggation]
1211

13-
1412
### Fluent API [_fluent_api]
1513

1614
```csharp
17-
var response = await client
18-
.SearchAsync<Person>(search => search
19-
.Index("persons")
20-
.Query(query => query
21-
.MatchAll(_ => {})
22-
)
23-
.Aggregations(aggregations => aggregations
24-
.Add("agg_name", aggregation => aggregation
25-
.Max(max => max
26-
.Field(x => x.Age)
27-
)
28-
)
29-
)
30-
.Size(10)
31-
);
15+
var response = await client.SearchAsync<Person>(search => search
16+
.Indices("persons")
17+
.Query(query => query
18+
.MatchAll()
19+
)
20+
.Aggregations(aggregations => aggregations
21+
.Add("agg_name", aggregation => aggregation
22+
.Max(max => max
23+
.Field(x => x.Age)
24+
)
25+
)
26+
)
27+
.Size(10)
28+
);
3229
```
3330

34-
3531
### Object initializer API [_object_initializer_api]
3632

3733
```csharp
3834
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
3935
{
40-
Query = Query.MatchAll(new MatchAllQuery()),
41-
Aggregations = new Dictionary<string, Aggregation>
42-
{
43-
{ "agg_name", Aggregation.Max(new MaxAggregation
44-
{
45-
Field = Infer.Field<Person>(x => x.Age)
46-
})}
47-
},
48-
Size = 10
36+
Query = new Query
37+
{
38+
MatchAll = new MatchAllQuery()
39+
},
40+
Aggregations = new Dictionary<string, Aggregation>
41+
{
42+
{ "agg_name", new Aggregation
43+
{
44+
Max = new MaxAggregation
45+
{
46+
Field = Infer.Field<Person>(x => x.Age)
47+
}
48+
}}
49+
},
50+
Size = 10
4951
});
5052
```
5153

52-
5354
### Consume the response [_consume_the_response]
5455

5556
```csharp
5657
var max = response.Aggregations!.GetMax("agg_name")!;
5758
Console.WriteLine(max.Value);
5859
```
5960

60-
6161
## Sub-aggregation [_sub_aggregation]
6262

63-
6463
### Fluent API [_fluent_api_2]
6564

6665
```csharp
67-
var response = await client
68-
.SearchAsync<Person>(search => search
69-
.Index("persons")
70-
.Query(query => query
71-
.MatchAll(_ => {})
72-
)
73-
.Aggregations(aggregations => aggregations
74-
.Add("firstnames", aggregation => aggregation
75-
.Terms(terms => terms
76-
.Field(x => x.FirstName)
77-
)
78-
.Aggregations(aggregations => aggregations
79-
.Add("avg_age", aggregation => aggregation
80-
.Max(avg => avg
81-
.Field(x => x.Age)
82-
)
83-
)
84-
)
85-
)
86-
)
87-
.Size(10)
88-
);
66+
var response = await client.SearchAsync<Person>(search => search
67+
.Indices("persons")
68+
.Query(query => query
69+
.MatchAll(_ => {})
70+
)
71+
.Aggregations(aggregations => aggregations
72+
.Add("firstnames", aggregation => aggregation <1>
73+
.Terms(terms => terms
74+
.Field(x => x.FirstName)
75+
)
76+
.Aggregations(aggregations => aggregations
77+
.Add("avg_age", aggregation => aggregation <2>
78+
.Max(avg => avg
79+
.Field(x => x.Age)
80+
)
81+
)
82+
)
83+
)
84+
)
85+
.Size(10)
86+
);
8987
```
9088

89+
1. The top level `Terms` aggregation with name `firstnames`.
90+
2. Nested aggregation of type `Max` with name `avg_age`.
9191

9292
### Object initializer API [_object_initializer_api_2]
9393

9494
```csharp
95-
var topLevelAggregation = Aggregation.Terms(new TermsAggregation
96-
{
97-
Field = Infer.Field<Person>(x => x.FirstName)
98-
});
99-
100-
topLevelAggregation.Aggregations = new Dictionary<string, Aggregation>
95+
var response = await client.SearchAsync<Person>(new SearchRequest<Person>
10196
{
102-
{ "avg_age", new MaxAggregation
103-
{
104-
Field = Infer.Field<Person>(x => x.Age)
105-
}}
106-
};
107-
108-
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
109-
{
110-
Query = Query.MatchAll(new MatchAllQuery()),
111-
Aggregations = new Dictionary<string, Aggregation>
112-
{
113-
{ "firstnames", topLevelAggregation}
114-
},
115-
Size = 10
97+
Query = new Query
98+
{
99+
MatchAll = new MatchAllQuery()
100+
},
101+
Aggregations = new Dictionary<string, Aggregation>
102+
{
103+
{ "firstnames", new Aggregation
104+
{
105+
Terms = new TermsAggregation
106+
{
107+
Field = Infer.Field<Person>(x => x.FirstName)
108+
},
109+
Aggregations = new Dictionary<string, Aggregation>
110+
{
111+
{ "avg_age", new Aggregation
112+
{
113+
Max = new MaxAggregation
114+
{
115+
Field = Infer.Field<Person>(x => x.Age)
116+
}
117+
}}
118+
}
119+
}}
120+
}
116121
});
117122
```
118123

119-
120124
### Consume the response [_consume_the_response_2]
121125

122126
```csharp
123127
var firstnames = response.Aggregations!.GetStringTerms("firstnames")!;
124128
foreach (var bucket in firstnames.Buckets)
125129
{
126-
var avg = bucket.Aggregations.GetAverage("avg_age")!;
127-
Console.WriteLine($"The average age for persons named '{bucket.Key}' is {avg}");
130+
var avg = bucket.Aggregations.GetAverage("avg_age")!;
131+
Console.WriteLine($"The average age for persons named '{bucket.Key}' is {avg}");
128132
}
129133
```
130-

docs/reference/configuration.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ mapped_pages:
66
# Configuration [configuration]
77

88
Connecting to {{es}} with the client is easy, but it’s possible that you’d like to change the default connection behaviour. There are a number of configuration options available on `ElasticsearchClientSettings` that can be used to control how the client interact with {{es}}.
9-
10-

docs/reference/connecting.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ This page contains the information you need to create an instance of the .NET Cl
1010
It’s possible to connect to your {{es}} cluster via a single node, or by specifying multiple nodes using a node pool. Using a node pool has a few advantages over a single node, such as load balancing and cluster failover support. The client provides convenient configuration options to connect to an Elastic Cloud deployment.
1111

1212
::::{important}
13-
Client applications should create a single instance of `ElasticsearchClient` that is used throughout your application for its entire lifetime. Internally the client manages and maintains HTTP connections to nodes, reusing them to optimize performance. If you use a dependency injection container for your application, the client instance should be registered with a singleton lifetime.
14-
::::
1513

14+
Client applications should create a single instance of `ElasticsearchClient` that is used throughout your application for its entire lifetime. Internally the client manages and maintains HTTP connections to nodes, reusing them to optimize performance. If you use a dependency injection container for your application, the client instance should be registered with a singleton lifetime.
1615

16+
::::
1717

1818
## Connecting to a cloud deployment [cloud-deployment]
1919

@@ -36,8 +36,6 @@ var client = new ElasticsearchClient("<CLOUD_ID>", new ApiKey("<API_KEY>")); <1>
3636

3737
1. Replace the placeholder string values above with your cloud ID and the API key configured for your application to access your deployment.
3838

39-
40-
4139
## Connecting to a single node [single-node]
4240

4341
Single node configuration is best suited to connections to a multi-node cluster running behind a load balancer or reverse proxy, which is exposed via a single URL. It may also be convenient to use a single node during local application development. If the URL represents a single {{es}} node, be aware that this offers no resiliency should the server be unreachable or unresponsive.
@@ -92,7 +90,6 @@ var client = new ElasticsearchClient(settings);
9290

9391
The preceding snippet demonstrates configuring the client to authenticate by providing a username and password with basic authentication. If preferred, you may also use `ApiKey` authentication as shown in the cloud connection example.
9492

95-
9693
## Connecting to multiple nodes using a node pool [multiple-nodes]
9794

9895
To provide resiliency, you should configure multiple nodes for your cluster to which the client attempts to communicate. By default, the client cycles through nodes for each request in a round robin fashion. The client also tracks unhealthy nodes and avoids sending requests to them until they become healthy.
@@ -107,9 +104,9 @@ using Elastic.Transport;
107104

108105
var nodes = new Uri[]
109106
{
110-
new Uri("https://myserver1:9200"),
111-
new Uri("https://myserver2:9200"),
112-
new Uri("https://myserver3:9200")
107+
new Uri("https://myserver1:9200"),
108+
new Uri("https://myserver2:9200"),
109+
new Uri("https://myserver3:9200")
113110
};
114111

115112
var pool = new StaticNodePool(nodes);
@@ -120,4 +117,3 @@ var settings = new ElasticsearchClientSettings(pool)
120117

121118
var client = new ElasticsearchClient(settings);
122119
```
123-

0 commit comments

Comments
 (0)