Skip to content

Commit 7c04566

Browse files
committed
Merge branch 'develop' of github.com:elasticsearch/elasticsearch-net into develop
2 parents 61ed271 + 2de46d2 commit 7c04566

File tree

15 files changed

+41
-10
lines changed

15 files changed

+41
-10
lines changed

src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public class ConnectionConfiguration<T> : IConnectionConfigurationValues, IHideO
106106
private TimeSpan? _sniffLifeSpan;
107107
TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan { get{ return _sniffLifeSpan; } }
108108

109+
private bool _compressionEnabled;
110+
bool IConnectionConfigurationValues.EnableCompressedResponses { get{ return _compressionEnabled; } }
111+
109112
private bool _traceEnabled;
110113
bool IConnectionConfigurationValues.TraceEnabled { get{ return _traceEnabled; } }
111114

@@ -159,6 +162,16 @@ public T SniffLifeSpan(TimeSpan sniffTimeSpan)
159162
return (T)this;
160163
}
161164

165+
/// <summary>
166+
/// Enable compressed responses from elasticsearch (NOTE that that nodes need to be configured to allow this)
167+
/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html
168+
/// </summary>
169+
public T EnableCompressedResponses(bool enabled = true)
170+
{
171+
this._compressionEnabled = enabled;
172+
return (T) this;
173+
}
174+
162175
/// <summary>
163176
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.
164177
/// </summary>

src/Elasticsearch.Net/Connection/Configuration/IConnectionConfiguration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public interface IConnectionConfiguration<out T> : IHideObjectMembers
1313
where T : IConnectionConfiguration<T>
1414
{
1515

16+
/// <summary>
17+
/// Enable compressed responses from elasticsearch (NOTE that that nodes need to be configured to allow this)
18+
/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html
19+
/// </summary>
20+
T EnableCompressedResponses(bool enabled = true);
21+
1622

1723
/// <summary>
1824
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.

src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IConnectionConfigurationValues
1616
int? MaxDeadTimeout { get; }
1717
int? MaxRetries { get; }
1818
bool DisablePings { get; }
19+
bool EnableCompressedResponses { get; }
1920

2021
string ProxyAddress { get; }
2122
string ProxyUsername { get; }

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.IO.Compression;
45
using System.Linq;
56
using System.Net;
67
using System.Runtime.InteropServices;
@@ -170,9 +171,13 @@ protected virtual HttpWebRequest CreateWebRequest(Uri uri, string method, byte[]
170171
//var url = this._CreateUriString(path);
171172

172173
var myReq = (HttpWebRequest)WebRequest.Create(uri);
173-
174174
myReq.Accept = "application/json";
175175
myReq.ContentType = "application/json";
176+
if (this.ConnectionSettings.EnableCompressedResponses)
177+
{
178+
myReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
179+
myReq.Headers.Add("Accept-Encoding", "gzip,deflate");
180+
}
176181
if (requestSpecificConfig != null && !string.IsNullOrWhiteSpace(requestSpecificConfig.ContentType))
177182
{
178183
myReq.Accept = requestSpecificConfig.ContentType;

src/Nest/DSL/Paths/DocumentOptionalPathDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void SetRouteParameters<TParameters>(
3131
ElasticsearchPathInfo<TParameters> pathInfo)
3232
where TParameters : IRequestParameters, new()
3333
{
34-
var inferrer = new ElasticInferrer(settings);
34+
var inferrer = settings.Inferrer;
3535

3636
pathInfo.Index = inferrer.IndexName(path.Index);
3737
pathInfo.Type = inferrer.TypeName(path.Type);
@@ -45,7 +45,7 @@ public static void SetRouteParameters<TParameters, T>(
4545
where TParameters : IRequestParameters, new()
4646
where T : class
4747
{
48-
var inferrer = new ElasticInferrer(settings);
48+
var inferrer = settings.Inferrer;
4949

5050
var index = path.Index != null ? inferrer.IndexName(path.Index) : inferrer.IndexName<T>();
5151
var type = path.Type != null ? inferrer.TypeName(path.Type) : inferrer.TypeName<T>();

src/Nest/DSL/Paths/FixedIndexTypePathDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void SetRouteParameters<TParameters>(
2121
ElasticsearchPathInfo<TParameters> pathInfo)
2222
where TParameters : IRequestParameters, new()
2323
{
24-
var inferrer = new ElasticInferrer(settings);
24+
var inferrer = settings.Inferrer;
2525
var index = inferrer.IndexName(path.Index);
2626
var type = inferrer.TypeName(path.Type);
2727

src/Nest/DSL/Visitor/DslPrettyPrintVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public string PrettyPrint
2525
public DslPrettyPrintVisitor(IConnectionSettingsValues settings)
2626
{
2727
this._sb = new StringBuilder();
28-
this._infer = new ElasticInferrer(settings);
28+
this._infer = settings.Inferrer;
2929
}
3030

3131
public virtual int Depth { get; set; }

src/Nest/Domain/Connection/ConnectionSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ string IConnectionSettingsValues.DefaultIndex
6464
}
6565
}
6666

67+
private ElasticInferrer _inferrer;
68+
ElasticInferrer IConnectionSettingsValues.Inferrer { get { return _inferrer; } }
69+
6770
private Func<Type, string> _defaultTypeNameInferrer;
6871
Func<Type, string> IConnectionSettingsValues.DefaultTypeNameInferrer { get { return _defaultTypeNameInferrer; } }
6972

@@ -97,6 +100,7 @@ public ConnectionSettings(IConnectionPool connectionPool, string defaultIndex) :
97100

98101
this._modifyJsonSerializerSettings = (j) => { };
99102
this._contractConverters = Enumerable.Empty<Func<Type, JsonConverter>>().ToList().AsReadOnly();
103+
this._inferrer = new ElasticInferrer(this);
100104
}
101105
public ConnectionSettings(Uri uri, string defaultIndex)
102106
: this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200")), defaultIndex)

src/Nest/Domain/Connection/IConnectionSettingsValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Nest
77
{
88
public interface IConnectionSettingsValues : IConnectionConfigurationValues
99
{
10+
ElasticInferrer Inferrer { get; }
1011
FluentDictionary<Type, string> DefaultIndices { get; }
1112
FluentDictionary<Type, string> DefaultTypeNames { get; }
1213
string DefaultIndex { get; }

src/Nest/Domain/Paths/FieldSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class FieldSelection<T> : IFieldSelection<T>
3030
private ElasticInferrer Infer { get; set; }
3131
public FieldSelection(IConnectionSettingsValues settings, IDictionary<string, object> valuesDictionary = null)
3232
{
33-
this.Infer = new ElasticInferrer(settings);
33+
this.Infer = settings.Inferrer;
3434
((IFieldSelection<T>)this).FieldValuesDictionary = valuesDictionary;
3535
}
3636

0 commit comments

Comments
 (0)