Skip to content

Commit

Permalink
Address review comment and add missing field in toXContent method
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Mar 18, 2022
1 parent 956e8ed commit 0fa6b43
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public void testIndexTemplates() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -181,7 +180,6 @@ public void testIndexTemplates() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();

Expand All @@ -193,15 +191,13 @@ public void testIndexTemplates() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field2")
.field("type", "text")
.field("store", false)
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ public void testLatestVersionLoaded() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -476,7 +475,6 @@ public void testLatestVersionLoaded() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void testSimpleIndexTemplateTests() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -125,7 +124,6 @@ public void testSimpleIndexTemplateTests() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();

Expand All @@ -138,15 +136,13 @@ public void testSimpleIndexTemplateTests() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field2")
.field("type", "text")
.field("store", false)
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();

Expand All @@ -162,15 +158,13 @@ public void testSimpleIndexTemplateTests() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field2")
.field("type", "text")
.field("store", false)
.endObject()
.endObject()
.endObject()
.endObject()
),
IllegalArgumentException.class
);
Expand Down Expand Up @@ -223,7 +217,6 @@ public void testDeleteIndexTemplate() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -235,7 +228,6 @@ public void testDeleteIndexTemplate() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand All @@ -248,15 +240,13 @@ public void testDeleteIndexTemplate() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field2")
.field("type", "text")
.field("store", false)
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand All @@ -279,7 +269,6 @@ public void testDeleteIndexTemplate() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -291,7 +280,6 @@ public void testDeleteIndexTemplate() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand Down Expand Up @@ -319,7 +307,6 @@ public void testThatGetIndexTemplatesWorks() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -331,7 +318,6 @@ public void testThatGetIndexTemplatesWorks() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand Down Expand Up @@ -363,7 +349,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -375,7 +360,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand All @@ -389,7 +373,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -401,7 +384,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand All @@ -415,7 +397,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -427,7 +408,6 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
Expand Down Expand Up @@ -1011,7 +991,7 @@ public void testPartitionedTemplate() throws Exception {
.indices()
.preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("te*"))
.setMapping("{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON)
.setMapping("{\"_routing\":{\"required\":false}}", XContentType.JSON)
.setSettings(Settings.builder().put("index.number_of_shards", "6").put("index.routing_partition_size", "3"))
.get()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.endObject();

builder.startObject("mappings");
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
mappings
)
) {
builder.copyCurrentStructure(parser);
if (mappings != null) {
builder.field(MapperService.SINGLE_MAPPING_NAME);
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
mappings
)
) {
builder.copyCurrentStructure(parser);
}
}
builder.endObject();

builder.startObject("aliases");
for (Alias alias : aliases) {
alias.toXContent(builder, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.test.AbstractXContentTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -93,7 +94,6 @@ public void testMappingKeyedByType() throws IOException {
request1.mapping(builder);
builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
Expand All @@ -106,7 +106,6 @@ public void testMappingKeyedByType() throws IOException {
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
request2.mapping(builder);
assertEquals(request1.mappings(), request2.mappings());
Expand All @@ -116,7 +115,7 @@ public void testMappingKeyedByType() throws IOException {
request2 = new PutIndexTemplateRequest("bar");
String nakedMapping = "{\"properties\": {\"foo\": {\"type\": \"integer\"}}}";
request1.mapping(nakedMapping, XContentType.JSON);
request2.mapping("{\"type2\": " + nakedMapping + "}", XContentType.JSON);
request2.mapping(nakedMapping, XContentType.JSON);
assertEquals(request1.mappings(), request2.mappings());
}
{
Expand All @@ -131,7 +130,7 @@ public void testMappingKeyedByType() throws IOException {
)
.map();
request1.mapping(nakedMapping);
request2.mapping(MapBuilder.<String, Object>newMapBuilder().put("type3", nakedMapping).map());
request2.mapping(MapBuilder.<String, Object>newMapBuilder().put(MapperService.SINGLE_MAPPING_NAME, nakedMapping).map());
assertEquals(request1.mappings(), request2.mappings());
}
}
Expand Down

0 comments on commit 0fa6b43

Please sign in to comment.