Skip to content

Commit b72c7d3

Browse files
committed
Fix Count() executing a POST without request body
Logic was reversed when determining whether to execute a POST or GET request. If there's no source param, then it should be a GET, otherwise POST. Closes #898.
1 parent 8f2db7e commit b72c7d3

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/Nest/DSL/CountDescriptor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ internal static class CountPathInfo
1919
public static void Update(ElasticsearchPathInfo<CountRequestParameters> pathInfo, ICountRequest request)
2020
{
2121
var source = request.RequestParameters.GetQueryStringValue<string>("source");
22-
pathInfo.HttpMethod = !source.IsNullOrEmpty()
22+
pathInfo.HttpMethod = source.IsNullOrEmpty()
2323
? PathInfoHttpMethod.GET
2424
: PathInfoHttpMethod.POST;
25-
26-
pathInfo.HttpMethod = PathInfoHttpMethod.POST;
2725
}
2826
}
2927

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using FluentAssertions;
2+
using Nest.Tests.MockData.Domain;
3+
using NUnit.Framework;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Nest.Tests.Integration.Core
11+
{
12+
[TestFixture]
13+
public class CountTests : IntegrationTests
14+
{
15+
[Test]
16+
public void CountTest()
17+
{
18+
var response = this.Client.Count<ElasticsearchProject>();
19+
20+
response.IsValid.Should().BeTrue();
21+
response.Count.Should().BeGreaterThan(0);
22+
}
23+
24+
[Test]
25+
public void CountWithQueryTest()
26+
{
27+
var response = this.Client.Count<ElasticsearchProject>(c => c
28+
.Query(q => q
29+
.Match(m => m
30+
.OnField(p => p.Country)
31+
.Query("Sweden")
32+
)
33+
)
34+
);
35+
36+
response.IsValid.Should().BeTrue();
37+
response.Count.Should().BeGreaterThan(0);
38+
}
39+
}
40+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="Connection\Thrift\ThiftBugReportTests.cs" />
105105
<Compile Include="Core\Bulk\BulkTests.cs" />
106106
<Compile Include="Core\Bulk\BulkUpdateTests.cs" />
107+
<Compile Include="Core\CountTests.cs" />
107108
<Compile Include="Core\Explain\ExplainTests.cs" />
108109
<Compile Include="Core\Exists\AliasExists.cs" />
109110
<Compile Include="Core\GetFieldMapping\GetFieldMappingTests.cs" />

0 commit comments

Comments
 (0)