Skip to content

Commit a4f2ed9

Browse files
committed
Add searchable and aggregatable to field stats
See elastic/elasticsearch#17980
1 parent 78e178c commit a4f2ed9

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/Nest/Ingest/Processors/DateIndexNameProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public class DateIndexNameProcessor : ProcessorBase, IDateIndexNameProcessor
8686
}
8787

8888
public class DateIndexNameProcessorDescriptor<T>
89-
: ProcessorDescriptorBase<DateIndexNameProcessorDescriptor<T>, IDateIndexNameProcessor>, IDateIndexNameProcessor
90-
where T : class
89+
: ProcessorDescriptorBase<DateIndexNameProcessorDescriptor<T>, IDateIndexNameProcessor>, IDateIndexNameProcessor
90+
where T : class
9191
{
9292
protected override string Name => "date_index_name";
9393

src/Nest/Search/FieldStats/FieldStatsResponse.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public class FieldStatsField
4343
[JsonProperty("sum_total_term_freq")]
4444
public long SumTotalTermFrequency { get; set; }
4545

46+
[JsonProperty("searchable")]
47+
public bool Searchable { get; set; }
48+
49+
[JsonProperty("aggregatable")]
50+
public bool Aggregatable { get; set; }
51+
4652
[JsonProperty("min_value")]
4753
public string MinValue { get; set; }
4854

src/Tests/Search/FieldStats/FieldStatsApiTests.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Linq;
23
using Elasticsearch.Net;
4+
using FluentAssertions;
35
using Nest;
46
using Tests.Framework;
57
using Tests.Framework.Integration;
@@ -25,30 +27,30 @@ protected override LazyResponses ClientUsage() => Calls(
2527
protected override int ExpectStatusCode => 200;
2628
protected override bool ExpectIsValid => true;
2729
protected override HttpMethod HttpMethod => HttpMethod.POST;
28-
protected override string UrlPath => "/project/_field_stats";
30+
protected override string UrlPath => "/project/_field_stats?level=indices";
2931

3032
protected override Func<FieldStatsDescriptor, IFieldStatsRequest> Fluent => d => d
31-
.Fields(Field<Project>(p => p.Name));
32-
33-
// Causes a NPE on ES 2.0.0
33+
.Fields(Fields<Project>("*"))
34+
.Level(Level.Indices);
35+
// TODO: These seem to never return stats...
3436
//.IndexConstraints(cs => cs
3537
// .IndexConstraint(Field<Project>(p => p.StartedOn), c => c
3638
// .MinValue(min => min
37-
// .GreaterThanOrEqualTo("2014-01-01")
39+
// .GreaterThanOrEqualTo(Project.Projects.Min(p => p.StartedOn).ToString("yyyy-MM-dd"))
3840
// .Format("date_optional_time")
3941
// )
4042
// .MaxValue(max => max
41-
// .LessThan("2015-12-29")
43+
// .LessThan(Project.Projects.Max(p => p.StartedOn).ToString("yyyy-MM-dd"))
4244
// .Format("date_optional_time")
4345
// )
4446
// )
4547
//);
4648

4749
protected override FieldStatsRequest Initializer => new FieldStatsRequest(typeof(Project))
4850
{
49-
Fields = Field<Project>(p => p.Name)
50-
51-
// Causes a NPE on ES 2.0.0
51+
Fields = Fields<Project>("*"),
52+
Level = Level.Indices,
53+
// TODO: These seem to never return stats...
5254
//IndexConstraints = new IndexConstraints
5355
//{
5456
// {
@@ -57,17 +59,26 @@ protected override LazyResponses ClientUsage() => Calls(
5759
// {
5860
// MinValue = new IndexConstraintComparison
5961
// {
60-
// GreaterThanOrEqualTo = "2014-01-01",
62+
// GreaterThanOrEqualTo = Project.Projects.Min(p => p.StartedOn).ToString("yyyy-MM-dd"),
6163
// Format = "date_optional_time"
6264
// },
6365
// MaxValue = new IndexConstraintComparison
6466
// {
65-
// LessThan = "2015-12-29",
67+
// LessThan = Project.Projects.Max(p => p.StartedOn).ToString("yyyy-MM-dd"),
6668
// Format = "date_optional_time"
6769
// }
6870
// }
6971
// }
7072
//}
7173
};
74+
75+
protected override void ExpectResponse(IFieldStatsResponse response)
76+
{
77+
foreach (var index in response.Indices)
78+
{
79+
var stats = index.Value;
80+
stats.Fields.Should().NotBeEmpty();
81+
}
82+
}
7283
}
7384
}

0 commit comments

Comments
 (0)