use of org.opensearch.index.mapper.MapperException in project OpenSearch by opensearch-project.
the class ParentJoinFieldMapperTests method testMultipleLevels.
public void testMultipleLevels() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("join_field").field("type", "join").startObject("relations").field("parent", "child").field("child", "grand_child").endObject().endObject().endObject().endObject());
IndexService service = createIndex("test");
DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService()));
// Doc without join
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON));
assertNull(doc.rootDoc().getBinaryValue("join_field"));
// Doc parent
doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child
doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("join_field").field("name", "child").field("parent", "1").endObject().endObject()), XContentType.JSON, "1"));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child missing parent
MapperException exc = expectThrows(MapperParsingException.class, () -> docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()), XContentType.JSON, "1")));
assertThat(exc.getRootCause().getMessage(), containsString("[parent] is missing for join field [join_field]"));
// Doc child missing routing
exc = expectThrows(MapperParsingException.class, () -> docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("join_field").field("name", "child").field("parent", "1").endObject().endObject()), XContentType.JSON)));
assertThat(exc.getRootCause().getMessage(), containsString("[routing] is missing for join field [join_field]"));
// Doc grand_child
doc = docMapper.parse(new SourceToParse("test", "type", "3", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("join_field").field("name", "grand_child").field("parent", "2").endObject().endObject()), XContentType.JSON, "1"));
assertEquals("2", doc.rootDoc().getBinaryValue("join_field#child").utf8ToString());
assertEquals("grand_child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Unknown join name
exc = expectThrows(MapperParsingException.class, () -> docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON)));
assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]"));
}
use of org.opensearch.index.mapper.MapperException in project OpenSearch by opensearch-project.
the class TransportShardBulkAction method dispatchedShardOperationOnPrimary.
@Override
protected void dispatchedShardOperationOnPrimary(BulkShardRequest request, IndexShard primary, ActionListener<PrimaryResult<BulkShardRequest, BulkShardResponse>> listener) {
ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis, (update, shardId, mappingListener) -> {
assert update != null;
assert shardId != null;
mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), update, mappingListener);
}, mappingUpdateListener -> observer.waitForNextChange(new ClusterStateObserver.Listener() {
@Override
public void onNewClusterState(ClusterState state) {
mappingUpdateListener.onResponse(null);
}
@Override
public void onClusterServiceClose() {
mappingUpdateListener.onFailure(new NodeClosedException(clusterService.localNode()));
}
@Override
public void onTimeout(TimeValue timeout) {
mappingUpdateListener.onFailure(new MapperException("timed out while waiting for a dynamic mapping update"));
}
}), listener, threadPool, executor(primary));
}
use of org.opensearch.index.mapper.MapperException in project OpenSearch by opensearch-project.
the class ParentJoinFieldMapperTests method testSingleLevel.
public void testSingleLevel() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("join_field").field("type", "join").startObject("relations").field("parent", "child").endObject().endObject().endObject().endObject());
IndexService service = createIndex("test");
DocumentMapper docMapper = service.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
assertTrue(docMapper.mappers().getMapper("join_field") == ParentJoinFieldMapper.getMapper(service.mapperService()));
// Doc without join
ParsedDocument doc = docMapper.parse(new SourceToParse("test", "type", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON));
assertNull(doc.rootDoc().getBinaryValue("join_field"));
// Doc parent
doc = docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()), XContentType.JSON));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("parent", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Doc child
doc = docMapper.parse(new SourceToParse("test", "type", "2", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("join_field").field("name", "child").field("parent", "1").endObject().endObject()), XContentType.JSON, "1"));
assertEquals("1", doc.rootDoc().getBinaryValue("join_field#parent").utf8ToString());
assertEquals("child", doc.rootDoc().getBinaryValue("join_field").utf8ToString());
// Unknown join name
MapperException exc = expectThrows(MapperParsingException.class, () -> docMapper.parse(new SourceToParse("test", "type", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()), XContentType.JSON)));
assertThat(exc.getRootCause().getMessage(), containsString("unknown join name [unknown] for field [join_field]"));
}
use of org.opensearch.index.mapper.MapperException in project OpenSearch by opensearch-project.
the class NamedAnalyzerTests method testCheckAllowedInMode.
public void testCheckAllowedInMode() {
try (NamedAnalyzer testAnalyzer = new NamedAnalyzer("my_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", AnalysisMode.INDEX_TIME), Integer.MIN_VALUE)) {
testAnalyzer.checkAllowedInMode(AnalysisMode.INDEX_TIME);
MapperException ex = expectThrows(MapperException.class, () -> testAnalyzer.checkAllowedInMode(AnalysisMode.SEARCH_TIME));
assertEquals("analyzer [my_analyzer] contains filters [my_analyzer] that are not allowed to run in search time mode.", ex.getMessage());
ex = expectThrows(MapperException.class, () -> testAnalyzer.checkAllowedInMode(AnalysisMode.ALL));
assertEquals("analyzer [my_analyzer] contains filters [my_analyzer] that are not allowed to run in all mode.", ex.getMessage());
}
try (NamedAnalyzer testAnalyzer = new NamedAnalyzer("my_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", AnalysisMode.SEARCH_TIME), Integer.MIN_VALUE)) {
testAnalyzer.checkAllowedInMode(AnalysisMode.SEARCH_TIME);
MapperException ex = expectThrows(MapperException.class, () -> testAnalyzer.checkAllowedInMode(AnalysisMode.INDEX_TIME));
assertEquals("analyzer [my_analyzer] contains filters [my_analyzer] that are not allowed to run in index time mode.", ex.getMessage());
ex = expectThrows(MapperException.class, () -> testAnalyzer.checkAllowedInMode(AnalysisMode.ALL));
assertEquals("analyzer [my_analyzer] contains filters [my_analyzer] that are not allowed to run in all mode.", ex.getMessage());
}
try (NamedAnalyzer testAnalyzer = new NamedAnalyzer("my_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", AnalysisMode.ALL), Integer.MIN_VALUE)) {
testAnalyzer.checkAllowedInMode(AnalysisMode.ALL);
testAnalyzer.checkAllowedInMode(AnalysisMode.INDEX_TIME);
testAnalyzer.checkAllowedInMode(AnalysisMode.SEARCH_TIME);
}
}
use of org.opensearch.index.mapper.MapperException in project OpenSearch by opensearch-project.
the class AnalysisRegistryTests method testOverrideDefaultAnalyzerWithoutAnalysisModeAll.
public void testOverrideDefaultAnalyzerWithoutAnalysisModeAll() throws IOException {
Version version = VersionUtils.randomVersion(random());
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index", settings);
TokenFilterFactory tokenFilter = new AbstractTokenFilterFactory(indexSettings, "my_filter", Settings.EMPTY) {
@Override
public AnalysisMode getAnalysisMode() {
return randomFrom(AnalysisMode.SEARCH_TIME, AnalysisMode.INDEX_TIME);
}
@Override
public TokenStream create(TokenStream tokenStream) {
return tokenStream;
}
};
TokenizerFactory tokenizer = new AbstractTokenizerFactory(indexSettings, Settings.EMPTY, "my_tokenizer") {
@Override
public Tokenizer create() {
return new StandardTokenizer();
}
};
Analyzer analyzer = new CustomAnalyzer(tokenizer, new CharFilterFactory[0], new TokenFilterFactory[] { tokenFilter });
MapperException ex = expectThrows(MapperException.class, () -> emptyRegistry.build(IndexSettingsModule.newIndexSettings("index", settings), singletonMap("default", new PreBuiltAnalyzerProvider("default", AnalyzerScope.INDEX, analyzer)), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
assertEquals("analyzer [default] contains filters [my_filter] that are not allowed to run in all mode.", ex.getMessage());
}
Aggregations