Skip to content

Commit ff45122

Browse files
author
unknown
committed
Merge branch 'master' of git://github.com/Mpdreamz/NEST.git
2 parents 272067a + 512fc56 commit ff45122

39 files changed

+664
-361
lines changed

src/Nest.Connection.Thrift/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: System.Runtime.InteropServices.ComVisible(false)]
1616
[assembly: System.CLSCompliant(true)]
1717
[assembly: System.Runtime.InteropServices.Guid("4d165338-2060-4641-8be6-b7aacbdee52d")]
18-
[assembly: System.Reflection.AssemblyVersion("0.11.1.0")]
19-
[assembly: System.Reflection.AssemblyFileVersion("0.11.1.0")]
18+
[assembly: System.Reflection.AssemblyVersion("0.11.2.0")]
19+
[assembly: System.Reflection.AssemblyFileVersion("0.11.2.0")]
2020

2121

src/Nest.Dsl.Factory/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[assembly: System.Runtime.InteropServices.ComVisible(false)]
1717
[assembly: System.CLSCompliant(true)]
1818
[assembly: System.Runtime.InteropServices.Guid("665cc582-c91f-4f6c-924a-614289fa9449")]
19-
[assembly: System.Reflection.AssemblyVersion("0.11.1.0")]
20-
[assembly: System.Reflection.AssemblyFileVersion("0.11.1.0")]
19+
[assembly: System.Reflection.AssemblyVersion("0.11.2.0")]
20+
[assembly: System.Reflection.AssemblyFileVersion("0.11.2.0")]
2121

2222

src/Nest.Tests.Integration/Core/Bulk/BulkUpdateTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public void BulkUpdateObject()
3535
result = this._client.Bulk(descriptor);
3636
result.Should().NotBeNull();
3737
result.IsValid.Should().BeTrue();
38+
result.Items.Count().Should().Be(1000);
39+
result.Items.All(i => i != null).Should().BeTrue();
40+
result.Items.All(i => i.OK).Should().BeTrue();
3841

3942
var updatedObject = this._client.Get<ElasticSearchProject>(5000);
4043
Assert.NotNull(updatedObject);

src/Nest.Tests.Integration/Integration/HighlightTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@ public void TestHighlight()
3434
Assert.DoesNotThrow(() => result.Highlights.Count());
3535
Assert.IsNotNull(result.Highlights);
3636
Assert.Greater(result.Highlights.Count(), 0);
37-
Assert.True(result.Highlights.Any(h => h.Highlights != null && h.Highlights.Any() && !string.IsNullOrEmpty(h.Highlights.First())));
37+
Assert.True(result.Highlights.All(h => h.Value != null));
38+
39+
Assert.True(result.Highlights.All(h => h.Value.All(hh => !hh.Value.DocumentId.IsNullOrEmpty())));
40+
41+
var id = result.Documents.First().Id.ToString();
42+
var highlights = result.Highlights[id];
43+
Assert.NotNull(highlights);
44+
Assert.NotNull(highlights["content"]);
45+
Assert.Greater(highlights["content"].Highlights.Count(), 0);
46+
47+
highlights = result.DocumentsWithMetaData.First().Highlight;
48+
Assert.NotNull(highlights);
49+
Assert.NotNull(highlights["content"]);
50+
Assert.Greater(highlights["content"].Highlights.Count(), 0);
3851
}
3952

4053
[Test]

src/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
<Compile Include="Integration\HighlightTests.cs" />
110110
<Compile Include="Integration\Query\TermQueryDynamic.cs" />
111111
<Compile Include="Mapping\NotAnalyzedTest.cs" />
112-
<Compile Include="Reproduce\ReproduceTests.cs" />
112+
<Compile Include="Reproduce\Reproduce308Tests.cs" />
113+
<Compile Include="Reproduce\Reproduce319Tests.cs" />
114+
<Compile Include="Reproduce\Reproduce211Tests.cs" />
113115
<Compile Include="Search\NamedFilter\NamedFilterTests.cs" />
114116
<Compile Include="Search\PercolateTests.cs" />
115117
<Compile Include="Search\CountTests.cs" />

