Skip to content

Commit daad150

Browse files
committed
Fix #646 deleteby query should not throw if no default index is set
1 parent 9891756 commit daad150

File tree

7 files changed

+53
-4
lines changed

7 files changed

+53
-4
lines changed

src/Elasticsearch.Net/Connection/InMemoryConnection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Elasticsearch.Net.Connection
1010
public class InMemoryConnection : HttpConnection
1111
{
1212
private byte[] _fixedResultBytes = Encoding.UTF8.GetBytes("{ \"USING NEST IN MEMORY CONNECTION\" : null }");
13-
13+
public InMemoryConnection()
14+
: base(new ConnectionConfiguration())
15+
{
16+
17+
}
1418
public InMemoryConnection(IConnectionConfigurationValues settings)
1519
: base(settings)
1620
{

src/Nest/ElasticClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ElasticClient(
4545
this.Connection = connection ?? new HttpConnection(settings);
4646

4747
this.Serializer = serializer ?? new NestSerializer(this._connectionSettings);
48-
var stringifier = new NestStringifier(settings);
48+
var stringifier = new NestStringifier(this._connectionSettings);
4949
this.Raw = new ElasticsearchClient(
5050
this._connectionSettings,
5151
this.Connection,

src/Nest/ExposedInternals/ElasticInferrer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public string DefaultIndex
2525
return (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex;
2626
}
2727
}
28+
2829
public ElasticInferrer(IConnectionSettingsValues connectionSettings)
2930
{
3031
this._connectionSettings = connectionSettings;

src/Nest/Resolvers/IndexNameResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class IndexNameResolver
1414

1515
public IndexNameResolver(IConnectionSettingsValues connectionSettings)
1616
{
17-
connectionSettings.ThrowIfNull("hasDefaultIndices");
17+
connectionSettings.ThrowIfNull("connectionSettings");
1818
this._connectionSettings = connectionSettings;
1919
}
2020

src/Nest/Resolvers/TypeNameResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class TypeNameResolver
1313

1414
public TypeNameResolver(IConnectionSettingsValues connectionSettings)
1515
{
16-
connectionSettings.ThrowIfNull("hasDefaultIndices");
16+
connectionSettings.ThrowIfNull("connectionSettings");
1717
this._connectionSettings = connectionSettings;
1818
this._propertyNameResolver = new PropertyNameResolver(this._connectionSettings);
1919
}

src/Tests/Nest.Tests.Unit/BigBadUrlUnitTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void TestAllTheUrls()
7474
Do("DELETE", "/customindex/doc/_query", c => c.DeleteByQuery<Doc>(q => q.Index("customindex").MatchAll()));
7575
Do("DELETE", "/_all/doc/_query", c => c.DeleteByQuery<Doc>(q => q.AllIndices().MatchAll()));
7676
Do("DELETE", "/mydefaultindex/_query", c => c.DeleteByQuery<Doc>(q => q.AllTypes().MatchAll()));
77+
Do("DELETE", "/custom-index/_query", c => c.DeleteByQuery<Doc>(q => q.Index("custom-index").AllTypes().MatchAll()));
7778
Do("DELETE", "/mydefaultindex", c => c.DeleteIndex(i => i.Index<Doc>()));
7879
Do("DELETE", "/a%2Cb", c => c.DeleteIndex(i => i.Indices("a", "b")));
7980
Do("POST", "/_bulk", c => c.DeleteMany(Enumerable.Range(0, 10).Select(i => new Doc { Id = i.ToString() })));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Elasticsearch.Net.Connection;
6+
using NUnit.Framework;
7+
8+
namespace Nest.Tests.Unit.Reproduce
9+
{
10+
/// <summary>
11+
/// tests to reproduce reported errors
12+
/// </summary>
13+
[TestFixture]
14+
public class Reproduce646Tests : BaseJsonTests
15+
{
16+
/// <summary>
17+
/// https://github.com/Mpdreamz/NEST/issues/646
18+
/// </summary>
19+
[Test]
20+
public void Issue646()
21+
{
22+
var client = new ElasticClient(connection: new InMemoryConnection());
23+
Assert.DoesNotThrow(()=>
24+
{
25+
var result = _client.DeleteByQuery<object>(dq => dq
26+
.Index("my-custom-index")
27+
.AllTypes()
28+
.Query(q => q
29+
.Filtered(descriptor => descriptor
30+
.Filter(filterDescriptor => filterDescriptor
31+
.Not(descriptor1 => descriptor1
32+
.Term("indexProcessId", "1")
33+
)
34+
)
35+
)
36+
)
37+
);
38+
});
39+
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)