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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ launchSettings.json
# https://github.com/elastic/elasticsearch-net/pull/1822#issuecomment-183722698
*.project.lock.json
project.lock.json
/src/.vs
/src/.vs/*

.idea/
*.sln.iml
/src/.vs/restore.dg
1,030 changes: 0 additions & 1,030 deletions .vs/config/applicationhost.config

This file was deleted.

2 changes: 2 additions & 0 deletions docs/aggregations/writing-aggregations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ 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

Combining multiple `AggregationDescriptor` is also possible using the bitwise `&&` operator
Expand Down Expand Up @@ -237,5 +238,6 @@ 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 @@ -144,8 +144,11 @@ public class PkiCluster : CertgenCaCluster
}
----
<1> Set the client certificate on `ConnectionSettings`

<2> The path to the `.cer` file

<3> The path to the `.key` file

<4> The password for the private key

Or per request on `RequestConfiguration` which will take precedence over the ones defined on `ConnectionConfiguration`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ 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 @@ -100,7 +103,9 @@ audit = await audit.TraceUnexpectedException(
);
----
<1> calls on 9200 set up to throw 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 @@ -145,6 +150,8 @@ 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 @@ -68,6 +68,7 @@ var audit = new Auditor(() => Framework.Cluster
);
----
<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 @@ -88,7 +89,9 @@ 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 does not attempt to deserialize the response body returned;
Expand Down Expand Up @@ -122,6 +125,7 @@ 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 @@ -154,5 +158,6 @@ 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 @@ -67,8 +67,11 @@ 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 @@ -92,6 +95,7 @@ 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 @@ -113,5 +117,6 @@ audit = await audit.TraceCall(
);
----
<1> diable ping and sniff

<2> no ping or sniff before the call

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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. It fails so we wrap over to node 9202

<3> The next call goes to 9203 which fails so we should wrap over

A cluster with 2 nodes where the second node fails on ping
Expand Down Expand Up @@ -192,5 +194,6 @@ await audit.TraceCalls(
);
----
<1> All the calls fail

<2> After all our registered nodes are marked dead we want to sample a single dead node each time to quickly see if the cluster is back up. We do not want to retry all 4 nodes

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var createIndexResponse = client.CreateIndex("my-index", c => c
);
----
<1> Pre-defined list of English stopwords within Elasticsearch

<2> Use the `standard_english` analyzer configured

[source,javascript]
Expand Down Expand Up @@ -267,6 +268,7 @@ var createIndexResponse = client.CreateIndex("questions", c => c
);
----
<1> Use an analyzer at index time that strips HTML tags

<2> Use an analyzer at search time that does not strip HTML tags

With this in place, the text of a question body will be analyzed with the `index_question` analyzer
Expand Down
1 change: 1 addition & 0 deletions docs/client-concepts/high-level/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ var indexResponse = client.Index(person); <1>
var asyncIndexResponse = await client.IndexAsync(person); <2>
----
<1> synchronous method that returns an `IIndexResponse`

<2> asynchronous method that returns a `Task<IIndexResponse>` that can be awaited

NOTE: All methods available within NEST are exposed as both synchronous and asynchronous versions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,13 @@ class Precedence
}
----
<1> Even though this property has a NEST property mapping _and_ a `JsonProperty` attribute, We are going to provide a hard rename for it on ConnectionSettings later that should win.

<2> This property has both a NEST attribute and a `JsonProperty`, NEST should win.

<3> We should take the json property into account by itself

<4> This property we are going to special case in our custom serializer to resolve to ask

<5> We are going to register a DefaultFieldNameInferrer on ConnectionSettings that will uppercase all properties.

Here we create a custom serializer that renames any property named `AskSerializer` to `ask`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ singleIndexFromIndexName.Match(
);
----
<1> `_all` will override any specific index names here

<2> The `Project` type has been mapped to a specific index name using <<index-name-type-mapping,`.InferMappingFor<Project>`>>

[[nest-indices]]
Expand Down Expand Up @@ -120,7 +121,9 @@ ISearchRequest singleTypedRequest = new SearchDescriptor<Project>().Index(single
var invalidSingleString = Nest.Indices.Index("name1, name2"); <3>
----
<1> specifying a single index using a string

<2> specifying a single index using a type

<3> an **invalid** single index name

===== Multiple indices
Expand All @@ -145,7 +148,9 @@ manyStringRequest = new SearchDescriptor<Project>().Type(new[] { "name1", "name2
((IUrlParameter)manyStringRequest.Type).GetString(client.ConnectionSettings).Should().Be("name1,name2");
----
<1> specifying multiple indices using strings

<2> specifying multiple indices using types

<3> The index names here come from the Connection Settings passed to `TestClient`. See the documentation on <<index-name-inference, Index Name Inference>> for more details.

===== All Indices
Expand Down
1 change: 1 addition & 0 deletions docs/client-concepts/high-level/mapping/auto-map.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var descriptor = new CreateIndexDescriptor("myindex")
);
----
<1> Auto map `Company`

<2> Auto map `Employee`

[source,javascript]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ var descriptor = new CreateIndexDescriptor("myindex")
);
----
<1> Automap company

<2> Override company inferred mappings

<3> Auto map employee

<4> Override employee inferred mappings

[source,javascript]
Expand Down Expand Up @@ -401,8 +404,11 @@ var descriptor = new CreateIndexDescriptor("myindex")
);
----
<1> Automap `Company`

<2> Override specific `Company` mappings

<3> Automap `Employees` property

<4> Override specific `Employee` properties

[source,javascript]
Expand Down
3 changes: 3 additions & 0 deletions docs/client-concepts/high-level/mapping/multi-fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ var descriptor = new CreateIndexDescriptor("myindex")
);
----
<1> Use the stop analyzer on this sub field

<2> Use a custom analyzer named "named_shingles" that is configured in the index

<3> Index as not analyzed

[source,javascript]
Expand Down Expand Up @@ -135,6 +137,7 @@ var searchResponse = client.Search<Person>(s => s
);
----
<1> Use the shingles subfield on `Name`

<2> Use the keyword subfield on `Name`

[source,javascript]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class DisableDocValuesPropertyVisitor : NoopPropertyVisitor
}
----
<1> Override the `Visit` method on `INumberProperty` and set `DocValues = false`

<2> Similarily, override the `Visit` method on `IBooleanProperty` and set `DocValues = false`

Now we can pass an instance of our custom visitor to `.AutoMap()`
Expand Down
9 changes: 9 additions & 0 deletions docs/client-concepts/low-level/connecting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ var client = new ElasticLowLevelClient(config);
var result = client.Search<SearchResponse<object>>(new { size = 12 });
----
<1> Disable automatic proxy detection. When called, defaults to `true`.

<2> Enable compressed request and responses from Elasticsearch (Note that nodes need to be configured to allow this. See the {ref_current}/modules-http.html[http module settings] for more info).

<3> By default responses are deserialized directly from the response stream to the object you tell it to. For debugging purposes, it can be very useful to keep a copy of the raw response on the result object, which is what calling this method will do.

`.ResponseBodyInBytes` will only have a value if the client configuration has `DisableDirectStreaming` set
Expand Down Expand Up @@ -124,10 +126,15 @@ config = config
.BasicAuthentication("username", "password"); <6>
----
<1> Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request.

<2> Sets proxy information on the connection.

<3> [[request-timeout]] Sets the global maximum time a connection may take. Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx[the MSDN documentation on `HttpWebRequest.Timeout` Property]).

<4> As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to <<thrown-exceptions, throw exceptions>>.

<5> forces all serialization to be indented and appends `pretty=true` to all the requests so that the responses are indented as well

<6> sets the HTTP basic authentication credentials to specify with all requests.

NOTE: Basic authentication credentials can alternatively be specified on the node URI directly:
Expand Down Expand Up @@ -309,7 +316,9 @@ public class MyJsonNetSerializer : JsonNetSerializer
}
----
<1> Call this constructor if you only need access to `JsonSerializerSettings` without local state

<2> Call OverwriteDefaultSerializers if you need access to `JsonSerializerSettings` with local state

<3> You can inject contract resolved converters by implementing the ContractConverters property. This can be much faster then registering them on `JsonSerializerSettings.Converters`

You can then register a factory on `ConnectionSettings` to create an instance of your subclass instead.
Expand Down
4 changes: 4 additions & 0 deletions docs/client-concepts/low-level/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var asyncIndexResponse = await lowlevelClient.IndexAsync<string>("people", "pers
string responseString = asyncIndexResponse.Body;
----
<1> synchronous method that returns an `IIndexResponse`

<2> asynchronous method that returns a `Task<IIndexResponse>` that can be awaited

NOTE: All available methods within Elasticsearch.Net are exposed as both synchronous and asynchronous versions,
Expand Down Expand Up @@ -243,8 +244,11 @@ var serverError = searchResponse.ServerError; <3>
var exception = searchResponse.OriginalException; <4>
----
<1> Response is in the 200 range, or an expected response for the given request

<2> Response is successful, or has a response code between 400-599 that indicates the request cannot be retried.

<3> Details of any error returned from Elasticsearch

<4> If the response is unsuccessful, will hold the original exception.

Using these details, it is possible to make decisions around what should be done in your application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ await client.RootNodeInfoAsync(); <3>
counter.Should().Be(2);
----
<1> Construct a client

<2> Make a synchronous call and assert the counter is incremented

<3> Make an asynchronous call and assert the counter is incremented

`OnRequestCompleted` is called even when an exception is thrown, so it can be used even if the client is
Expand All @@ -63,7 +65,9 @@ await Assert.ThrowsAsync<ElasticsearchClientException>(async () => await client.
counter.Should().Be(2);
----
<1> Configure a client with a connection that **always returns a HTTP 500 response

<2> Always throw exceptions when a call results in an exception

<3> Assert an exception is thrown and the counter is incremented

Here's an example using `OnRequestCompleted()` for more complex logging
Expand Down Expand Up @@ -144,10 +148,15 @@ list.ShouldAllBeEquivalentTo(new[] <6>
});
----
<1> Here we use `InMemoryConnection` but in a real application, you'd use an `IConnection` that _actually_ sends the request, such as `HttpConnection`

<2> Disable direct streaming so we can capture the request and response bytes

<3> Perform some action when a request completes. Here, we're just adding to a list, but in your application you may be logging to a file.

<4> Make a synchronous call

<5> Make an asynchronous call

<6> Assert the list contains the contents written in the delegate passed to `OnRequestCompleted`

When running an application in production, you probably don't want to disable direct streaming for _all_
Expand Down Expand Up @@ -227,7 +236,10 @@ list.ShouldAllBeEquivalentTo(new[]
});
----
<1> Make a synchronous call where the request and response bytes will not be buffered

<2> Make an asynchronous call where `DisableDirectStreaming()` is enabled

<3> Only the method and url for the first request is captured

<4> the body of the second request is captured

Expand Down
6 changes: 3 additions & 3 deletions docs/code-standards/elastic-client.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ private class MethodWithRequestParameter
{
public string Name { get; }

public MethodInfo MethodInfo { get; }
public MethodInfo MethodInfo { get; }

public bool IsAsync { get; }

public ClientMethodType MethodType { get; }

public ParameterInfo Parameter { get; }
public ParameterInfo Parameter { get; }

public MethodWithRequestParameter(MethodInfo methodInfo)
public MethodWithRequestParameter(MethodInfo methodInfo)
{
Name = methodInfo.Name.EndsWith("Async")
? methodInfo.Name.Substring(0, methodInfo.Name.Length - "Async".Length)
Expand Down
Loading