use of org.opensearch.common.xcontent.NamedXContentRegistry in project OpenSearch by opensearch-project.
the class AbstractSuggestionBuilderTestCase method init.
/**
* setup for the whole base test class
*/
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project OpenSearch by opensearch-project.
the class SuggestBuilderTests method init.
/**
* Setup for the whole base test class.
*/
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project OpenSearch by opensearch-project.
the class SortBuilderTests method init.
@BeforeClass
public static void init() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project OpenSearch by opensearch-project.
the class MetadataIndexTemplateServiceTests method testDefinedTimestampMappingIsAddedForDataStreamTemplates.
public void testDefinedTimestampMappingIsAddedForDataStreamTemplates() throws Exception {
final MetadataIndexTemplateService service = getMetadataIndexTemplateService();
ClusterState state = ClusterState.EMPTY_STATE;
ComponentTemplate ct1 = new ComponentTemplate(new Template(null, new CompressedXContent("{\n" + " \"properties\": {\n" + " \"field1\": {\n" + " \"type\": \"keyword\"\n" + " }\n" + " }\n" + " }"), null), null, null);
state = service.addComponentTemplate(state, true, "ct1", ct1);
{
ComposableIndexTemplate it = new ComposableIndexTemplate(org.opensearch.common.collect.List.of("logs*"), new Template(null, new CompressedXContent("{\n" + " \"properties\": {\n" + " \"field2\": {\n" + " \"type\": \"integer\"\n" + " }\n" + " }\n" + " }"), null), org.opensearch.common.collect.List.of("ct1"), 0L, 1L, null, new ComposableIndexTemplate.DataStreamTemplate());
state = service.addIndexTemplateV2(state, true, "logs-data-stream-template", it);
List<CompressedXContent> mappings = MetadataIndexTemplateService.collectMappings(state, "logs-data-stream-template", DataStream.getDefaultBackingIndexName("logs", 1L));
assertNotNull(mappings);
assertThat(mappings.size(), equalTo(4));
List<Map<String, Object>> parsedMappings = mappings.stream().map(m -> {
try {
return MapperService.parseMapping(new NamedXContentRegistry(org.opensearch.common.collect.List.of()), m.string());
} catch (Exception e) {
logger.error(e);
fail("failed to parse mappings: " + m.string());
return null;
}
}).collect(Collectors.toList());
Map<String, Object> firstParsedMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of(TIMESTAMP_FIELD.getName(), org.opensearch.common.collect.Map.of("type", "date"))));
assertThat(parsedMappings.get(0), equalTo(firstParsedMapping));
Map<String, Object> secondMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field1", org.opensearch.common.collect.Map.of("type", "keyword"))));
assertThat(parsedMappings.get(1), equalTo(secondMapping));
Map<String, Object> thirdMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field2", org.opensearch.common.collect.Map.of("type", "integer"))));
assertThat(parsedMappings.get(2), equalTo(thirdMapping));
}
{
// indices matched by templates without the data stream field defined don't get the default @timestamp mapping
ComposableIndexTemplate it = new ComposableIndexTemplate(org.opensearch.common.collect.List.of("timeseries*"), new Template(null, new CompressedXContent("{\n" + " \"properties\": {\n" + " \"field2\": {\n" + " \"type\": \"integer\"\n" + " }\n" + " }\n" + " }"), null), org.opensearch.common.collect.List.of("ct1"), 0L, 1L, null, null);
state = service.addIndexTemplateV2(state, true, "timeseries-template", it);
List<CompressedXContent> mappings = MetadataIndexTemplateService.collectMappings(state, "timeseries-template", "timeseries");
assertNotNull(mappings);
assertThat(mappings.size(), equalTo(2));
List<Map<String, Object>> parsedMappings = mappings.stream().map(m -> {
try {
return MapperService.parseMapping(new NamedXContentRegistry(org.opensearch.common.collect.List.of()), m.string());
} catch (Exception e) {
logger.error(e);
fail("failed to parse mappings: " + m.string());
return null;
}
}).collect(Collectors.toList());
Map<String, Object> firstMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field1", org.opensearch.common.collect.Map.of("type", "keyword"))));
assertThat(parsedMappings.get(0), equalTo(firstMapping));
Map<String, Object> secondMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field2", org.opensearch.common.collect.Map.of("type", "integer"))));
assertThat(parsedMappings.get(1), equalTo(secondMapping));
// a default @timestamp mapping will not be added if the matching template doesn't have the data stream field configured, even
// if the index name matches that of a data stream backing index
mappings = MetadataIndexTemplateService.collectMappings(state, "timeseries-template", DataStream.getDefaultBackingIndexName("timeseries", 1L));
assertNotNull(mappings);
assertThat(mappings.size(), equalTo(2));
parsedMappings = mappings.stream().map(m -> {
try {
return MapperService.parseMapping(new NamedXContentRegistry(org.opensearch.common.collect.List.of()), m.string());
} catch (Exception e) {
logger.error(e);
fail("failed to parse mappings: " + m.string());
return null;
}
}).collect(Collectors.toList());
firstMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field1", org.opensearch.common.collect.Map.of("type", "keyword"))));
assertThat(parsedMappings.get(0), equalTo(firstMapping));
secondMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of("field2", org.opensearch.common.collect.Map.of("type", "integer"))));
assertThat(parsedMappings.get(1), equalTo(secondMapping));
}
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project OpenSearch by opensearch-project.
the class MetadataIndexTemplateServiceTests method testUserDefinedMappingTakesPrecedenceOverDefault.
public void testUserDefinedMappingTakesPrecedenceOverDefault() throws Exception {
final MetadataIndexTemplateService service = getMetadataIndexTemplateService();
ClusterState state = ClusterState.EMPTY_STATE;
{
// user defines a @timestamp mapping as part of a component template
ComponentTemplate ct1 = new ComponentTemplate(new Template(null, new CompressedXContent("{\n" + " \"properties\": {\n" + " \"@timestamp\": {\n" + " \"type\": \"date_nanos\"\n" + " }\n" + " }\n" + " }"), null), null, null);
state = service.addComponentTemplate(state, true, "ct1", ct1);
ComposableIndexTemplate it = new ComposableIndexTemplate(org.opensearch.common.collect.List.of("logs*"), null, org.opensearch.common.collect.List.of("ct1"), 0L, 1L, null, new ComposableIndexTemplate.DataStreamTemplate());
state = service.addIndexTemplateV2(state, true, "logs-template", it);
List<CompressedXContent> mappings = MetadataIndexTemplateService.collectMappings(state, "logs-template", DataStream.getDefaultBackingIndexName("logs", 1L));
assertNotNull(mappings);
assertThat(mappings.size(), equalTo(3));
List<Map<String, Object>> parsedMappings = mappings.stream().map(m -> {
try {
return MapperService.parseMapping(new NamedXContentRegistry(org.opensearch.common.collect.List.of()), m.string());
} catch (Exception e) {
logger.error(e);
fail("failed to parse mappings: " + m.string());
return null;
}
}).collect(Collectors.toList());
Map<String, Object> firstMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of(TIMESTAMP_FIELD.getName(), org.opensearch.common.collect.Map.of("type", "date"))));
assertThat(parsedMappings.get(0), equalTo(firstMapping));
Map<String, Object> secondMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of(TIMESTAMP_FIELD.getName(), org.opensearch.common.collect.Map.of("type", "date_nanos"))));
assertThat(parsedMappings.get(1), equalTo(secondMapping));
}
{
// user defines a @timestamp mapping as part of a composable index template
Template template = new Template(null, new CompressedXContent("{\n" + " \"properties\": {\n" + " \"@timestamp\": {\n" + " \"type\": \"date_nanos\"\n" + " }\n" + " }\n" + " }"), null);
ComposableIndexTemplate it = new ComposableIndexTemplate(org.opensearch.common.collect.List.of("timeseries*"), template, null, 0L, 1L, null, new ComposableIndexTemplate.DataStreamTemplate());
state = service.addIndexTemplateV2(state, true, "timeseries-template", it);
List<CompressedXContent> mappings = MetadataIndexTemplateService.collectMappings(state, "timeseries-template", DataStream.getDefaultBackingIndexName("timeseries-template", 1L));
assertNotNull(mappings);
assertThat(mappings.size(), equalTo(3));
List<Map<String, Object>> parsedMappings = mappings.stream().map(m -> {
try {
return MapperService.parseMapping(new NamedXContentRegistry(org.opensearch.common.collect.List.of()), m.string());
} catch (Exception e) {
logger.error(e);
fail("failed to parse mappings: " + m.string());
return null;
}
}).collect(Collectors.toList());
Map<String, Object> firstMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of(TIMESTAMP_FIELD.getName(), org.opensearch.common.collect.Map.of("type", "date"))));
assertThat(parsedMappings.get(0), equalTo(firstMapping));
Map<String, Object> secondMapping = org.opensearch.common.collect.Map.of("_doc", org.opensearch.common.collect.Map.of("properties", org.opensearch.common.collect.Map.of(TIMESTAMP_FIELD.getName(), org.opensearch.common.collect.Map.of("type", "date_nanos"))));
assertThat(parsedMappings.get(1), equalTo(secondMapping));
}
}
Aggregations