Skip to content

Commit 6b4d304

Browse files
committed
Merge branch 'master' into AddSettingsSerialization
2 parents afb3e96 + 49512ce commit 6b4d304

37 files changed

+971
-151
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ build/keys/keypair.snk
4242
/dep/Newtonsoft.Json.4.0.2
4343

4444
/src/Nest.Tests.Unit/*.ncrunchproject
45+
*.ncrunchproject

src/Nest.Tests.Integration/Mapping/MapTests.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ private void TestMapping(RootObjectMapping typeMapping)
4949
[Test]
5050
public void SimpleMapByAttributes()
5151
{
52-
this._client.DeleteMapping<ElasticSearchProject>();
53-
this._client.DeleteMapping<ElasticSearchProject>(ElasticsearchConfiguration.DefaultIndex + "_clone");
54-
var x = this._client.MapFromAttributes<ElasticSearchProject>();
52+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
53+
var x = this._client.CreateIndex(index, s => s
54+
.AddMapping<ElasticSearchProject>(m => m.MapFromAttributes())
55+
);
56+
Assert.IsTrue(x.OK, x.ConnectionStatus.ToString());
5557
Assert.IsTrue(x.OK);
5658

57-
var typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex, "elasticsearchprojects");
59+
var typeMapping = this._client.GetMapping(index, "elasticsearchprojects");
5860
TestMapping(typeMapping);
5961
}
6062

@@ -64,13 +66,15 @@ public void SimpleMapByAttributes()
6466
[Test]
6567
public void SimpleMapByAttributesUsingType()
6668
{
67-
var t = typeof(ElasticSearchProject);
68-
this._client.DeleteMapping(t);
69-
this._client.DeleteMapping(t, ElasticsearchConfiguration.DefaultIndex + "_clone");
70-
var x = this._client.MapFromAttributes(t);
71-
Assert.IsTrue(x.OK);
72-
73-
var typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex, "elasticsearchprojects");
69+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
70+
var x = this._client.CreateIndex(index, s => s
71+
72+
);
73+
Assert.IsTrue(x.OK, x.ConnectionStatus.ToString());
74+
var xx = this._client.MapFromAttributes(typeof(ElasticSearchProject), index);
75+
Assert.IsTrue(xx.OK);
76+
77+
var typeMapping = this._client.GetMapping(index, "elasticsearchprojects");
7478
TestMapping(typeMapping);
7579
}
7680

@@ -95,15 +99,17 @@ public void GetMappingOnNonExistingIndexType()
9599
[Test]
96100
public void DynamicMap()
97101
{
102+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
103+
var x = this._client.CreateIndex(index, s => s);
104+
Assert.IsTrue(x.OK, x.ConnectionStatus.ToString());
98105
var typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex, "elasticsearchprojects");
99106
var mapping = typeMapping.Properties["country"] as StringMapping;
100107
Assert.NotNull(mapping);
101108
mapping.Boost = 3;
102109
typeMapping.TypeNameMarker = "elasticsearchprojects2";
103-
this._client.Map(typeMapping, ElasticsearchConfiguration.DefaultIndex + "_clone");
110+
this._client.Map(typeMapping, index);
104111

105-
typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex + "_clone",
106-
"elasticsearchprojects2");
112+
typeMapping = this._client.GetMapping(index, "elasticsearchprojects2");
107113
var countryMapping = typeMapping.Properties["country"] as StringMapping;
108114
Assert.NotNull(countryMapping);
109115
Assert.AreEqual(3, countryMapping.Boost);

src/Nest.Tests.Integration/Mapping/NotAnalyzedTest.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ public class NotAnalyzedTests : IntegrationTests
1010
[Test]
1111
public void NotAnalyzedReturnsOneItem()
1212
{
13-
this._client.DeleteMapping<ElasticSearchProject>();
14-
this._client.DeleteMapping<ElasticSearchProject>(ElasticsearchConfiguration.DefaultIndex + "_clone");
15-
this._client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, new IndexSettings());
16-
var x = this._client.MapFromAttributes<ElasticSearchProject>();
13+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
14+
var x = this._client.CreateIndex(index, s => s
15+
.AddMapping<ElasticSearchProject>(m=>m.MapFromAttributes())
16+
);
1717
Assert.IsTrue(x.OK, x.ConnectionStatus.ToString());
1818

19-
var typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex, "elasticsearchprojects");
19+
var typeMapping = this._client.GetMapping(index, "elasticsearchprojects");
2020
var mapping = typeMapping.Properties["country"] as StringMapping;
2121
Assert.NotNull(mapping);
2222
Assert.AreEqual(FieldIndexOption.not_analyzed, mapping.Index);
2323

2424
var indexResult = this._client.Index(new ElasticSearchProject
2525
{
2626
Country = "The Royal Kingdom Of The Netherlands"
27-
}, new IndexParameters { Refresh = true });
27+
}, indexParameters: new IndexParameters { Refresh = true }, index: index);
2828
Assert.IsTrue(indexResult.IsValid);
2929

3030
var result = this._client.Search<ElasticSearchProject>(s=>s
31+
.Index(index)
3132
.FacetTerm(ft=>ft.OnField(f=>f.Country))
3233
.MatchAll()
3334
);
@@ -37,27 +38,30 @@ public void NotAnalyzedReturnsOneItem()
3738
}
3839

3940
[Test]
40-
public void AnalyzedReturnsTwoItems()
41+
public void AnalyzedReturnsMoreItems()
4142
{
42-
this._client.DeleteMapping<ElasticSearchProject>();
43-
var x = this._client.MapFromAttributes<ElasticSearchProject>();
44-
Assert.IsTrue(x.OK);
45-
46-
var typeMapping = this._client.GetMapping(ElasticsearchConfiguration.DefaultIndex, "elasticsearchprojects");
47-
this._client.DeleteMapping<ElasticSearchProject>();
48-
var mapping = typeMapping.Properties["country"] as StringMapping;
49-
Assert.NotNull(mapping);
50-
mapping.Index = FieldIndexOption.analyzed;
51-
var updateMapResult = this._client.Map(typeMapping);
52-
Assert.True(updateMapResult.IsValid);
43+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
44+
var x = this._client.CreateIndex(index, s => s
45+
.AddMapping<ElasticSearchProject>(m => m
46+
.MapFromAttributes()
47+
.Properties(pp=>pp
48+
.String(pps=>pps.Name(p=>p.Country).Index(FieldIndexOption.analyzed))
49+
)
50+
)
51+
);
52+
Assert.IsTrue(x.OK, x.ConnectionStatus.ToString());
5353

54-
var indexResult = this._client.Index(new ElasticSearchProject
55-
{
56-
Country = "The Royal Kingdom Of The Netherlands"
57-
}, new IndexParameters { Refresh = true });
54+
var indexResult = this._client.Index(
55+
new ElasticSearchProject
56+
{
57+
Country = "The Royal Kingdom Of The Netherlands"
58+
},
59+
indexParameters: new IndexParameters { Refresh = true }
60+
, index: index);
5861
Assert.IsTrue(indexResult.IsValid);
5962

6063
var result = this._client.Search<ElasticSearchProject>(s => s
64+
.Index(index)
6165
.FacetTerm(ft => ft.OnField(f => f.Country))
6266
.MatchAll()
6367
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void TermSuggest()
154154

155155
var results = this._client.Search<ElasticSearchProject>(s => s
156156
.Query(q => q.MatchAll())
157-
.TermSuggest("mySuggest", m => m.SuggestMode(SuggestMode.Always).Text(wrongCountry).Size(1).OnField("country"))
157+
.SuggestTerm("mySuggest", m => m.SuggestMode(SuggestMode.Always).Text(wrongCountry).Size(1).OnField("country"))
158158
);
159159

160160
Assert.NotNull(results);
@@ -179,7 +179,7 @@ public void PhraseSuggest()
179179
{
180180
var results = this._client.Search<ElasticSearchProject>(s => s
181181
.Query(q => q.MatchAll())
182-
.PhraseSuggest("myPhraseSuggest", m => m.Text("Nostrud frankufrter dseerunt ulalmco").Size(1).OnField("content"))
182+
.SuggestPhrase("myPhraseSuggest", m => m.Text("Nostrud frankufrter dseerunt ulalmco").Size(1).OnField("content"))
183183
);
184184

185185
Assert.NotNull(results);

src/Nest.Tests.Integration/Warmers/IndicesWarmersTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class IndicesWarmersTests : IntegrationTests
1414
[Test]
1515
public void CreateIndexWithWarmer()
1616
{
17-
var index = ElasticsearchConfiguration.DefaultIndex + "_clone";
18-
if (this._client.IndexExists(index).Exists)
19-
this._client.DeleteIndex(index);
17+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
2018

2119
var result = this._client.CreateIndex(index, c => c
2220
.NumberOfReplicas(0)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ public void MapFluentFull()
234234
.TreeLevels(2)
235235
.DistanceErrorPercentage(0.025)
236236
)
237+
.Completion(s=>s
238+
.Name(p=>p.Name)
239+
.IndexAnalyzer("standard")
240+
.SearchAnalyzer("standard")
241+
.MaxInputLength(20)
242+
.Payloads()
243+
.PreservePositionIncrements()
244+
.PreserveSeparators()
245+
)
237246
)
238247
);
239248

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@
107107
<Compile Include="Internals\Inferno\HostNameWithPathTests.cs" />
108108
<Compile Include="Internals\Inferno\MapTypeNamesTests.cs" />
109109
<Compile Include="Internals\Serialize\OptOutTests.cs" />
110+
<Compile Include="Search\Filter\Singles\TermsLookupFilterJson.cs" />
111+
<Compile Include="Search\Filter\Singles\GeoIndexedShapeFilterJson.cs" />
112+
<Compile Include="Search\Filter\Singles\GeoShapeFilterJson.cs" />
110113
<Compile Include="Search\Filter\Singles\RegexpFilterJson.cs" />
111114
<Compile Include="Search\Query\BoolQueryMerges\BoolQueryMergesTests.cs" />
112115
<Compile Include="Search\Filter\BoolFilterMerges\BoolFilterMergesTests.cs" />
@@ -219,6 +222,7 @@
219222
<Compile Include="Search\SearchType\ScriptFieldTests.cs" />
220223
<Compile Include="Internals\Serialize\SerializeTests.cs" />
221224
<Compile Include="Search\Sort\SortTests.cs" />
225+
<Compile Include="Search\Suggest\CompletionSuggestTests.cs" />
222226
<Compile Include="Search\Suggest\PhraseSuggestTests.cs" />
223227
<Compile Include="Search\Suggest\TermSuggestTests.cs" />
224228
<Compile Include="Settings\UsePrettyResponseTests.cs" />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
using Nest.Tests.MockData.Domain;
3+
4+
namespace Nest.Tests.Unit.Search.Filter.Singles
5+
{
6+
[TestFixture]
7+
public class GeoIndexedShapeFilterJson
8+
{
9+
[Test]
10+
public void GeoShapeFilter()
11+
{
12+
//[13.0, 53.0], [14.0, 52.0]]
13+
var s = new SearchDescriptor<ElasticSearchProject>()
14+
.From(0)
15+
.Size(10)
16+
.Filter(filter => filter
17+
.Cache(true)
18+
.Name("my_geo_filter")
19+
.GeoIndexedShape(f=>f.Origin, d=>d
20+
.Lookup<ElasticSearchProject>(p=>p.MyGeoShape, "1")
21+
)
22+
);
23+
24+
var json = TestElasticClient.Serialize(s);
25+
var expected = @"{ from: 0, size: 10,
26+
filter : {
27+
geo_shape: {
28+
origin: {
29+
indexed_shape: {
30+
id: ""1"",
31+
type: ""elasticsearchprojects"",
32+
index: ""mydefaultindex"",
33+
shape_field_name: ""myGeoShape""
34+
}
35+
},
36+
_cache: true,
37+
_name: ""my_geo_filter""
38+
}
39+
}
40+
}";
41+
Assert.True(json.JsonEquals(expected), json);
42+
}
43+
44+
}
45+
}

src/Nest.Tests.Unit/Search/Filter/Singles/GeoPolygonFilterJson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void GeoPolygonFilter()
1717
.Filter(filter => filter
1818
.GeoPolygon("origin", "drn5x1g8cu2y", "30, -80", "20, -90")
1919
);
20-
20+
2121
var json = TestElasticClient.Serialize(s);
2222
var expected = @"{ from: 0, size: 10,
2323
filter : {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using NUnit.Framework;
2+
using Nest.Tests.MockData.Domain;
3+
4+
namespace Nest.Tests.Unit.Search.Filter.Singles
5+
{
6+
[TestFixture]
7+
public class GeoShapeFilterJson
8+
{
9+
[Test]
10+
public void GeoShapeFilter()
11+
{
12+
//[13.0, 53.0], [14.0, 52.0]]
13+
var s = new SearchDescriptor<ElasticSearchProject>()
14+
.From(0)
15+
.Size(10)
16+
.Filter(filter => filter
17+
.Cache(true)
18+
.Name("my_geo_filter")
19+
.GeoShape(f=>f.Origin, d=>d
20+
.Type("envelope")
21+
.Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } })
22+
)
23+
);
24+
25+
var json = TestElasticClient.Serialize(s);
26+
var expected = @"{ from: 0, size: 10,
27+
filter : {
28+
geo_shape: {
29+
origin: {
30+
shape: {
31+
type: ""envelope"",
32+
coordinates: [[13.0, 53.0], [14.0, 52.0]]
33+
}
34+
},
35+
_cache: true,
36+
_name: ""my_geo_filter""
37+
}
38+
}
39+
}";
40+
Assert.True(json.JsonEquals(expected), json);
41+
}
42+
43+
}
44+
}

0 commit comments

Comments
 (0)