src/Nest.Tests.Integration/Reproduce/ReproduceTests.cs renamed to src/Nest.Tests.Integration/Reproduce/Reproduce211Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Nest.Tests.Integration.Reproduce
1313
/// tests to reproduce reported errors
1414
/// </summary>
1515
[TestFixture]
16-
public class ReproduceTests : IntegrationTests
16+
public class Reproduce211Tests : IntegrationTests
1717
{
1818
public class Post
1919
{
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Nest.Tests.MockData;
5+
using Nest.Tests.MockData.Domain;
6+
using NUnit.Framework;
7+
using System.Diagnostics;
8+
using FluentAssertions;
9+
10+
namespace Nest.Tests.Integration.Reproduce
11+
{
12+
/// <summary>
13+
/// tests to reproduce reported errors
14+
/// </summary>
15+
[TestFixture]
16+
public class Reproduce308Tests : IntegrationTests
17+
{
18+
19+
/// <summary>
20+
/// https://github.com/Mpdreamz/NEST/issues/308
21+
/// </summary>
22+
[Test]
23+
public void ShouldBeAbleToSetIndexToReadonly()
24+
{
25+
var settings = new IndexSettings();
26+
settings.Similarity = new SimilaritySettings();
27+
settings.NumberOfReplicas = 1;
28+
settings.NumberOfShards = 5;
29+
settings.Add("index.blocks.read_only", "true");
30+
31+
var indexName = ElasticsearchConfiguration.NewUniqueIndexName();
32+
var idxRsp = this._client.CreateIndex(indexName, settings);
33+
Assert.IsTrue(idxRsp.IsValid, idxRsp.ConnectionStatus.ToString());
34+
35+
var getSettingsResponse = this._client.GetIndexSettings(indexName);
36+
Assert.IsTrue(getSettingsResponse.IsValid, getSettingsResponse.ConnectionStatus.ToString());
37+
38+
getSettingsResponse.Settings.Should().ContainKey("index.blocks.read_only");
39+
getSettingsResponse.Settings["index.blocks.read_only"].Should().Be("true");
40+
41+
42+
43+
}
44+
45+
}
46+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Nest.Tests.MockData;
5+
using Nest.Tests.MockData.Domain;
6+
using NUnit.Framework;
7+
using System.Diagnostics;
8+
using FluentAssertions;
9+
10+
namespace Nest.Tests.Integration.Reproduce
11+
{
12+
/// <summary>
13+
/// tests to reproduce reported errors
14+
/// </summary>
15+
[TestFixture]
16+
public class Reproduce319Tests : IntegrationTests
17+
{
18+
19+
/// <summary>
20+
/// https://github.com/Mpdreamz/NEST/issues/319
21+
/// </summary>
22+
[Test]
23+
public void CreateIndexShouldNotThrowNullReference()
24+
{
25+
var settings = new IndexSettings();
26+
settings.Similarity = new SimilaritySettings();
27+
settings.NumberOfReplicas = 1;
28+
settings.NumberOfShards = 5;
29+
settings.Add("index.refresh_interval", "10s");
30+
settings.Add("merge.policy.merge_factor", "10");
31+
settings.Add("search.slowlog.threshold.fetch.warn", "1s");
32+
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("keyword", new KeywordAnalyzer()));
33+
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("simple", new SimpleAnalyzer()));
34+
settings.Mappings.Add(new RootObjectMapping
35+
{
36+
Name = "my_root_object",
37+
Properties = new Dictionary<string, IElasticType>
38+
{
39+
{"my_field", new StringMapping() { Name = "my_string_field "}}
40+
}
41+
});
42+
43+
Assert.DoesNotThrow(() =>
44+
{
45+
var idxRsp = this._client.CreateIndex(ElasticsearchConfiguration.NewUniqueIndexName(), settings);
46+
Assert.IsTrue(idxRsp.IsValid, idxRsp.ConnectionStatus.ToString());
47+
});
48+
}
49+
50+
}
51+
}

src/Nest.Tests.Integration/Search/QueryResponseMapperTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ public void QueryWithHighlightTest()
530530
var queryResults = this._client.SearchRaw<ElasticSearchProject>(query);
531531

532532
//assert
533-
Assert.IsTrue(queryResults.DocumentsWithMetaData.First().Highlight["content"].Count > 0);
533+
Assert.IsTrue(queryResults.DocumentsWithMetaData.First().Highlight["content"].Highlights.Count() > 0);
534+
534535
}
535536
}
536537
}

