|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
| 9 | +using FluentAssertions; |
| 10 | +using Nest; |
| 11 | +using Tests.Core.Client; |
| 12 | + |
| 13 | +namespace Tests.Reproduce |
| 14 | +{ |
| 15 | + public class GitHubIssue5432 |
| 16 | + { |
| 17 | + [U] |
| 18 | + public void DeserializesAnalyzers() |
| 19 | + { |
| 20 | + const string json = @"{ |
| 21 | + ""analyzer-test"": { |
| 22 | + ""aliases"": {}, |
| 23 | + ""mappings"": {}, |
| 24 | + ""settings"": { |
| 25 | + ""index"": { |
| 26 | + ""routing"": { |
| 27 | + ""allocation"": { |
| 28 | + ""include"": { |
| 29 | + ""_tier_preference"": ""data_content"" |
| 30 | + } |
| 31 | + } |
| 32 | + }, |
| 33 | + ""number_of_shards"": ""1"", |
| 34 | + ""provided_name"": ""analyzer-test"", |
| 35 | + ""creation_date"": ""1616482422981"", |
| 36 | + ""analysis"": { |
| 37 | + ""filter"": { |
| 38 | + ""autocomplete_ngram"": { |
| 39 | + ""type"": ""edge_ngram"", |
| 40 | + ""min_gram"": ""3"", |
| 41 | + ""max_gram"": ""20"" |
| 42 | + } |
| 43 | + }, |
| 44 | + ""analyzer"": { |
| 45 | + ""search_autocomplete"": { |
| 46 | + ""filter"": [ |
| 47 | + ""lowercase"" |
| 48 | + ], |
| 49 | + ""tokenizer"": ""keyword"" |
| 50 | + }, |
| 51 | + ""index_autocomplete"": { |
| 52 | + ""filter"": [ |
| 53 | + ""lowercase"", |
| 54 | + ""autocomplete_ngram"" |
| 55 | + ], |
| 56 | + ""tokenizer"": ""keyword"" |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + ""number_of_replicas"": ""1"", |
| 61 | + ""uuid"": ""g8qnTA5wTveRCQnQN6xa3A"", |
| 62 | + ""version"": { |
| 63 | + ""created"": ""7110099"" |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +}"; |
| 69 | + |
| 70 | + var bytes = Encoding.UTF8.GetBytes(json); |
| 71 | + var client = TestClient.FixedInMemoryClient(bytes); |
| 72 | + var response = client.Indices.Get("analyzer-test"); |
| 73 | + |
| 74 | + var analyzers = response.Indices.Values.First().Settings.Analysis.Analyzers.Values; |
| 75 | + analyzers.Count.Should().Be(2); |
| 76 | + |
| 77 | + foreach(var a in analyzers) |
| 78 | + { |
| 79 | + a.Should().NotBeNull(); |
| 80 | + } |
| 81 | + |
| 82 | + if (response.Indices.Values.First().Settings.Analysis.Analyzers.TryGetValue("search_autocomplete", out var analyzerOne)) |
| 83 | + { |
| 84 | + var customAnalyzer = analyzerOne as CustomAnalyzer; |
| 85 | + customAnalyzer.Should().NotBeNull(); |
| 86 | + customAnalyzer!.Filter.Count().Should().Be(1); |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + throw new Exception("Expected index_autocomplete analyzer was not found."); |
| 91 | + } |
| 92 | + |
| 93 | + if (response.Indices.Values.First().Settings.Analysis.Analyzers.TryGetValue("index_autocomplete", out var analyzerTwo)) |
| 94 | + { |
| 95 | + var customAnalyzer = analyzerTwo as CustomAnalyzer; |
| 96 | + customAnalyzer.Should().NotBeNull(); |
| 97 | + customAnalyzer!.Filter.Count().Should().Be(2); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + throw new Exception("Expected index_autocomplete analyzer was not found."); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments