本文整理匯總了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"));
}
示例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());
}
示例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());
}
示例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();
}
示例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);
}
});
}
示例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);
}
});
}