當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeMissingException類代碼示例

本文整理匯總了Java中org.elasticsearch.indices.TypeMissingException的典型用法代碼示例。如果您正苦於以下問題:Java TypeMissingException類的具體用法?Java TypeMissingException怎麽用?Java TypeMissingException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeMissingException類屬於org.elasticsearch.indices包,在下文中一共展示了TypeMissingException類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAutoCreateWithDisabledDynamicMappings

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
public void testAutoCreateWithDisabledDynamicMappings() throws Exception {
    assertAcked(client().admin().indices().preparePutTemplate("my_template")
        .setCreate(true)
        .setPatterns(Collections.singletonList("index_*"))
        .addMapping("foo", "field", "type=keyword")
        .setSettings(Settings.builder().put("index.mapper.dynamic", false).build())
        .get());

    // succeeds since 'foo' has an explicit mapping in the template
    indexRandom(true, false, client().prepareIndex("index_1", "foo", "1").setSource("field", "abc"));

    // fails since 'bar' does not have an explicit mapping in the template and dynamic template creation is disabled
    TypeMissingException e1 = expectThrows(TypeMissingException.class,
            () -> client().prepareIndex("index_2", "bar", "1").setSource("field", "abc").get());
    assertEquals("type[bar] missing", e1.getMessage());
    assertEquals("trying to auto create mapping, but dynamic mapping is disabled", e1.getCause().getMessage());

    // make sure no mappings were created for bar
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices("index_2").get();
    assertFalse(getIndexResponse.mappings().containsKey("bar"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:DynamicMappingIT.java

示例2: documentMapperWithAutoCreate

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
/**
 * Returns the document mapper created, including a mapping update if the
 * type has been dynamically created.
 */
public DocumentMapperForType documentMapperWithAutoCreate(String type) {
    DocumentMapper mapper = mappers.get(type);
    if (mapper != null) {
        return new DocumentMapperForType(mapper, null);
    }
    if (!dynamic) {
        throw new TypeMissingException(index(),
                new IllegalStateException("trying to auto create mapping, but dynamic mapping is disabled"), type);
    }
    mapper = parse(type, null, true);
    return new DocumentMapperForType(mapper, mapper.mapping());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:MapperService.java

示例3: documentMapperWithAutoCreate

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
/**
 * Returns the document mapper created, including a mapping update if the
 * type has been dynamically created.
 */
public DocumentMapperForType documentMapperWithAutoCreate(String type) {
    DocumentMapper mapper = mappers.get(type);
    if (mapper != null) {
        return new DocumentMapperForType(mapper, null);
    }
    if (!dynamic) {
        throw new TypeMissingException(index, type, "trying to auto create mapping, but dynamic mapping is disabled");
    }
    mapper = parse(type, null, true);
    return new DocumentMapperForType(mapper, mapper.mapping());
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:16,代碼來源:MapperService.java

示例4: delete

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
@Delete("/:type")
@Delete("/:type/")
public Payload delete(String type) {
	try {
		Credentials credentials = SpaceContext.checkAdminCredentials();
		Start.get().getElasticClient().deleteIndex(credentials.backendId(), type);
		DataAccessControl.delete(type);
	} catch (TypeMissingException ignored) {
	}
	return JsonPayload.success();
}
 
開發者ID:spacedog-io,項目名稱:spacedog-server,代碼行數:12,代碼來源:SchemaResource.java

示例5: prepareRequest

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
    GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
    getMappingsRequest.indices(indices).types(types);
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetMappingsResponse response, XContentBuilder builder) throws Exception {

            ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
            if (mappingsByIndex.isEmpty()) {
                if (indices.length != 0 && types.length != 0) {
                    return new BytesRestResponse(OK, builder.startObject().endObject());
                } else if (indices.length != 0) {
                    builder.close();
                    return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
                } else if (types.length != 0) {
                    builder.close();
                    return new BytesRestResponse(channel, new TypeMissingException("_all", types[0]));
                } else {
                    return new BytesRestResponse(OK, builder.startObject().endObject());
                }
            }

            builder.startObject();
            for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappingsByIndex) {
                if (indexEntry.value.isEmpty()) {
                    continue;
                }
                builder.startObject(indexEntry.key);
                builder.startObject(Fields.MAPPINGS);
                for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
                    builder.field(typeEntry.key);
                    builder.map(typeEntry.value.sourceAsMap());
                }
                builder.endObject();
                builder.endObject();
            }

            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:48,代碼來源:RestGetMappingAction.java

示例6: handleRequest

import org.elasticsearch.indices.TypeMissingException; //導入依賴的package包/類
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
    GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
    getMappingsRequest.indices(indices).types(types);
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetMappingsResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
            if (mappingsByIndex.isEmpty()) {
                if (indices.length != 0 && types.length != 0) {
                    return new BytesRestResponse(OK, builder.endObject());
                } else if (indices.length != 0) {
                    return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
                } else if (types.length != 0) {
                    return new BytesRestResponse(channel, new TypeMissingException(new Index("_all"), types[0]));
                } else {
                    return new BytesRestResponse(OK, builder.endObject());
                }
            }

            for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappingsByIndex) {
                if (indexEntry.value.isEmpty()) {
                    continue;
                }
                builder.startObject(indexEntry.key, XContentBuilder.FieldCaseConversion.NONE);
                builder.startObject(Fields.MAPPINGS);
                for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
                    builder.field(typeEntry.key);
                    Map<String, Object> mapping = typeEntry.value.sourceAsMap();
                    if (mapping.containsKey("_meta")) {
                        ((Map<String, Object>)mapping.get("_meta")).put(MappingMetaData.MAPPING_VERSION, typeEntry.value.mappingVersion());
                    } else {
                        HashMap<String, Object> mappingMeta = new HashMap<>();
                        mappingMeta.put(MappingMetaData.MAPPING_VERSION, typeEntry.value.mappingVersion());
                        mapping.put("_meta", mappingMeta);
                    }
                    builder.map(mapping);
                }
                builder.endObject();
                builder.endObject();
            }

            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:53,代碼來源:RestGetMappingAction.java


注:本文中的org.elasticsearch.indices.TypeMissingException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。