|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using NUnit.Framework; |
| 7 | +using FluentAssertions; |
| 8 | + |
| 9 | +namespace Nest.Tests.Integration.Core |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class FieldStatsTests : IntegrationTests |
| 13 | + { |
| 14 | + private void Assert(FieldStatsField fields) |
| 15 | + { |
| 16 | + fields.DocCount.Should().BeGreaterThan(0); |
| 17 | + fields.MaxDoc.Should().BeGreaterThan(0); |
| 18 | + fields.Density.Should().BeGreaterThan(0); |
| 19 | + fields.SumDocumentFrequency.Should().BeGreaterThan(0); |
| 20 | + fields.MinValue.Should().NotBeNullOrEmpty(); |
| 21 | + fields.MaxValue.Should().NotBeNullOrEmpty(); |
| 22 | + } |
| 23 | + |
| 24 | + [Test] |
| 25 | + [SkipVersion("0 - 1.5.9", "Field stats added in ES 1.6")] |
| 26 | + public void FieldStatsClusterLevel() |
| 27 | + { |
| 28 | + var r = this.Client.FieldStats(fs => fs.Fields("name", "country")); |
| 29 | + r.IsValid.Should().BeTrue(); |
| 30 | + r.Shards.Should().NotBeNull(); |
| 31 | + r.Shards.Successful.Should().BeGreaterThan(0); |
| 32 | + r.Indices.Should().NotBeEmpty(); |
| 33 | + r.Indices.Should().ContainKey("_all"); |
| 34 | + var all = r.Indices["_all"]; |
| 35 | + all.Fields.Should().NotBeNull(); |
| 36 | + all.Fields.Should().ContainKey("name"); |
| 37 | + var nameFieldStats = all.Fields["name"]; |
| 38 | + Assert(nameFieldStats); |
| 39 | + all.Fields.Should().ContainKey("country"); |
| 40 | + var countryFieldStats = all.Fields["country"]; |
| 41 | + Assert(countryFieldStats); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + [SkipVersion("0 - 1.5.9", "Field stats added in ES 1.6")] |
| 46 | + public void FieldStatsIndicesLevel() |
| 47 | + { |
| 48 | + var r = this.Client.FieldStats(fs => fs |
| 49 | + .Index(ElasticsearchConfiguration.DefaultIndex) |
| 50 | + .Fields("name") |
| 51 | + .Level(Elasticsearch.Net.Level.Indices) |
| 52 | + ); |
| 53 | + r.IsValid.Should().BeTrue(); |
| 54 | + r.Shards.Should().NotBeNull(); |
| 55 | + r.Shards.Successful.Should().BeGreaterThan(0); |
| 56 | + r.Indices.Should().NotBeEmpty(); |
| 57 | + r.Indices.Should().ContainKey(ElasticsearchConfiguration.DefaultIndex); |
| 58 | + var defaultIndex = r.Indices[ElasticsearchConfiguration.DefaultIndex]; |
| 59 | + defaultIndex.Fields.Should().NotBeNull(); |
| 60 | + defaultIndex.Fields.Should().ContainKey("name"); |
| 61 | + Assert(defaultIndex.Fields["name"]); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments