Skip to content

Commit ae9d6a9

Browse files
committed
added test to try and reproduce #986
1 parent 5cfe1c8 commit ae9d6a9

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@
174174
<Compile Include="Core\AsyncTests.cs" />
175175
<Compile Include="Mapping\MappingVisitorTests.cs" />
176176
<Compile Include="Reproduce\Reproduce769Tests.cs" />
177+
<Compile Include="Reproduce\Reproduce945Tests.cs" />
178+
<Compile Include="Reproduce\Reproduce953Tests.cs" />
177179
<Compile Include="Reproduce\Reproduce960Tests.cs" />
178180
<Compile Include="Search\Filter\AndOrNotFilterTests.cs" />
179181
<Compile Include="Search\Filter\ScriptFilterTests.cs" />
@@ -250,6 +252,10 @@
250252
<Compile Include="Warmers\WarmersTests.cs" />
251253
</ItemGroup>
252254
<ItemGroup>
255+
<ProjectReference Include="..\..\Connections\Elasticsearch.Net.Connection.HttpClient\Elasticsearch.Net.Connection.HttpClient.csproj">
256+
<Project>{a69322fd-b874-44ef-abe0-63f4a7b5593e}</Project>
257+
<Name>Elasticsearch.Net.Connection.HttpClient</Name>
258+
</ProjectReference>
253259
<ProjectReference Include="..\..\Elasticsearch.Net\Elasticsearch.Net.csproj">
254260
<Project>{e97ccf40-0ba6-43fe-9f2d-58d454134088}</Project>
255261
<Name>Elasticsearch.Net</Name>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using FluentAssertions;
8+
9+
namespace Nest.Tests.Integration.Reproduce
10+
{
11+
public class ElasticCallCustomer
12+
{
13+
public int Id { get; set; }
14+
15+
public string Name { get; set; }
16+
17+
}
18+
public class ElasticCall
19+
{
20+
public int Id { get; set; }
21+
22+
public long Duration { get; set; }
23+
24+
public ElasticCallCustomer Customer { get; set; }
25+
}
26+
27+
[TestFixture]
28+
public class Reproduce986Tests : IntegrationTests
29+
{
30+
[Test]
31+
public void PrefixQueryShouldReturnHits()
32+
{
33+
var customer1 = new ElasticCallCustomer { Id = 1, Name = "Martijn" };
34+
var customer2 = new ElasticCallCustomer { Id = 2, Name = "Thomas Tvedt" };
35+
36+
var calls = new[]
37+
{
38+
new ElasticCall {Id = 1, Duration=12315, Customer = customer1 },
39+
new ElasticCall {Id = 2, Duration=345345, Customer = customer2 },
40+
new ElasticCall {Id = 3, Duration=231, Customer = customer1 },
41+
new ElasticCall {Id = 4, Duration=908, Customer = customer1 },
42+
new ElasticCall {Id = 5, Duration=1231, Customer = customer2 },
43+
new ElasticCall {Id = 6, Duration=2112, Customer = customer1 },
44+
new ElasticCall {Id = 7, Duration=99891, Customer = customer1 },
45+
new ElasticCall {Id = 8, Duration=29401281, Customer = customer1 },
46+
new ElasticCall {Id = 9, Duration=2, Customer = customer1 },
47+
new ElasticCall {Id = 10, Duration=21231, Customer = customer1 },
48+
};
49+
50+
var result = this.Client.Bulk(b => b.IndexMany(calls).Refresh());
51+
result.IsValid.Should().BeTrue();
52+
53+
var search = this.Client.Search<ElasticCall>(s => s
54+
.Aggregations(agg => agg
55+
.Terms("calls_per_customer", calls_per_customer => calls_per_customer
56+
.Field(call=>call.Customer.Id)
57+
.Size(10)
58+
.Aggregations(callsPerCustomerAggs => callsPerCustomerAggs
59+
.Terms("customer_name", customer_name => customer_name
60+
.Script("_source.customer.name")
61+
.Size(1)
62+
)
63+
.Sum("total_duration", total_duration => total_duration.Field("duration"))
64+
.Average("average_duration", average_duration => average_duration.Field("duration"))
65+
)
66+
)
67+
)
68+
);
69+
70+
search.IsValid.Should().BeTrue();
71+
72+
var callsPerCustomer = search.Aggs.Terms("calls_per_customer");
73+
callsPerCustomer.Items.Should().NotBeEmpty().And.HaveCount(2);
74+
75+
foreach(var term in callsPerCustomer.Items)
76+
{
77+
var name = term.Terms("customer_name");
78+
name.Items.Should().NotBeEmpty().And.HaveCount(1);
79+
80+
var sum = term.Sum("total_duration").Value;
81+
sum.Should().BeGreaterThan(10);
82+
83+
var average = term.Average("average_duration").Value;
84+
average.Should().BeGreaterThan(10);
85+
}
86+
87+
88+
}
89+
}
90+
}

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@
379379
<Compile Include="QueryParsers\Visitor\DslPrettyPrintVisitor.cs" />
380380
<Compile Include="QueryParsers\Visitor\VisitorDemoUseCase.cs" />
381381
<Compile Include="QueryParsers\Visitor\VisitorTests.cs" />
382+
<Compile Include="Reproduce\Reproduce990Tests.cs" />
382383
<Compile Include="Reproduce\Reproduce974Tests.cs" />
383384
<Compile Include="Reproduce\Reproduce928Tests.cs" />
384385
<Compile Include="Reproduce\Reproduce902Tests.cs" />

0 commit comments

Comments
 (0)