Skip to content

Commit da76b34

Browse files
committed
CatFieldData is row-centric
Removal of total and each field is represented as a separate line See elastic/elasticsearch#18068
1 parent 9aaae89 commit da76b34

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

src/Nest/Cat/CatFielddata/CatFielddataRecord.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ public class CatFielddataRecord : ICatRecord
1111
public string Host { get; set; }
1212
public string Ip { get; set; }
1313
public string Node { get; set; }
14-
public string Total { get; set; }
15-
16-
public IDictionary<string, string> FieldSizes { get; set; }
14+
public string Field { get; set; }
15+
public string Size { get; set; }
1716
}
18-
19-
}
17+
}

src/Nest/Cat/CatFielddata/CatFielddataRecordJsonConverter.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,48 @@ namespace Nest
66
{
77
internal class CatFielddataRecordJsonConverter : JsonConverter
88
{
9-
public override bool CanWrite
10-
{
11-
get { return false; }
12-
}
9+
public override bool CanWrite => false;
1310

1411
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
1512
{
1613
throw new NotSupportedException();
1714
}
1815

19-
2016
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
2117
JsonSerializer serializer)
2218
{
23-
var o = new CatFielddataRecord() { FieldSizes = new Dictionary<string, string>() };
19+
var record = new CatFielddataRecord();
2420
while (reader.Read())
2521
{
2622
var prop = reader.Value as string;
27-
if (prop == null) return o;
23+
if (prop == null) return record;
2824

2925
switch (prop)
3026
{
3127
case "id":
32-
o.Id = reader.ReadAsString();
28+
record.Id = reader.ReadAsString();
3329
continue;
3430
case "node":
3531
case "n":
36-
o.Node = reader.ReadAsString();
32+
record.Node = reader.ReadAsString();
3733
continue;
3834
case "host":
39-
o.Host = reader.ReadAsString();
35+
record.Host = reader.ReadAsString();
4036
continue;
4137
case "ip":
42-
o.Ip = reader.ReadAsString();
38+
record.Ip = reader.ReadAsString();
4339
continue;
44-
case "total":
45-
o.Total = reader.ReadAsString();
40+
case "field":
41+
record.Field = reader.ReadAsString();
4642
continue;
47-
default:
48-
var value = reader.ReadAsString();
49-
o.FieldSizes[prop] = value;
43+
case "size":
44+
record.Size = reader.ReadAsString();
5045
continue;
5146
}
5247
}
53-
return o;
48+
return record;
5449
}
5550

56-
public override bool CanConvert(Type objectType)
57-
{
58-
return objectType == typeof(CatFielddataRecord);
59-
}
51+
public override bool CanConvert(Type objectType) => objectType == typeof(CatFielddataRecord);
6052
}
61-
}
53+
}

src/Tests/Cat/CatFielddata/CatFielddataApiTests.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using Elasticsearch.Net;
1+
using System;
2+
using System.Linq;
3+
using Elasticsearch.Net;
24
using FluentAssertions;
35
using Nest;
46
using Tests.Framework;
57
using Tests.Framework.Integration;
8+
using Tests.Framework.MockData;
69
using Xunit;
710

811
namespace Tests.Cat.CatFielddata
@@ -18,14 +21,39 @@ protected override LazyResponses ClientUsage() => Calls(
1821
requestAsync: (client, r) => client.CatFielddataAsync(r)
1922
);
2023

24+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
25+
{
26+
// ensure some fielddata is loaded
27+
var response = client.Search<Project>(s => s
28+
.Query(q => q
29+
.Terms(t => t
30+
.Field(p => p.CuratedTags.First().Name)
31+
.Terms(Tag.Generator.Generate(50).Select(ct => ct.Name))
32+
)
33+
)
34+
);
35+
36+
if (!response.IsValid)
37+
throw new Exception($"Failure setting up integration test. {response.DebugInformation}");
38+
}
39+
2140
protected override bool ExpectIsValid => true;
2241
protected override int ExpectStatusCode => 200;
2342
protected override HttpMethod HttpMethod => HttpMethod.GET;
2443
protected override string UrlPath => "/_cat/fielddata";
2544

2645
protected override void ExpectResponse(ICatResponse<CatFielddataRecord> response)
2746
{
28-
response.Records.Should().NotBeEmpty().And.Contain(a => !string.IsNullOrEmpty(a.Node));
47+
response.Records.Should().NotBeEmpty();
48+
foreach (var record in response.Records)
49+
{
50+
record.Node.Should().NotBeNullOrEmpty();
51+
record.Id.Should().NotBeNullOrEmpty();
52+
record.Host.Should().NotBeNullOrEmpty();
53+
record.Ip.Should().NotBeNullOrEmpty();
54+
record.Field.Should().NotBeNullOrEmpty();
55+
record.Size.Should().NotBeNullOrEmpty();
56+
}
2957
}
3058
}
3159

0 commit comments

Comments
 (0)