Skip to content

Commit

Permalink
Add getMetadataFields to MapperService (opensearch-project#13819)
Browse files Browse the repository at this point in the history
* Add getMetadataFields to MapperService

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Unmodifiable Set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
  • Loading branch information
cwperks committed May 24, 2024
1 parent 8ac6806 commit 8883e62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Make outbound side of transport protocol dependent ([#13293](https://github.com/opensearch-project/OpenSearch/pull/13293))
- [Remote Store] Add dynamic cluster settings to set timeout for segments upload to Remote Store ([#13679](https://github.com/opensearch-project/OpenSearch/pull/13679))
- [Remote Store] Upload translog checkpoint as object metadata to translog.tlog([#13637](https://github.com/opensearch-project/OpenSearch/pull/13637))
- Add getMetadataFields to MapperService ([#13819](https://github.com/opensearch-project/OpenSearch/pull/13819))

### Dependencies
- Bump `com.github.spullara.mustache.java:compiler` from 0.9.10 to 0.9.13 ([#13329](https://github.com/opensearch-project/OpenSearch/pull/13329), [#13559](https://github.com/opensearch-project/OpenSearch/pull/13559))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,13 @@ public boolean isMetadataField(String field) {
return mapperRegistry.isMetadataField(field);
}

/**
* Returns a set containing the registered metadata fields
*/
public Set<String> getMetadataFields() {
return Collections.unmodifiableSet(mapperRegistry.getMetadataMapperParsers().keySet());
}

/**
* An analyzer wrapper that can lookup fields within the index mappings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.opensearch.index.mapper.KeywordFieldMapper.KeywordFieldType;
import org.opensearch.index.mapper.MapperService.MergeReason;
import org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType;
import org.opensearch.indices.IndicesModule;
import org.opensearch.indices.InvalidTypeNameException;
import org.opensearch.indices.analysis.AnalysisModule.AnalysisProvider;
import org.opensearch.plugins.AnalysisPlugin;
Expand Down Expand Up @@ -90,6 +91,11 @@ public void testTypeValidation() {
MapperService.validateTypeName("_doc"); // no exception
}

public void testGetMetadataFieldsReturnsExpectedSet() throws Throwable {
final MapperService mapperService = createIndex("test1").mapperService();
assertEquals(mapperService.getMetadataFields(), IndicesModule.getBuiltInMetadataFields());
}

public void testPreflightUpdateDoesNotChangeMapping() throws Throwable {
final MapperService mapperService = createIndex("test1").mapperService();
final CompressedXContent mapping = createMappingSpecifyingNumberOfFields(1);
Expand Down

0 comments on commit 8883e62

Please sign in to comment.