@Override public String toString() { StringBuilder message = new StringBuilder(); message.append("ES put mapping request"); if (request.indices().length > 0) { message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ","))); } String type = request.type(); if (type != null) { message.append(String.format(" on type '%s'", type)); } String source = request.source(); if (source != null) { message.append(String.format(" with source '%s'", source)); } return message.toString(); } }
@Override public boolean putMapping(String indexName, String type, Object mapping) { Assert.notNull(indexName, "No index defined for putMapping()"); Assert.notNull(type, "No type defined for putMapping()"); PutMappingRequest request = new PutMappingRequest(indexName).type(type); if (mapping instanceof String) { request.source(String.valueOf(mapping), XContentType.JSON); } else if (mapping instanceof Map) { request.source((Map) mapping); } else if (mapping instanceof XContentBuilder) { request.source((XContentBuilder) mapping); } try { return client.indices().putMapping(request).isAcknowledged(); } catch (IOException e) { throw new ElasticsearchException("Failed to put mapping for " + indexName, e); } }
/** * The type of the mappings. */ public PutMappingRequestBuilder setType(String type) { request.type(type); return this; }
tc.admin().indices().create(new CreateIndexRequest("u")).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("a").type("b") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("c").type("d") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("test").type("type1") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("u").type("b") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet();
@Override public void onFailure(Exception t) { logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t); listener.onFailure(t); } });
tc.admin().indices().putMapping(new PutMappingRequest("test").type("typex").source("fieldx","type=text")).actionGet(); Assert.fail(); } catch (ElasticsearchSecurityException e) {
/** * The type of the mappings. */ public PutMappingRequestBuilder setType(String type) { request.type(type); return this; }
/** * The type of the mappings. */ public PutMappingRequestBuilder setType(String type) { request.type(type); return this; }
/** * The type of the mappings. */ public PutMappingRequestBuilder setType(String type) { request.type(type); return this; }
/** * The type of the mappings. */ public PutMappingRequestBuilder setType(String type) { request.type(type); return this; }
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest() .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .indices(concreteIndices).type(request.type()) .updateAllTypes(request.updateAllTypes()) .source(request.source()); } catch (IndexNotFoundException ex) { logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", request.indices(), request.type()), ex); throw ex;
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); putMappingRequest.type(request.param("type")); putMappingRequest.source(request.requiredContent(), request.getXContentType()); if (request.hasParam("update_all_types")) { DEPRECATION_LOGGER.deprecated("[update_all_types] is deprecated since indices may not have more than one type anymore"); } putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout())); putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions())); return channel -> client.admin().indices().putMapping(putMappingRequest, new RestToXContentListener<>(channel)); } }
PutMappingRequest putRequest = new PutMappingRequest(indexName); putRequest.source(indexMapping); putRequest.type("test"); try { PutMappingResponse response = admin.putMapping(putRequest).actionGet(); } catch (Exception e) { log.warn("Failed to add mapping", e); throw new RuntimeException(e); }
@Override public void onFailure(Exception t) { logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t); listener.onFailure(t); } });
private static Request putMapping(final PutMappingRequest putMappingRequest) { final String endpoint = "/" + putMappingRequest.indices()[0] + "/_mapping/" + putMappingRequest.type(); final ByteArrayEntity entity = new ByteArrayEntity(putMappingRequest.source().getBytes(), ContentType.APPLICATION_JSON); return new Request(HttpPut.METHOD_NAME, endpoint, Collections.emptyMap(), entity); }
@Override public void onFailure(Exception t) { logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t); listener.onFailure(t); } });
@Override public void onFailure(Exception t) { logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t); listener.onFailure(t); } });
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); putMappingRequest.type(request.param("type")); putMappingRequest.source(request.content().toUtf8()); putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout())); putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions())); client.admin().indices().putMapping(putMappingRequest, new AcknowledgedRestListener<PutMappingResponse>(channel)); } }
@Override public Table execute() throws MetaModelException { final MutableTable table = getTable(); final Map<String, ?> source = ElasticSearchUtils.getMappingSource(table); final ElasticSearchRestDataContext dataContext = getUpdateCallback().getDataContext(); final String indexName = dataContext.getIndexName(); final PutMappingRequest putMapping = new PutMappingRequest(indexName).type(table.getName()).source(source); getUpdateCallback().execute(putMapping); final MutableSchema schema = (MutableSchema) getSchema(); schema.addTable(table); return table; }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); putMappingRequest.type(request.param("type")); putMappingRequest.source(request.requiredContent(), request.getXContentType()); putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout())); putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions())); return channel -> client.admin().indices().putMapping(putMappingRequest, new AcknowledgedRestListener<>(channel)); } }