Skip to content

Commit 01955f1

Browse files
committed
Merge pull request #1492 from elastic/fix/multitermvector-document-metadata
Fix #1484 Added document metadata to multitermvectors response
2 parents d60fde2 + ac0840e commit 01955f1

File tree

3 files changed

+79
-39
lines changed

3 files changed

+79
-39
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/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
}

0 commit comments

Comments
 (0)