Skip to content

Commit 2546ab7

Browse files
committed
Merge branch 'FoneticSolutions-2308-TookAsLongIn2x' into 2.x
2 parents bbd2ae4 + 8b8ef64 commit 2546ab7

File tree

12 files changed

+138
-45
lines changed

12 files changed

+138
-45
lines changed

src/Benchmarking/PartitionExtension.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> sourc
3535
}
3636
}
3737

38-
public static decimal GetMedian(this IEnumerable<int> source)
38+
public static decimal GetMedian(this IEnumerable<long> source)
3939
{
4040
// Create a copy of the input, and sort the copy
41-
int[] temp = source.ToArray();
41+
long[] temp = source.ToArray();
4242
Array.Sort(temp);
4343

4444
int count = temp.Length;
@@ -50,13 +50,13 @@ public static decimal GetMedian(this IEnumerable<int> source)
5050
if (count % 2 == 0)
5151
{
5252
// count is even, average two middle elements
53-
int a = temp[count / 2 - 1];
54-
int b = temp[count / 2];
53+
long a = temp[count / 2 - 1];
54+
long b = temp[count / 2];
5555
return (a + b) / 2m;
5656
}
57-
57+
5858
// count is odd, return the middle element
5959
return temp[count / 2];
6060
}
6161
}
62-
}
62+
}

src/Benchmarking/Results.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Results
1515

1616
public int IndexedDocuments { get; set; }
1717

18-
public IEnumerable<int> EsTimings { get; set; }
18+
public IEnumerable<long> EsTimings { get; set; }
1919

2020
public Metrics Before { get; set; }
2121

@@ -30,4 +30,4 @@ public void Write(TextWriter output)
3030
output.WriteLine(" memory after:{0} thread count after:{1}", After.MemorySize.Bytes(), After.ThreadCount);
3131
}
3232
}
33-
}
33+
}

src/Benchmarking/Tester.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Results RunTests(int numMessages = NumberOfMessages, int bufferSize = Buf
7575

7676
protected ConnectionSettings CreateSettings()
7777
{
78-
var host = Process.GetProcessesByName("fiddler").Any()
78+
var host = Process.GetProcessesByName("fiddler").Any()
7979
? "ipv4.fiddler"
8080
: "localhost";
8181

@@ -99,7 +99,7 @@ protected void Connect()
9999
protected class IndexResults
100100
{
101101
public double Elapsed { get; set; }
102-
public IEnumerable<int> EsTimings { get; set; }
102+
public IEnumerable<long> EsTimings { get; set; }
103103
}
104104

105105
protected IndexResults GenerateAndIndex(int numMessages, int bufferSize)
@@ -132,7 +132,7 @@ protected IndexResults GenerateAndIndex(int numMessages, int bufferSize)
132132
{
133133
Interlocked.Add(ref NumSent, bufferSize);
134134
Console.Write("\r{2}: {0:0,0} msgs es-time: {1} ",
135-
NumSent, tt.Result.Took, this.Type);
135+
NumSent, tt.Result.TookAsLong, this.Type);
136136
return tt.Result;
137137
})
138138
).ToArray();
@@ -151,7 +151,7 @@ protected IndexResults GenerateAndIndex(int numMessages, int bufferSize)
151151
return new IndexResults
152152
{
153153
Elapsed = sw.ElapsedMilliseconds,
154-
EsTimings = array.Select(a => a.Result.Took).ToList()
154+
EsTimings = array.Select(a => a.Result.TookAsLong).ToList()
155155
};
156156
}
157157

@@ -173,4 +173,4 @@ public void SearchUsingSingleClient(int numberOfSearches)
173173
Task.WaitAll(tasks.ToArray());
174174
}
175175
}
176-
}
176+
}

src/Nest/Document/Multiple/Bulk/BulkResponse.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
using System.Linq;
33
using System.Text;
44
using Newtonsoft.Json;
5+
using System;
56

