Skip to content

Commit e8a91e5

Browse files
committed
Fix #1457: analyzers with no type should be treated as custom
1 parent 66692b6 commit e8a91e5

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

src/Nest/Resolvers/Converters/AnalyzerCollectionConverter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2929
{
3030
var propertyName = childProperty.Name;
3131
var typeProperty = ((JObject)childProperty.Value).Property("type");
32-
typeProperty.Remove();
32+
if (typeProperty != null)
33+
typeProperty.Remove();
34+
35+
var typePropertyValue = (typeProperty != null)
36+
? typeProperty.Value.ToString()
37+
: "custom";
3338

34-
var typePropertyValue = typeProperty.Value.ToString();
3539
Language language;
3640
if (Enum.TryParse(typePropertyValue, true, out language))
3741
{

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
<Compile Include="Reproduce\Reproduce1304Tests.cs" />
178178
<Compile Include="Reproduce\Reproduce1317Tests.cs" />
179179
<Compile Include="Reproduce\Reproduce1403Tests.cs" />
180+
<Compile Include="Reproduce\Reproduce1457Tests.cs" />
180181
<Compile Include="Reproduce\Reproduce769Tests.cs" />
181182
<Compile Include="Reproduce\Reproduce945Tests.cs" />
182183
<Compile Include="Reproduce\Reproduce953Tests.cs" />
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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

Comments
 (0)