Skip to content

Commit 79caff0

Browse files
authored
Add GenericProperty.Indexed to support bool? values (#3225)
This commit adds GenericProperty.Indexed to allow a bool? value to be specified for the field's "index" value, in line with other properties. Deprecate the usage of GenericProperty.Index and point users to users GenericProperty.Indexed. If a user does continue to use GenericProperty.Index however, set a value of true for FieldIndexOption.Analyzed and FieldIndexOption.NotAnalyzed, false for FieldIndexOption.No, and null for null. GenericProperty.Index will be updated to type bool? in 7.x Fixes #3103
1 parent 15138f0 commit 79caff0

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

.paket/Paket.Restore.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
<!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk -->
5050
<PropertyGroup>
51-
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
52-
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
51+
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
52+
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
5353
</PropertyGroup>
5454

5555
<!-- If shasum and awk exist get the hashes -->

src/Nest/Mapping/Types/Specialized/Generic/GenericProperty.cs

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ namespace Nest
1111
[JsonObject(MemberSerialization.OptIn)]
1212
public interface IGenericProperty : IDocValuesProperty
1313
{
14-
[JsonProperty("index")]
14+
[JsonIgnore]
15+
[Obsolete("Please use Indexed. Will be fixed in NEST 7.x")]
1516
FieldIndexOption? Index { get; set; }
1617

18+
[JsonProperty("index")]
19+
bool? Indexed { get; set; }
20+
1721
[JsonProperty("term_vector")]
1822
TermVectorOption? TermVector { get; set; }
1923

@@ -52,6 +56,8 @@ public interface IGenericProperty : IDocValuesProperty
5256
[DebuggerDisplay("{DebugDisplay}")]
5357
public class GenericProperty : DocValuesPropertyBase, IGenericProperty
5458
{
59+
private FieldIndexOption? _index;
60+
5561
public GenericProperty() : base(FieldType.Object) => this.TypeOverride = null;
5662

5763
public TermVectorOption? TermVector { get; set; }
@@ -60,7 +66,31 @@ public class GenericProperty : DocValuesPropertyBase, IGenericProperty
6066
public int? IgnoreAbove { get; set; }
6167
public int? PositionIncrementGap { get; set; }
6268
public IStringFielddata Fielddata { get; set; }
63-
public FieldIndexOption? Index { get; set; }
69+
70+
[Obsolete("Please use Indexed. Will be fixed in NEST 7.x")]
71+
public FieldIndexOption? Index
72+
{
73+
get => _index;
74+
set
75+
{
76+
_index = value;
77+
switch (_index)
78+
{
79+
case FieldIndexOption.Analyzed:
80+
case FieldIndexOption.NotAnalyzed:
81+
Indexed = true;
82+
break;
83+
case FieldIndexOption.No:
84+
Indexed = false;
85+
break;
86+
default:
87+
Indexed = null;
88+
break;
89+
}
90+
}
91+
}
92+
93+
public bool? Indexed { get; set; }
6494
public string NullValue { get; set; }
6595
public bool? Norms { get; set; }
6696
public IndexOptions? IndexOptions { get; set; }
@@ -82,7 +112,31 @@ public class GenericPropertyDescriptor<T>
82112
: DocValuesPropertyDescriptorBase<GenericPropertyDescriptor<T>, IGenericProperty, T>, IGenericProperty
83113
where T : class
84114
{
85-
FieldIndexOption? IGenericProperty.Index { get; set; }
115+
private FieldIndexOption? _index;
116+
117+
FieldIndexOption? IGenericProperty.Index
118+
{
119+
get => _index;
120+
set
121+
{
122+
_index = value;
123+
switch (_index)
124+
{
125+
case FieldIndexOption.Analyzed:
126+
case FieldIndexOption.NotAnalyzed:
127+
Self.Indexed = true;
128+
break;
129+
case FieldIndexOption.No:
130+
Self.Indexed = false;
131+
break;
132+
default:
133+
Self.Indexed = null;
134+
break;
135+
}
136+
}
137+
}
138+
139+
bool? IGenericProperty.Indexed { get; set; }
86140
TermVectorOption? IGenericProperty.TermVector { get; set; }
87141
double? IGenericProperty.Boost { get; set; }
88142
string IGenericProperty.NullValue { get; set; }
@@ -98,12 +152,16 @@ public class GenericPropertyDescriptor<T>
98152

99153
public GenericPropertyDescriptor<T> Type(string type) => Assign(a => this.TypeOverride = type);
100154

155+
[Obsolete("Please use the overload that accepts bool?. Will be fixed in NEST 7.x")]
101156
public GenericPropertyDescriptor<T> Index(FieldIndexOption? index = FieldIndexOption.NotAnalyzed) => Assign(a => a.Index = index);
102157

158+
public GenericPropertyDescriptor<T> Index(bool? index = true) => Assign(a => a.Indexed = index);
159+
103160
public GenericPropertyDescriptor<T> Boost(double? boost) => Assign(a => a.Boost = boost);
104161

105162
public GenericPropertyDescriptor<T> NullValue(string nullValue) => Assign(a => a.NullValue = nullValue);
106163

164+
[Obsolete("Deprecated. Will be removed in NEST 7.x")]
107165
public GenericPropertyDescriptor<T> NotAnalyzed() => Index(FieldIndexOption.NotAnalyzed);
108166

109167
public GenericPropertyDescriptor<T> TermVector(TermVectorOption? termVector) => Assign(a => a.TermVector = termVector);

src/Tests/Indices/IndexSettings/IndexTemplates/PutIndexTemplate/PutIndexTemplateApiTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected override LazyResponses ClientUsage() => Calls(
4949
match_mapping_type = "*",
5050
mapping = new
5151
{
52-
index = "no"
52+
index = false
5353
}
5454
}
5555
}
@@ -74,7 +74,7 @@ protected override LazyResponses ClientUsage() => Calls(
7474
.MatchMappingType("*")
7575
.Mapping(mm => mm
7676
.Generic(g => g
77-
.Index(FieldIndexOption.No)
77+
.Index(false)
7878
)
7979
)
8080
)
@@ -106,7 +106,7 @@ protected override LazyResponses ClientUsage() => Calls(
106106
MatchMappingType = "*",
107107
Mapping = new GenericProperty
108108
{
109-
Index = FieldIndexOption.No
109+
Indexed = false
110110
}
111111
}
112112
}

src/Tests/Mapping/Types/Specialized/Generic/GenericPropertyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ public class GenericPropertyTests : SingleMappingPropertyTestsBase
1010
private const string GenericType = "{dynamic_type}";
1111
public GenericPropertyTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1212

13-
protected override object SingleMappingJson { get; } = new {index = "no", type= GenericType};
13+
protected override object SingleMappingJson { get; } = new {index = false, type= GenericType};
1414

1515
protected override Func<SingleMappingSelector<object>, IProperty> FluentSingleMapping => m => m
1616
.Generic(g => g
1717
.Type(GenericType)
18-
.Index(FieldIndexOption.No)
18+
.Index(false)
1919
);
2020

2121
protected override IProperty InitializerSingleMapping { get; } = new GenericProperty
2222
{
2323
Type = GenericType,
24-
Index = FieldIndexOption.No
24+
Indexed = false
2525
};
2626
}
2727
}

0 commit comments

Comments
 (0)