67
namespace Nest
78
{
89
public interface IBulkResponse : IResponse
910
{
11+
/// <summary>
12+
/// Time in milliseconds for Elasticsearch to execute the search
13+
/// </summary>
14+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
1015
int Took { get; }
16+
17+
/// <summary>
18+
/// Time in milliseconds for Elasticsearch to execute the search
19+
/// </summary>
20+
long TookAsLong { get; }
21+
1122
bool Errors { get; }
1223
IEnumerable<BulkResponseItemBase> Items { get; }
1324
IEnumerable<BulkResponseItemBase> ItemsWithErrors { get; }
@@ -20,13 +31,23 @@ public class BulkResponse : ResponseBase, IBulkResponse
2031
protected override void DebugIsValid(StringBuilder sb)
2132
{
2233
if (this.Items == null) return;
23-
sb.AppendLine($"# Invalid Bulk items:");
34+
sb.AppendLine("# Invalid Bulk items:");
2435
foreach(var i in Items.Select((item, i) => new { item, i}).Where(i=>!i.item.IsValid))
2536
sb.AppendLine($" operation[{i.i}]: {i.item}");
2637
}
2738

39+
/// <summary>
40+
/// Time in milliseconds for Elasticsearch to execute the search
41+
/// </summary>
2842
[JsonProperty("took")]
29-
public int Took { get; internal set; }
43+
public long TookAsLong { get; internal set;}
44+
45+
/// <summary>
46+
/// Time in milliseconds for Elasticsearch to execute the search
47+
/// </summary>
48+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
49+
[JsonIgnore]
50+
public int Took => TookAsLong > int.MaxValue ? int.MaxValue : (int)TookAsLong;
3051

3152
[JsonProperty("errors")]
3253
public bool Errors { get; internal set; }
@@ -35,12 +56,7 @@ protected override void DebugIsValid(StringBuilder sb)
3556
public IEnumerable<BulkResponseItemBase> Items { get; internal set; }
3657

3758
[JsonIgnore]
38-
public IEnumerable<BulkResponseItemBase> ItemsWithErrors
39-
{
40-
get
41-
{
42-
return !this.Items.HasAny() ? Enumerable.Empty<BulkResponseItemBase>() : this.Items.Where(i => !i.IsValid);
43-
}
44-
}
59+
public IEnumerable<BulkResponseItemBase> ItemsWithErrors =>
60+
!this.Items.HasAny() ? Enumerable.Empty<BulkResponseItemBase>() : this.Items.Where(i => !i.IsValid);
4561
}
4662
}

src/Nest/Document/Single/TermVectors/TermVectorsResponse.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Newtonsoft.Json;
3+
using System;
34

45
namespace Nest
56
{
@@ -10,7 +11,18 @@ public interface ITermVectorsResponse : IResponse
1011
string Id { get; }
1112
long Version { get; }
1213
bool Found { get; }
14+
15+
/// <summary>
16+
/// Time in milliseconds for Elasticsearch to execute the search
17+
/// </summary>
18+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
1319
int Took { get; }
20+
21+
/// <summary>
22+
/// Time in milliseconds for Elasticsearch to execute the search
23+
/// </summary>
24+
long TookAsLong { get; }
25+
1426
IDictionary<string, TermVector> TermVectors { get; }
1527
}
1628

@@ -32,8 +44,18 @@ public class TermVectorsResponse : ResponseBase, ITermVectorsResponse
3244
[JsonProperty("found")]
3345
public bool Found { get; internal set; }
3446

35-
[JsonProperty(PropertyName = "took")]
36-
public int Took { get; internal set; }
47+
/// <summary>
48+
/// Time in milliseconds for Elasticsearch to execute the search
49+
/// </summary>
50+
[JsonProperty("took")]
51+
public long TookAsLong { get; internal set; }
52+
53+
/// <summary>
54+
/// Time in milliseconds for Elasticsearch to execute the search
55+
/// </summary>
56+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
57+
[JsonIgnore]
58+
public int Took => TookAsLong > int.MaxValue ? int.MaxValue : (int)TookAsLong;
3759