src/Nest.Tests.Unit/Core/Get/GetFullTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ public void GetUsingDescriptor()
4141
var status = result.ConnectionStatus;
4242
StringAssert.EndsWith("/myindex/elasticsearchprojects/404", status.RequestUrl);
4343
}
44-
[Test]
45-
public void GetUsingDescriptorEscapes()
46-
{
47-
var result = this._client.GetFull<ElasticSearchProject>(g => g
48-
.Index("myindex")
49-
.Id("myid/with/slashes")
50-
);
51-
var status = result.ConnectionStatus;
52-
StringAssert.EndsWith("/myindex/elasticsearchprojects/myid%252Fwith%252Fslashes", status.RequestUrl);
53-
}
44+
5445
[Test]
5546
public void GetUsingDescriptorWithType()
5647
{

src/Nest.Tests.Unit/Core/Index/IndexTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void IndexParameters()
2828
var status = result.ConnectionStatus;
2929
StringAssert.Contains("version=1", status.RequestUrl);
3030
}
31+
3132
[Test]
3233
public void GetSupportsVersioning()
3334
{

src/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public void MapFluentFull()
4343
.DisableSizeField(false)
4444
.Dynamic()
4545
.Enabled()
46+
.SourceField(s=>s
47+
.SetDisabled(false)
48+
.SetExcludes(new [] {"anyfromthis.prop.*"})
49+
)
4650
.IncludeInAll()
4751
.Path("full")
4852
.IdField(i => i

src/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
<Compile Include="Search\SearchType\ScriptFieldTests.cs" />
216216
<Compile Include="Internals\Serialize\SerializeTests.cs" />
217217
<Compile Include="Search\Sort\SortTests.cs" />
218+
<Compile Include="Settings\UsePrettyResponseTests.cs" />
218219
<Compile Include="Test.Designer.cs">
219220
<DependentUpon>Test.settings</DependentUpon>
220221
<AutoGen>True</AutoGen>

src/Nest.Tests.Unit/Search/Sort/SortTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void TestSort()
1717
.OnField(e => e.Country)
1818
.MissingLast()
1919
.Descending()
20+
.IgnoreUnmappedFields(true)
2021
);
2122
var json = TestElasticClient.Serialize(s);
2223
var expected = @"
@@ -26,7 +27,8 @@ public void TestSort()
2627
sort: {
2728
country: {
2829
missing: ""_last"",
29-
order: ""desc""
30+
order: ""desc"",
31+
ignore_unmapped: true
3032
}
3133
}
3234
}";
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using FluentAssertions;
3+
using NUnit.Framework;
4+
5+
namespace Nest.Tests.Unit.Settings
6+
{
7+
[TestFixture]
8+
public class UsePrettyResponses : BaseJsonTests
9+
{
10+
[Test]
11+
public void UsePrettyResponsesShouldSurviveUrlModififications()
12+
{
13+
var settings = new ConnectionSettings(Test.Default.Uri)
14+
.SetDefaultIndex(Test.Default.DefaultIndex)
15+
.UsePrettyResponses();
16+
var connection = new InMemoryConnection(settings);
17+
var client = new ElasticClient(settings, connection);
18+
19+
var r = client.Health(HealthLevel.Cluster);
20+
var u = new Uri(r.ConnectionStatus.RequestUrl);
21+
u.AbsolutePath.Should().StartWith("/_cluster/health");
22+
u.Query.Should().Contain("level=cluster");
23+
24+
u.Query.Should().Contain("pretty=true");
25+
}
26+
27+
}
28+
}

src/Nest/DSL/Filter/TypeFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal override bool IsConditionless
1313
{
1414
get
1515
{
16-
return this.Value.IsNullOrEmpty();
16+
return this.Value.IsConditionless();
1717
}
1818

1919
}

