@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 mapping source definition. */ public PutMappingRequestBuilder setSource(XContentBuilder mappingBuilder) { request.source(mappingBuilder); return this; }
/** * The mapping source definition. */ public PutMappingRequestBuilder setSource(String mappingSource, XContentType xContentType) { request.source(mappingSource, xContentType); return this; }
/** * The mapping source definition. */ public PutMappingRequestBuilder setSource(Map mappingSource) { request.source(mappingSource); return this; }
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ public PutMappingRequestBuilder setSource(Object... source) { request.source(source); return this; }
.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(); .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(); .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(); .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();
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). * * Also supports metadata mapping fields such as `_all` and `_parent` as property definition, these metadata * mapping fields will automatically be put on the top level mapping object. */ public PutMappingRequest source(Object... source) { return source(buildFromSimplifiedDef(type, source)); }
/** * The mapping source definition. */ public PutMappingRequest source(String mappingSource, XContentType xContentType) { return source(new BytesArray(mappingSource), xContentType); }
/** * The mapping source definition. */ public PutMappingRequest source(XContentBuilder mappingBuilder) { return source(Strings.toString(mappingBuilder), mappingBuilder.contentType()); }
/** * The mapping source definition. */ @SuppressWarnings("unchecked") public PutMappingRequest source(Map mappingSource) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(mappingSource); return source(Strings.toString(builder), XContentType.JSON); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e); } }
tc.admin().indices().putMapping(new PutMappingRequest("test").type("typex").source("fieldx","type=text")).actionGet(); Assert.fail(); } catch (ElasticsearchSecurityException e) {
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ public PutMappingRequestBuilder setSource(Object... source) { request.source(source); return this; }
/** * The mapping source definition. */ public PutMappingRequestBuilder setSource(XContentBuilder mappingBuilder) { request.source(mappingBuilder); return this; }
/** * The mapping source definition. */ public PutMappingRequestBuilder setSource(XContentBuilder mappingBuilder) { request.source(mappingBuilder); return this; }
/** * The mapping source definition. */ public PutMappingRequestBuilder setSource(Map mappingSource) { request.source(mappingSource); return this; }
@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)); } }
.indices(concreteIndices).type(request.type()) .updateAllTypes(request.updateAllTypes()) .source(request.source());
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). * * Also supports metadata mapping fields such as `_all` and `_parent` as property definition, these metadata * mapping fields will automatically be put on the top level mapping object. */ public PutMappingRequest source(Object... source) { return source(buildFromSimplifiedDef(type, source)); }
/** * The mapping source definition. * @deprecated use {@link #source(String, XContentType)} */ @Deprecated public PutMappingRequest source(String mappingSource) { return source(mappingSource, XContentFactory.xContentType(mappingSource)); }