Skip to content

Commit bc4a514

Browse files
committed
Don't sanitize the keys for Filters aggregation named buckets (#4656)
This commit fixes a bug where the keys in the dictionary passed to filters aggregation are sanitized when copying to the backing dictionary. Keys in this scenario are the keys for named buckets which should never be sanitized. Fixes #4582 (cherry picked from commit 7d522fe)
1 parent cd16a61 commit bc4a514

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/Nest/Aggregations/Bucket/Filters/FiltersAggregate.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public FiltersAggregate() : base(EmptyReadOnly<string, IAggregate>.Dictionary) {
2828

2929
public FiltersAggregate(IReadOnlyDictionary<string, IAggregate> aggregations) : base(aggregations) { }
3030

31+
// Don't sanitize the keys as these are the keys for named buckets
32+
protected override string Sanitize(string key) => key;
33+
3134
public IReadOnlyCollection<FiltersBucketItem> Buckets { get; set; } = EmptyReadOnly<FiltersBucketItem>.Collection;
3235

3336
public SingleBucketAggregate NamedBucket(string key) => Global(key);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text;
5+
using Elastic.Xunit.XunitPlumbing;
6+
using Elasticsearch.Net;
7+
using FluentAssertions;
8+
using Nest;
9+
using Tests.Core.Client;
10+
using Tests.Core.Extensions;
11+
12+
namespace Tests.Reproduce
13+
{
14+
public class GithubIssue4582
15+
{
16+
[U]
17+
public void DeserializeBucketKeyWithHash()
18+
{
19+
var json = @"
20+
{
21+
""hits"": {
22+
},
23+
""aggregations"":
24+
{
25+
""some_agg"" : {
26+
""buckets"" : {
27+
""value1"" : {
28+
""doc_count"" : 0
29+
},
30+
""value2"" : {
31+
""doc_count"" : 0
32+
},
33+
""value3#something else"" : {
34+
""doc_count"" : 0
35+
}
36+
}
37+
}
38+
}
39+
}
40+
";
41+
42+
var bytes = Encoding.UTF8.GetBytes(json);
43+
var client = TestClient.FixedInMemoryClient(bytes);
44+
var response = client.Search<object>();
45+
46+
var filters = response.Aggregations
47+
.Filters("some_agg")
48+
.Select(x => x.Key)
49+
.ToList();
50+
51+
filters[2].Should().Be("value3#something else");
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)