3860
[JsonProperty("term_vectors")]
3961
public IDictionary<string, TermVector> TermVectors { get; internal set; } = new Dictionary<string, TermVector>();
Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
using System.Collections.Generic;
22
using Elasticsearch.Net;
33
using Newtonsoft.Json;
4-
4+
using System;
5+
56
namespace Nest
67
{
78
public interface IPercolateCountResponse : IResponse
8-
{
9-
int Took { get; }
9+
{
10+
/// <summary>
11+
/// Time in milliseconds for Elasticsearch to execute the search
12+
/// </summary>
13+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
14+
int Took { get; }
15+
16+
/// <summary>
17+
/// Time in milliseconds for Elasticsearch to execute the search
18+
/// </summary>
19+
long TookAsLong { get; }
20+
1021
long Total { get; }
1122
}
1223

@@ -17,20 +28,30 @@ public interface IPercolateResponse : IPercolateCountResponse
1728

1829
[JsonObject]
1930
public class PercolateCountResponse : ResponseBase, IPercolateCountResponse
20-
{
21-
[JsonProperty(PropertyName = "took")]
22-
public int Took { get; internal set; }
31+
{
32+
/// <summary>
33+
/// Time in milliseconds for Elasticsearch to execute the search
34+
/// </summary>
35+
[JsonProperty("took")]
36+
public long TookAsLong { get; internal set; }
37+
38+
/// <summary>
39+
/// Time in milliseconds for Elasticsearch to execute the search
40+
/// </summary>
41+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
42+
[JsonIgnore]
43+
public int Took => TookAsLong > int.MaxValue? int.MaxValue : (int)TookAsLong;
2344

24-
[JsonProperty(PropertyName = "total")]
45+
[JsonProperty("total")]
2546
public long Total { get; internal set; }
26-
27-
[JsonProperty(PropertyName = "_shards")]
47+
48+
[JsonProperty("_shards")]
2849
public ShardsMetaData Shards { get; internal set; }
29-
50+
3051
/// <summary>
3152
/// The individual error for separate requests on the _mpercolate API
3253
/// </summary>
33-
[JsonProperty(PropertyName = "error")]
54+
[JsonProperty("error")]
3455
internal ServerError Error { get; set; }
3556

3657
public override ServerError ServerError => this.Error ?? base.ServerError;
@@ -39,24 +60,23 @@ public class PercolateCountResponse : ResponseBase, IPercolateCountResponse
3960
[JsonObject]
4061
public class PercolateResponse : PercolateCountResponse, IPercolateResponse
4162
{
42-
43-
[JsonProperty(PropertyName = "matches")]
63+
[JsonProperty("matches")]
4464
public IEnumerable<PercolatorMatch> Matches { get; internal set; }
4565
}
4666

4767
public class PercolatorMatch
4868
{
49-
[JsonProperty(PropertyName = "highlight")]
69+
[JsonProperty("highlight")]
5070
public Dictionary<string, IList<string>> Highlight { get; set; }
5171

52-
[JsonProperty(PropertyName = "_id")]
72+
[JsonProperty("_id")]
5373
public string Id { get; set; }
5474

55-
[JsonProperty(PropertyName = "_index")]
75+
[JsonProperty("_index")]
5676
public string Index { get; set; }
5777

58-
[JsonProperty(PropertyName = "_score")]
78+
[JsonProperty("_score")]
5979
public double Score { get; set; }
6080
}
6181

62-
}
82+
}

src/Nest/Search/Search/SearchResponse.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ public interface ISearchResponse<T> : IResponse where T : class
1414
Profile Profile { get; }
1515
AggregationsHelper Aggs { get; }
1616
IDictionary<string, Suggest[]> Suggest { get; }
17+
18+
/// <summary>
19+
/// Time in milliseconds for Elasticsearch to execute the search
20+
/// </summary>
21+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
1722
int Took { get; }
23+
24+
/// <summary>
25+
/// Time in milliseconds for Elasticsearch to execute the search
26+
/// </summary>
27+
long TookAsLong { get; }
28+
1829
bool TimedOut { get; }
1930
bool TerminatedEarly { get; }
2031
string ScrollId { get; }
@@ -64,8 +75,18 @@ public class SearchResponse<T> : ResponseBase, ISearchResponse<T> where T : clas
6475
[JsonProperty(PropertyName = "suggest")]
6576
public IDictionary<string, Suggest[]> Suggest { get; internal set; }
6677

67-
[JsonProperty(PropertyName = "took")]
68-
public int Took { get; internal set; }
78+
/// <summary>
79+
/// Time in milliseconds for Elasticsearch to execute the search
80+
/// </summary>
81+
[JsonProperty("took")]
82+
public long TookAsLong { get; internal set; }
83+
84+
/// <summary>
85+
/// Time in milliseconds for Elasticsearch to execute the search
86+
/// </summary>
87+
[Obsolete(@"returned value may be larger than int. In this case, value will be int.MaxValue and TookAsLong field can be checked. Took is long in 5.0.0")]
88+
[JsonIgnore]
89+
public int Took => TookAsLong > int.MaxValue ? int.MaxValue : (int)TookAsLong;
6990

7091
[JsonProperty("timed_out")]
7192
public bool TimedOut { get; internal set; }

src/Tests/Document/Multiple/Bulk/BulkApiTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ protected override LazyResponses ClientUsage() => Calls(
9292

9393
protected override void ExpectResponse(IBulkResponse response)
9494
{
95+
#pragma warning disable 618
9596
response.Took.Should().BeGreaterThan(0);
97+
#pragma warning restore 618
98+
response.TookAsLong.Should().BeGreaterThan(0);
9699
response.Errors.Should().BeFalse();
97100
response.ItemsWithErrors.Should().NotBeNull().And.BeEmpty();
98101
response.Items.Should().NotBeEmpty();

src/Tests/Document/Multiple/Bulk/BulkInvalidApiTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ protected override LazyResponses ClientUsage() => Calls(
3737

3838
protected override void ExpectResponse(IBulkResponse response)
3939
{
40+
#pragma warning disable 618
4041
response.Took.Should().BeGreaterThan(0);
42+
#pragma warning restore 618
43+
response.TookAsLong.Should().BeGreaterThan(0);
4144
response.Errors.Should().BeTrue();
4245

4346
//a delete not found is not an error (also in Elasticsearch)

src/Tests/Document/Multiple/MultiTermVectors/MultiTermVectorsApiTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ protected override void ExpectResponse(IMultiTermVectorsResponse response)
6161
termvectorDoc.Index.Should().NotBeNull();
6262
termvectorDoc.Type.Should().NotBeNull();
6363
termvectorDoc.Id.Should().NotBeNull();
64+
#pragma warning disable 618
6465
termvectorDoc.Took.Should().BeGreaterThan(0);
66+
#pragma warning restore 618
67+
termvectorDoc.TookAsLong.Should().BeGreaterThan(0);
6568

6669
termvectorDoc.TermVectors.Should().NotBeEmpty().And.ContainKey("firstName");
6770
var vectors = termvectorDoc.TermVectors["firstName"];

0 commit comments

Comments
 (0)