|
| 1 | +using NUnit.Framework; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using FluentAssertions; |
| 8 | + |
| 9 | +namespace Nest.Tests.Integration.Reproduce |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class Reproduce1457Tests : IntegrationTests |
| 13 | + { |
| 14 | + [Test] |
| 15 | + public void AnalyzerMissingType_ShouldNotThrow_And_DeserializeAsCustom() |
| 16 | + { |
| 17 | + var indexName = "issue1457-repro"; |
| 18 | + |
| 19 | + if (this.Client.IndexExists(indexName).Exists) |
| 20 | + this.Client.DeleteIndex(indexName); |
| 21 | + |
| 22 | + var putTemplate = this.Client.PutTemplate("issue1457template", t => t |
| 23 | + .Template("issue1457-*") |
| 24 | + .Settings(s => s |
| 25 | + .Add("analysis", BuildAnalysisSettings()) |
| 26 | + ) |
| 27 | + ); |
| 28 | + |
| 29 | + putTemplate.IsValid.Should().BeTrue(); |
| 30 | + |
| 31 | + var createIndex = this.Client.CreateIndex(indexName); |
| 32 | + createIndex.IsValid.Should().BeTrue(); |
| 33 | + |
| 34 | + var getIndex = this.Client.GetIndex(g => g.Index(indexName)); |
| 35 | + getIndex.Indices.Should().NotBeNull(); |
| 36 | + var index = getIndex.Indices[indexName]; |
| 37 | + index.Analysis.Should().NotBeNull(); |
| 38 | + var analyzers = index.Analysis.Analyzers; |
| 39 | + analyzers.Should().NotBeNull(); |
| 40 | + analyzers["standardplus"].Type.Should().Be("custom"); |
| 41 | + analyzers["typename"].Type.Should().Be("custom"); |
| 42 | + analyzers["whitespace_lower"].Type.Should().Be("custom"); |
| 43 | + analyzers["version_search"].Type.Should().Be("custom"); |
| 44 | + analyzers["version_index"].Type.Should().Be("custom"); |
| 45 | + analyzers["email"].Type.Should().Be("custom"); |
| 46 | + analyzers["comma_whitespace"].Type.Should().Be("pattern"); |
| 47 | + getIndex.IsValid.Should().BeTrue(); |
| 48 | + } |
| 49 | + |
| 50 | + private object BuildAnalysisSettings() |
| 51 | + { |
| 52 | + return new |
| 53 | + { |
| 54 | + analyzer = new |
| 55 | + { |
| 56 | + comma_whitespace = new |
| 57 | + { |
| 58 | + type = "pattern", |
| 59 | + pattern = @"[,\s]+" |
| 60 | + }, |
| 61 | + email = new |
| 62 | + { |
| 63 | + tokenizer = "keyword", |
| 64 | + filter = new[] { |
| 65 | + "email", |
| 66 | + "lowercase", |
| 67 | + "unique" |
| 68 | + } |
| 69 | + }, |
| 70 | + version_index = new |
| 71 | + { |
| 72 | + tokenizer = "whitespace", |
| 73 | + filter = new[] { |
| 74 | + "version_pad1", |
| 75 | + "version_pad2", |
| 76 | + "version_pad3", |
| 77 | + "version_pad4", |
| 78 | + "version", |
| 79 | + "lowercase", |
| 80 | + "unique" |
| 81 | + } |
| 82 | + }, |
| 83 | + version_search = new |
| 84 | + { |
| 85 | + tokenizer = "whitespace", |
| 86 | + filter = new[] { |
| 87 | + "version_pad1", |
| 88 | + "version_pad2", |
| 89 | + "version_pad3", |
| 90 | + "version_pad4", |
| 91 | + "lowercase" |
| 92 | + } |
| 93 | + }, |
| 94 | + whitespace_lower = new |
| 95 | + { |
| 96 | + tokenizer = "whitespace", |
| 97 | + filter = new[] { "lowercase" } |
| 98 | + }, |
| 99 | + typename = new |
| 100 | + { |
| 101 | + tokenizer = "whitespace", |
| 102 | + filter = new[] { |
| 103 | + "typename", |
| 104 | + "lowercase", |
| 105 | + "unique" |
| 106 | + } |
| 107 | + }, |
| 108 | + standardplus = new |
| 109 | + { |
| 110 | + tokenizer = "whitespace", |
| 111 | + filter = new[] { |
| 112 | + "standard", |
| 113 | + "typename", |
| 114 | + "lowercase", |
| 115 | + "stop", |
| 116 | + "unique" |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + }; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments