Skip to content

Commit e736c06

Browse files
russcamcodebrain
authored andcommitted
Attribute SuggestBucket for serialization (#3763)
This commit adds JsonProperty attributes to SuggestBucket to ensure that properties are correctly serialized when a DefaultFieldNameInferrer delegate is passed. These are required because the concrete SuggestBucket is not passed and serialized as the ISuggestBucket interface in the VerbatimDictionaryKeysJsonConverter WriteJson method.
1 parent 4ed8ab1 commit e736c06

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/Nest/Search/Suggesters/SuggestBucket.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ public interface ISuggestBucket
2727

2828
public class SuggestBucket : ISuggestBucket
2929
{
30+
[JsonProperty("completion")]
3031
public ICompletionSuggester Completion { get; set; }
3132

33+
[JsonProperty("phrase")]
3234
public IPhraseSuggester Phrase { get; set; }
3335

36+
[JsonProperty("prefix")]
3437
public string Prefix { get; set; }
3538

39+
[JsonProperty("regex")]
3640
public string Regex { get; set; }
3741

42+
[JsonProperty("term")]
3843
public ITermSuggester Term { get; set; }
44+
45+
[JsonProperty("text")]
3946
public string Text { get; set; }
4047
}
4148
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Text;
4+
using Elastic.Xunit.XunitPlumbing;
5+
using Elasticsearch.Net;
6+
using FluentAssertions;
7+
using FluentAssertions.Common;
8+
using Nest;
9+
using Newtonsoft.Json.Linq;
10+
using Tests.Core.Client;
11+
using Tests.Core.Extensions;
12+
using Tests.Core.Serialization;
13+
using Tests.Domain;
14+
15+
namespace Tests.Reproduce
16+
{
17+
public class Discuss179634
18+
{
19+
[U]
20+
public void SerializeCompletionSuggesterFieldsCorrectlyWhenDefaultFieldNameInferrerUsed()
21+
{
22+
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
23+
var settings = new ConnectionSettings(connectionPool, new InMemoryConnection())
24+
.DefaultFieldNameInferrer(p => p.ToUpper(CultureInfo.CurrentCulture))
25+
.DisableDirectStreaming();
26+
27+
var tester = new SerializationTester(new ElasticClient(settings));
28+
29+
var suggest = new SearchDescriptor<Project>()
30+
.Suggest(ss => ss
31+
.Completion("title", cs => cs
32+
.Field(f => f.Suggest)
33+
.Prefix("keyword")
34+
.Fuzzy(f => f
35+
.Fuzziness(Fuzziness.Auto)
36+
)
37+
.Size(5)
38+
)
39+
);
40+
41+
var expected = @"{
42+
""suggest"": {
43+
""title"": {
44+
""completion"": {
45+
""field"": ""SUGGEST"",
46+
""size"": 5,
47+
""fuzzy"": {
48+
""fuzziness"": ""AUTO""
49+
}
50+
},
51+
""prefix"": ""keyword""
52+
}
53+
}
54+
}";
55+
56+
var result = tester.Serializes(suggest, expected);
57+
result.Success.Should().Be(true, result.DiffFromExpected);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)