Skip to content

Commit ed8dccb

Browse files
committed
#fix 1427 register percolator did not handle raw queries well
1 parent ef46d05 commit ed8dccb

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/Nest/DSL/RegisterPercolatorDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
4444
public object GetCustomJson()
4545
{
4646
return new FluentDictionary<string, object>(this.MetaData)
47-
.Add("query", this.Query);
47+
.Add("query", this.Query == null ? null : this.Query.GetCustomJson());
4848
}
4949

5050
}
@@ -84,7 +84,7 @@ public RegisterPercolatorDescriptor<T> Query(Func<QueryDescriptor<T>, QueryConta
8484
public object GetCustomJson()
8585
{
8686
return new FluentDictionary<string, object>(Self.MetaData)
87-
.Add("query", Self.Query);
87+
.Add("query", Self.Query != null ? Self.Query.GetCustomJson() : null);
8888
}
8989

9090
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<IndexRequestParameters> pathInfo)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
<Compile Include="Reproduce\Reproduce1497Tests.cs" />
430430
<Compile Include="Reproduce\Reproduce1528Tests.cs" />
431431
<Compile Include="Reproduce\Reproduce1464Tests.cs" />
432+
<Compile Include="Reproduce\Reproduce1427Tests.cs" />
432433
<Compile Include="Reproduce\Reproduce629Tests.cs" />
433434
<Compile Include="Reproduce\Reproduce1187Tests.cs" />
434435
<Compile Include="Reproduce\Reproduce901Tests.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Elasticsearch.Net;
6+
using FluentAssertions;
7+
using Nest.Tests.MockData.Domain;
8+
using NUnit.Framework;
9+
10+
namespace Nest.Tests.Unit.Reproduce
11+
{
12+
/// <summary>
13+
/// tests to reproduce reported errors
14+
/// </summary>
15+
[TestFixture]
16+
public class Reproduce1427Tests : BaseJsonTests
17+
{
18+
[Test]
19+
public void RawSurvives()
20+
{
21+
var registerPercolator = new RegisterPercolatorDescriptor<ElasticsearchProject>()
22+
.Name("name")
23+
.Index("index")
24+
.Query(q => q.Raw(@"{ ""term"" : ""value"" }"));
25+
var serialized = _client.Serializer.Serialize(registerPercolator).Utf8String();
26+
serialized.Should().Contain("term");
27+
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)