Skip to content

Commit 8cb26a1

Browse files
committed
Add applies property as nested field in Elasticsearch exporter mapping
1 parent ed9cc82 commit 8cb26a1

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/Elastic.Documentation/AppliesTo/ApplicableToJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ApplicableToJsonConverter : JsonConverter<ApplicableTo>
6262
case "type":
6363
type = reader.GetString();
6464
break;
65-
case "sub-type":
65+
case "sub_type":
6666
subType = reader.GetString();
6767
break;
6868
case "lifecycle":
@@ -243,7 +243,7 @@ private static void WriteApplicabilityEntries(Utf8JsonWriter writer, string type
243243
{
244244
writer.WriteStartObject();
245245
writer.WriteString("type", type);
246-
writer.WriteString("sub-type", subType);
246+
writer.WriteString("sub_type", subType);
247247

248248
// Write lifecycle
249249
var lifecycleName = applicability.Lifecycle switch

src/Elastic.Markdown/Exporters/Elasticsearch/ElasticsearchExporter.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ protected static string CreateMapping(string? inferenceId) =>
193193
"prefix": { "type": "text", "analyzer" : "hierarchy_analyzer" }
194194
}
195195
},
196+
"applies" : {
197+
"type" : "nested"
198+
"properties" : {
199+
"type" : { "type" : "keyword" },
200+
"sub-type" : { "type" : "keyword" },
201+
"lifecycle" : { "type" : "keyword" },
202+
"version" : { "type" : "version" },
203+
}
204+
},
196205
"hash" : { "type" : "keyword" },
197206
"title": {
198207
"type": "text",

tests/Elastic.Markdown.Tests/AppliesTo/ApplicableToJsonConverterSerializationTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Serialize_Stack_ProducesCorrectJson()
2727
[
2828
{
2929
"type": "stack",
30-
"sub-type": "stack",
30+
"sub_type": "stack",
3131
"lifecycle": "ga",
3232
"version": "9999.9999.9999"
3333
}
@@ -49,7 +49,7 @@ public void Serialize_StackWithVersion_ProducesCorrectJson()
4949
[
5050
{
5151
"type": "stack",
52-
"sub-type": "stack",
52+
"sub_type": "stack",
5353
"lifecycle": "beta",
5454
"version": "8.0.0"
5555
}
@@ -75,13 +75,13 @@ public void Serialize_MultipleApplicabilities_ProducesCorrectJson()
7575
[
7676
{
7777
"type": "stack",
78-
"sub-type": "stack",
78+
"sub_type": "stack",
7979
"lifecycle": "ga",
8080
"version": "8.0.0"
8181
},
8282
{
8383
"type": "stack",
84-
"sub-type": "stack",
84+
"sub_type": "stack",
8585
"lifecycle": "beta",
8686
"version": "7.17.0"
8787
}
@@ -107,13 +107,13 @@ public void Serialize_Deployment_ProducesCorrectJson()
107107
[
108108
{
109109
"type": "deployment",
110-
"sub-type": "ece",
110+
"sub_type": "ece",
111111
"lifecycle": "ga",
112112
"version": "3.0.0"
113113
},
114114
{
115115
"type": "deployment",
116-
"sub-type": "ess",
116+
"sub_type": "ess",
117117
"lifecycle": "ga",
118118
"version": "9999.9999.9999"
119119
}
@@ -139,13 +139,13 @@ public void Serialize_Serverless_ProducesCorrectJson()
139139
[
140140
{
141141
"type": "serverless",
142-
"sub-type": "elasticsearch",
142+
"sub_type": "elasticsearch",
143143
"lifecycle": "beta",
144144
"version": "1.0.0"
145145
},
146146
{
147147
"type": "serverless",
148-
"sub-type": "security",
148+
"sub_type": "security",
149149
"lifecycle": "ga",
150150
"version": "9999.9999.9999"
151151
}
@@ -167,7 +167,7 @@ public void Serialize_Product_ProducesCorrectJson()
167167
[
168168
{
169169
"type": "product",
170-
"sub-type": "product",
170+
"sub_type": "product",
171171
"lifecycle": "preview",
172172
"version": "0.5.0"
173173
}
@@ -193,13 +193,13 @@ public void Serialize_ProductApplicability_ProducesCorrectJson()
193193
[
194194
{
195195
"type": "product",
196-
"sub-type": "ecctl",
196+
"sub_type": "ecctl",
197197
"lifecycle": "deprecated",
198198
"version": "5.0.0"
199199
},
200200
{
201201
"type": "product",
202-
"sub-type": "apm-agent-dotnet",
202+
"sub_type": "apm-agent-dotnet",
203203
"lifecycle": "ga",
204204
"version": "9999.9999.9999"
205205
}
@@ -255,10 +255,10 @@ public void Serialize_Complex_ProducesCorrectJson()
255255
json.Should().Contain("\"type\": \"deployment\"");
256256
json.Should().Contain("\"type\": \"product\"");
257257

258-
// Verify sub-types
259-
json.Should().Contain("\"sub-type\": \"stack\"");
260-
json.Should().Contain("\"sub-type\": \"ece\"");
261-
json.Should().Contain("\"sub-type\": \"product\"");
258+
// Verify sub_types
259+
json.Should().Contain("\"sub_type\": \"stack\"");
260+
json.Should().Contain("\"sub_type\": \"ece\"");
261+
json.Should().Contain("\"sub_type\": \"product\"");
262262
}
263263

264264
[Fact]
@@ -294,13 +294,13 @@ public void Serialize_ValidatesJsonStructure()
294294

295295
var stackEntry = array[0];
296296
stackEntry.GetProperty("type").GetString().Should().Be("stack");
297-
stackEntry.GetProperty("sub-type").GetString().Should().Be("stack");
297+
stackEntry.GetProperty("sub_type").GetString().Should().Be("stack");
298298
stackEntry.GetProperty("lifecycle").GetString().Should().Be("ga");
299299
stackEntry.GetProperty("version").GetString().Should().Be("9999.9999.9999");
300300

301301
var deploymentEntry = array[1];
302302
deploymentEntry.GetProperty("type").GetString().Should().Be("deployment");
303-
deploymentEntry.GetProperty("sub-type").GetString().Should().Be("ece");
303+
deploymentEntry.GetProperty("sub_type").GetString().Should().Be("ece");
304304
deploymentEntry.GetProperty("lifecycle").GetString().Should().Be("beta");
305305
deploymentEntry.GetProperty("version").GetString().Should().Be("3.0.0");
306306
}

0 commit comments

Comments
 (0)