Search in sources :

Example 1 with TypeMissingException

use of org.opensearch.indices.TypeMissingException in project OpenSearch by opensearch-project.

the class IndexShard method applyDeleteOperation.

private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, String type, String id, @Nullable VersionType versionType, long ifSeqNo, long ifPrimaryTerm, Engine.Operation.Origin origin) throws IOException {
    assert opPrimaryTerm <= getOperationPrimaryTerm() : "op term [ " + opPrimaryTerm + " ] > shard term [" + getOperationPrimaryTerm() + "]";
    ensureWriteAllowed(origin);
    // TODO: clean this up when types are gone
    try {
        Mapping update = docMapper(type).getMapping();
        if (update != null) {
            return new Engine.DeleteResult(update);
        }
    } catch (MapperParsingException | IllegalArgumentException | TypeMissingException e) {
        return new Engine.DeleteResult(e, version, getOperationPrimaryTerm(), seqNo, false);
    }
    if (mapperService.resolveDocumentType(type).equals(mapperService.documentMapper().type()) == false) {
        // document in the wrong type.
        throw new IllegalStateException("Deleting document from type [" + mapperService.resolveDocumentType(type) + "] while current type is [" + mapperService.documentMapper().type() + "]");
    }
    final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
    final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
    return delete(engine, delete);
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException) TypeMissingException(org.opensearch.indices.TypeMissingException) Mapping(org.opensearch.index.mapper.Mapping) Term(org.apache.lucene.index.Term) Engine(org.opensearch.index.engine.Engine) ReadOnlyEngine(org.opensearch.index.engine.ReadOnlyEngine)

Example 2 with TypeMissingException

use of org.opensearch.indices.TypeMissingException in project OpenSearch by opensearch-project.

the class TransportGetFieldMappingsIndexAction method shardOperation.

@Override
protected GetFieldMappingsResponse shardOperation(final GetFieldMappingsIndexRequest request, ShardId shardId) {
    assert shardId != null;
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    Version indexCreatedVersion = indexService.mapperService().getIndexSettings().getIndexVersionCreated();
    Predicate<String> metadataFieldPredicate = (f) -> indicesService.isMetadataField(indexCreatedVersion, f);
    Predicate<String> fieldPredicate = metadataFieldPredicate.or(indicesService.getFieldFilter().apply(shardId.getIndexName()));
    DocumentMapper mapper = indexService.mapperService().documentMapper();
    Collection<String> typeIntersection;
    if (request.types().length == 0) {
        typeIntersection = mapper == null ? Collections.emptySet() : Collections.singleton(mapper.type());
    } else {
        typeIntersection = mapper != null && Regex.simpleMatch(request.types(), mapper.type()) ? Collections.singleton(mapper.type()) : Collections.emptySet();
        if (typeIntersection.isEmpty()) {
            throw new TypeMissingException(shardId.getIndex(), request.types());
        }
    }
    Map<String, Map<String, FieldMappingMetadata>> typeMappings = new HashMap<>();
    for (String type : typeIntersection) {
        DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
        Map<String, FieldMappingMetadata> fieldMapping = findFieldMappingsByType(fieldPredicate, documentMapper, request);
        if (!fieldMapping.isEmpty()) {
            typeMappings.put(type, fieldMapping);
        }
    }
    return new GetFieldMappingsResponse(singletonMap(shardId.getIndexName(), Collections.unmodifiableMap(typeMappings)));
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) ToXContent(org.opensearch.common.xcontent.ToXContent) ThreadPool(org.opensearch.threadpool.ThreadPool) Version(org.opensearch.Version) HashMap(java.util.HashMap) FieldMappingMetadata(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata) OpenSearchException(org.opensearch.OpenSearchException) Writeable(org.opensearch.common.io.stream.Writeable) Regex(org.opensearch.common.regex.Regex) ClusterState(org.opensearch.cluster.ClusterState) Map(java.util.Map) Inject(org.opensearch.common.inject.Inject) Collections.singletonMap(java.util.Collections.singletonMap) Predicate(java.util.function.Predicate) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) Collection(java.util.Collection) IndicesService(org.opensearch.indices.IndicesService) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) Mapper(org.opensearch.index.mapper.Mapper) ShardsIterator(org.opensearch.cluster.routing.ShardsIterator) IndexService(org.opensearch.index.IndexService) TransportService(org.opensearch.transport.TransportService) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) XContentHelper(org.opensearch.common.xcontent.XContentHelper) MappingLookup(org.opensearch.index.mapper.MappingLookup) ShardId(org.opensearch.index.shard.ShardId) ActionFilters(org.opensearch.action.support.ActionFilters) ClusterService(org.opensearch.cluster.service.ClusterService) XContentType(org.opensearch.common.xcontent.XContentType) TypeMissingException(org.opensearch.indices.TypeMissingException) Collections(java.util.Collections) TransportSingleShardAction(org.opensearch.action.support.single.shard.TransportSingleShardAction) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IndexService(org.opensearch.index.IndexService) HashMap(java.util.HashMap) TypeMissingException(org.opensearch.indices.TypeMissingException) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) Version(org.opensearch.Version) FieldMappingMetadata(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

TypeMissingException (org.opensearch.indices.TypeMissingException)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 Term (org.apache.lucene.index.Term)1 OpenSearchException (org.opensearch.OpenSearchException)1 Version (org.opensearch.Version)1 FieldMappingMetadata (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata)1 ActionFilters (org.opensearch.action.support.ActionFilters)1 TransportSingleShardAction (org.opensearch.action.support.single.shard.TransportSingleShardAction)1 ClusterState (org.opensearch.cluster.ClusterState)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1 ClusterBlockLevel (org.opensearch.cluster.block.ClusterBlockLevel)1 IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)1 ShardsIterator (org.opensearch.cluster.routing.ShardsIterator)1 ClusterService (org.opensearch.cluster.service.ClusterService)1