src/Nest/DSL/SortDescriptor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class SortDescriptor<T> where T : class
2323

2424
[JsonProperty("nested_path")]
2525
internal string _NestedPath { get; set; }
26+
27+
[JsonProperty("ignore_unmapped")]
28+
internal bool? _IgnoreUnmappedFields { get; set; }
2629

2730
public virtual SortDescriptor<T> OnField(string field)
2831
{
@@ -60,6 +63,11 @@ public virtual SortDescriptor<T> MissingValue(string value)
6063
this._Missing = value;
6164
return this;
6265
}
66+
public virtual SortDescriptor<T> IgnoreUnmappedFields(bool ignore = true)
67+
{
68+
this._IgnoreUnmappedFields = ignore;
69+
return this;
70+
}
6371
public virtual SortDescriptor<T> Ascending()
6472
{
6573
this._Order = "asc";

src/Nest/Domain/Connection/Connection.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Specialized;
44
using System.IO;
55
using System.Net;
6+
using System.Reflection;
67
using System.Text;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -326,17 +327,21 @@ public void Iterate(IEnumerable<Task> asyncIterator, TaskCompletionSource<Connec
326327
recursiveBody(null);
327328
}
328329

329-
private string _CreateUriString(string path)
330+
private Uri _CreateUriString(string path)
330331
{
331332
var s = this._ConnectionSettings;
332-
333+
334+
333335
if (s.QueryStringParameters != null)
334336
{
335-
var uri = new Uri(s.Uri, path);
336-
var qs = s.QueryStringParameters.ToQueryString(uri.Query.IsNullOrEmpty() ? "?" : "&");
337+
var tempUri = new Uri(s.Uri, path);
338+
var qs = s.QueryStringParameters.ToQueryString(tempUri.Query.IsNullOrEmpty() ? "?" : "&");
337339
path += qs;
338340
}
339-
341+
LeaveDotsAndSlashesEscaped(s.Uri);
342+
var uri = new Uri(s.Uri, path);
343+
LeaveDotsAndSlashesEscaped(uri);
344+
return uri;
340345
var url = s.Uri.AbsoluteUri + path;
341346
//WebRequest.Create will replace %2F with /
342347
//this is a 'security feature'
@@ -346,7 +351,39 @@ private string _CreateUriString(string path)
346351
//it won't barf.
347352
//If you manually set the config settings to NOT forefully unescape dots and slashes be sure to call
348353
//.SetDontDoubleEscapePathDotsAndSlashes() on the connection settings.
349-
return this._ConnectionSettings.DontDoubleEscapePathDotsAndSlashes ? url : url.Replace("%2F", "%252F");
354+
//return );
355+
356+
//return this._ConnectionSettings.DontDoubleEscapePathDotsAndSlashes ? url : url.Replace("%2F", "%252F");
357+
}
358+
359+
// System.UriSyntaxFlags is internal, so let's duplicate the flag privately
360+
private const int UnEscapeDotsAndSlashes = 0x2000000;
361+
362+
public static void LeaveDotsAndSlashesEscaped(Uri uri)
363+
{
364+
if (uri == null)
365+
{
366+
throw new ArgumentNullException("uri");
367+
}
368+
369+
FieldInfo fieldInfo = uri.GetType().GetField("m_Syntax", BindingFlags.Instance | BindingFlags.NonPublic);
370+
if (fieldInfo == null)
371+
{
372+
throw new MissingFieldException("'m_Syntax' field not found");
373+
}
374+
object uriParser = fieldInfo.GetValue(uri);
375+
376+
fieldInfo = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
377+
if (fieldInfo == null)
378+
{
379+
throw new MissingFieldException("'m_Flags' field not found");
380+
}
381+
object uriSyntaxFlags = fieldInfo.GetValue(uriParser);
382+
383+
// Clear the flag that we don't want
384+
uriSyntaxFlags = (int)uriSyntaxFlags & ~UnEscapeDotsAndSlashes;
385+
386+
fieldInfo.SetValue(uriParser, uriSyntaxFlags);
350387
}
351388
}
352389
}

0 commit comments

Comments
 (0)