Skip to content

Commit b9fa4e1

Browse files
committed
fix #487 YesNoBoolConverter does not handle true/false properly if yes no is expected but a real boolean is returned
1 parent 15cad69 commit b9fa4e1

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

src/Nest/Domain/Mapping/Types/StringMapping.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class StringMapping : IElasticType, IElasticCoreType
2828
[JsonProperty("analyzer")]
2929
public string Analyzer { get; set; }
3030

31-
[JsonProperty("store"), JsonConverter(typeof(YesNoBoolConverter))]
3231
public bool? Store { get; set; }
3332

3433
[JsonProperty("index"), JsonConverter(typeof(StringEnumConverter))]

src/Nest/Resolvers/Converters/YesNoBoolConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
1818

1919
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
2020
{
21-
return reader.Value != null && reader.Value.ToString() == "yes";
21+
var v = reader.Value.ToString();
22+
return reader.Value != null && (v == "yes" || v == "True");
2223
}
2324

2425
public override bool CanConvert(Type objectType)

src/Tests/Nest.Tests.Integration/Mapping/MapTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public void SimpleMapByAttributes()
6363
}
6464

6565

66-
67-
6866
[Test]
6967
public void SimpleMapByAttributesUsingType()
7068
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Nest.Tests.MockData;
5+
using Nest.Tests.MockData.Domain;
6+
using NUnit.Framework;
7+
using System.Diagnostics;
8+
using FluentAssertions;
9+
10+
namespace Nest.Tests.Integration.Reproduce
11+
{
12+
[TestFixture]
13+
public class Reproduce487Tests : IntegrationTests
14+
{
15+
public class Post
16+
{
17+
public int Id { get; set; }
18+
public string Name { get; set; }
19+
}
20+
21+
22+
/// <summary>
23+
/// https://github.com/Mpdreamz/NEST/issues/487
24+
/// </summary>
25+
[Test]
26+
public void NoSearchResults()
27+
{
28+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
29+
var x = this._client.CreateIndex(index, s => s
30+
.AddMapping<ElasticsearchProject>(m => m
31+
.Properties(pp=>pp
32+
.String(sm=>sm.Name(p=>p.Name).Store())
33+
)
34+
)
35+
);
36+
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());
37+
38+
var typeMapping = this._client.GetMapping(i => i.Index(index).Type("elasticsearchprojects"));
39+
typeMapping.Should().NotBeNull();
40+
var stringMapping = typeMapping.Mapping.Properties["name"] as StringMapping;
41+
stringMapping.Should().NotBeNull();
42+
stringMapping.Store.Should().HaveValue();
43+
stringMapping.Store.Should().BeTrue();
44+
}
45+
46+
}
47+
}

0 commit comments

Comments
 (0)