Skip to content

Commit 2d75323

Browse files
committed
Merge branch 'develop' of github.com:elasticsearch/elasticsearch-net into develop
2 parents c680e81 + d8d62ac commit 2d75323

File tree

7 files changed

+139
-47
lines changed

7 files changed

+139
-47
lines changed

src/Nest/Domain/Responses/MultiTermVectorResponse.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55

66
namespace Nest
77
{
8-
public interface IMultiTermVectorResponse : IResponse
9-
{
10-
IEnumerable<TermVectorResponse> Documents { get; }
11-
}
8+
public interface IMultiTermVectorResponse : IResponse
9+
{
10+
[Obsolete("In 1.x this property does not return metadata for the documents, switch to .Docs or upgrade to 2.0 when its release")]
11+
IEnumerable<TermVectorResponse> Documents { get; }
12+
IEnumerable<MultiTermVectorHit> Docs { get; }
13+
}
1214

13-
[JsonObject]
14-
public class MultiTermVectorResponse : BaseResponse, IMultiTermVectorResponse
15-
{
16-
public MultiTermVectorResponse()
17-
{
18-
IsValid = true;
19-
Documents = new List<TermVectorResponse>();
20-
}
15+
[JsonObject]
16+
public class MultiTermVectorResponse : BaseResponse, IMultiTermVectorResponse
17+
{
18+
public MultiTermVectorResponse()
19+
{
20+
IsValid = true;
21+
Docs = new List<MultiTermVectorHit>();
22+
}
2123

22-
[JsonProperty("docs")]
23-
public IEnumerable<TermVectorResponse> Documents { get; internal set; }
24-
}
24+
[Obsolete("In 1.x this property does not return metadata for the documents, switch to .Docs or upgrade to 2.0 when its release")]
25+
public IEnumerable<TermVectorResponse> Documents { get { return this.Docs; } }
26+
27+
[JsonProperty("docs")]
28+
public IEnumerable<MultiTermVectorHit> Docs { get; internal set; }
29+
}
2530
}

src/Nest/Domain/Responses/TermVectorResponse.cs

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,54 @@
55

66
namespace Nest
77
{
8-
public interface ITermVectorResponse : IResponse
9-
{
10-
bool Found { get; }
11-
IDictionary<string, TermVector> TermVectors { get; }
12-
}
13-
14-
[JsonObject]
15-
public class TermVectorResponse : BaseResponse, ITermVectorResponse
16-
{
17-
public TermVectorResponse()
18-
{
19-
IsValid = true;
20-
TermVectors = new Dictionary<string, TermVector>();
21-
}
22-
23-
[JsonProperty("found")]
24-
public bool Found { get; internal set; }
25-
26-
[JsonProperty("term_vectors")]
27-
public IDictionary<string, TermVector> TermVectors { get; internal set; }
28-
}
8+
public interface ITermVectorResponse : IResponse
9+
{
10+
bool Found { get; }
11+
IDictionary<string, TermVector> TermVectors { get; }
12+
}
13+
14+
public interface IMultiTermVectorHit : ITermVectorResponse
15+
{
16+
string Index { get; }
17+
string Type { get; }
18+
string Id { get; }
19+
long Version { get; }
20+
long Took { get; }
21+
}
22+
23+
[JsonObject]
24+
public class TermVectorResponse : BaseResponse, ITermVectorResponse
25+
{
26+
public TermVectorResponse()
27+
{
28+
IsValid = true;
29+
TermVectors = new Dictionary<string, TermVector>();
30+
}
31+
32+
[JsonProperty("found")]
33+
public bool Found { get; internal set; }
34+
35+
36+
[JsonProperty("term_vectors")]
37+
public IDictionary<string, TermVector> TermVectors { get; internal set; }
38+
}
39+
40+
public class MultiTermVectorHit : TermVectorResponse, IMultiTermVectorHit
41+
{
42+
[JsonProperty("_index")]
43+
public string Index { get; internal set; }
44+
45+
[JsonProperty("_type")]
46+
public string Type { get; internal set; }
47+
48+
[JsonProperty("_id")]
49+
public string Id { get; internal set; }
50+
51+
[JsonProperty("_version")]
52+
public long Version { get; internal set; }
53+
54+
[JsonProperty("took")]
55+
public long Took { get; internal set; }
56+
57+
}
2958
}

src/Nest/Domain/Responses/UpdateResponse.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
2+
using Nest.Domain;
3+
using Newtonsoft.Json;
24

35
namespace Nest
46
{
@@ -9,6 +11,10 @@ public interface IUpdateResponse : IResponse
911
string Type { get; }
1012
string Id { get; }
1113
string Version { get; }
14+
GetFromUpdate Get { get; }
15+
16+
T Source<T>() where T : class;
17+
FieldSelection<T> Fields<T>() where T : class;
1218
}
1319

1420
[JsonObject]
@@ -25,5 +31,36 @@ public class UpdateResponse : BaseResponse, IUpdateResponse
2531
public string Id { get; private set; }
2632
[JsonProperty(PropertyName = "_version")]
2733
public string Version { get; private set; }
34+
35+
[JsonProperty(PropertyName = "get")]
36+
public GetFromUpdate Get { get; private set; }
37+
38+
public T Source<T>() where T : class
39+
{
40+
if (this.Get == null) return null;
41+
return this.Get.Source.As<T>();
42+
}
43+
44+
public FieldSelection<T> Fields<T>() where T : class
45+
{
46+
if (this.Get == null) return null;
47+
return new FieldSelection<T>(this.Settings, this.Get._fields);
48+
}
49+
}
50+
51+
[JsonObject]
52+
public class GetFromUpdate
53+
{
54+
[JsonProperty(PropertyName = "found")]
55+
public bool Found { get; set; }
56+
57+
[JsonProperty(PropertyName = "_source")]
58+
internal IDocument Source { get; set; }
59+
60+
61+
[JsonProperty(PropertyName = "fields")]
62+
internal IDictionary<string, object> _fields { get; set; }
63+
64+
2865
}
2966
}

src/Nest/Resolvers/Writers/TypeMappingWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ private string GetElasticsearchType(FieldType? fieldType)
300300
return FieldType.Date;
301301
case "Boolean":
302302
return FieldType.Boolean;
303+
case "Guid":
304+
return FieldType.String;
303305
}
304306
}
305307
else

src/Tests/Nest.Tests.Integration/Core/TermVectors/MultiTermVectorsTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ public void MultiTermVectorsTest_DocumentsInBody()
4444

4545
result.IsValid.Should().BeTrue();
4646

47-
result.Documents.Should().NotBeNull();
48-
result.Documents.Count().Should().Be(2);
47+
result.Docs.Should().NotBeNull();
48+
result.Docs.Count().Should().Be(2);
4949

50-
foreach (var document in result.Documents)
50+
foreach (var document in result.Docs)
5151
{
52+
document.Index.Should().NotBeNullOrWhiteSpace();
53+
document.Type.Should().NotBeNullOrWhiteSpace();
54+
document.Id.Should().NotBeNullOrWhiteSpace();
55+
document.Version.Should().BeGreaterThan(0);
56+
document.Took.Should().BeGreaterThan(0);
57+
5258
document.TermVectors.Count().Should().Be(1);
5359
document.TermVectors.First().Key.Should().Be("content");
5460
}

src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@ public void TestUpdate()
1616
Assert.NotNull(project);
1717
Assert.Greater(project.LOC, 0);
1818
var loc = project.LOC;
19-
this.Client.Update<ElasticsearchProject>(u => u
20-
.IdFrom(project)
21-
.Script("ctx._source.loc += 10")
22-
.RetryOnConflict(5)
23-
.Refresh()
19+
var update = this.Client.Update<ElasticsearchProject>(u => u
20+
.IdFrom(project)
21+
.Script("ctx._source.loc += 10")
22+
.Fields("_source", "loc")
23+
.RetryOnConflict(5)
24+
.Refresh()
2425
);
2526
project = this.Client.Source<ElasticsearchProject>(s => s.Id(1));
2627
Assert.AreEqual(project.LOC, loc + 10);
2728
Assert.AreNotEqual(project.Version, "1");
29+
30+
update.Get.Should().NotBeNull();
31+
update.Get.Found.Should().BeTrue();
32+
update.Source<ElasticsearchProject>().Should().NotBeNull();
33+
update.Source<ElasticsearchProject>().LOC.Should().Be(loc + 10);
34+
var fieldLoc = update.Fields<ElasticsearchProject>().FieldValues(p => p.LOC);
35+
fieldLoc.Should().HaveCount(1);
36+
fieldLoc.First().Should().Be(loc + 10);
37+
2838
}
29-
39+
3040
[Test]
3141
public void TestUpdate_ObjectInitializer()
3242
{
@@ -49,7 +59,7 @@ public void TestUpdate_ObjectInitializer()
4959
public class ElasticsearchProjectLocUpdate
5060
{
5161
public int Id { get; set; }
52-
[ElasticProperty(Name="loc",AddSortField=true)]
62+
[ElasticProperty(Name = "loc", AddSortField = true)]
5363
public int LOC { get; set; }
5464
}
5565

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class MapFromAttributeTests : IntegrationTests
1414
{
1515
class MapFromAttributeObject
1616
{
17+
public Guid Id { get; set; }
1718
public string Name { get; set; }
1819
public int Number { get; set; }
1920
[ElasticProperty(Type = FieldType.Nested, IncludeInParent = true)]
@@ -37,6 +38,8 @@ public void InlcudeInParent()
3738
var typeMapping = this.Client.GetMapping<MapFromAttributeObject>(i => i.Type("mapfromattributeobject"));
3839
typeMapping.Should().NotBeNull();
3940

41+
typeMapping.Mapping.Properties["id"].Type.Name.Should().Be("string");
42+
4043
typeMapping.Mapping.Properties["nestedObjects"].Type.Name.Should().Be("nested");
4144
typeMapping.Mapping.Properties["nestedObjectsDontIncludeInParent"].Type.Name.Should().Be("nested");
4245
var nestedObject = typeMapping.Mapping.Properties["nestedObjects"] as NestedObjectMapping;

0 commit comments

Comments
 (0)