/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequestBuilder addMapping(String type, String source, XContentType xContentType) { request.mapping(type, source, xContentType); return this; }
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ public CreateIndexRequestBuilder addMapping(String type, Object... source) { request.mapping(type, source); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public CreateIndexRequestBuilder addMapping(String type, XContentBuilder source) { request.mapping(type, source); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public CreateIndexRequestBuilder addMapping(String type, Map<String, Object> source) { request.mapping(type, source); return this; }
@Test public void testAdvancedMapping() throws Exception { setup(Settings.EMPTY, new DynamicSgConfig(), Settings.EMPTY, true, ClusterConfiguration.DEFAULT); try (TransportClient tc = getInternalTransportClient(this.clusterInfo, Settings.EMPTY)) { tc.admin().indices().create(new CreateIndexRequest("myindex1") .mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet(); tc.admin().indices().create(new CreateIndexRequest("myindex2") .mapping("mytype2", FileHelper.loadFile("mapping2.json"), XContentType.JSON)).actionGet(); tc.admin().indices().create(new CreateIndexRequest("myindex3") .mapping("mytype3", FileHelper.loadFile("mapping3.json"), XContentType.JSON)).actionGet(); tc.admin().indices().create(new CreateIndexRequest("myindex4") .mapping("mytype4", FileHelper.loadFile("mapping4.json"), XContentType.JSON)).actionGet(); } RestHelper rh = nonSslRestHelper(); System.out.println("############ write into mapping 1"); String data1 = FileHelper.loadFile("data1.json"); System.out.println(rh.executePutRequest("myindex1/mytype1/1?refresh", data1, encodeBasicHeader("nagilum", "nagilum"))); System.out.println(rh.executePutRequest("myindex1/mytype1/1?refresh", data1, encodeBasicHeader("nagilum", "nagilum"))); System.out.println("############ write into mapping 2"); System.out.println(rh.executePutRequest("myindex2/mytype2/2?refresh", data1, encodeBasicHeader("nagilum", "nagilum"))); System.out.println(rh.executePutRequest("myindex2/mytype2/2?refresh", data1, encodeBasicHeader("nagilum", "nagilum"))); System.out.println("############ write into mapping 3"); String parent = FileHelper.loadFile("data2.json"); String child = FileHelper.loadFile("data3.json"); System.out.println(rh.executePutRequest("myindex3/mytype3/1?refresh", parent, encodeBasicHeader("nagilum", "nagilum"))); System.out.println(rh.executePutRequest("myindex3/mytype3/2?routing=1&refresh", child, encodeBasicHeader("nagilum", "nagilum"))); System.out.println("############ write into mapping 4"); System.out.println(rh.executePutRequest("myindex4/mytype4/1?refresh", parent, encodeBasicHeader("nagilum", "nagilum"))); System.out.println(rh.executePutRequest("myindex4/mytype4/2?routing=1&refresh", child, encodeBasicHeader("nagilum", "nagilum"))); }
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ public CreateIndexRequest mapping(String type, Object... source) { mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source)); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequest mapping(String type, String source, XContentType xContentType) { return mapping(type, new BytesArray(source), xContentType); }
public RolloverRequestBuilder mapping(String type, String source) { this.request.getCreateIndexRequest().mapping(type, source); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public CreateIndexRequest mapping(String type, XContentBuilder source) { return mapping(type, BytesReference.bytes(source), source.contentType()); }
/** * Sets the settings and mappings as a single source. */ @SuppressWarnings("unchecked") public CreateIndexRequest source(Map<String, ?> source, DeprecationHandler deprecationHandler) { boolean found = false; for (Map.Entry<String, ?> entry : source.entrySet()) { String name = entry.getKey(); if (SETTINGS.match(name, deprecationHandler)) { found = true; settings((Map<String, Object>) entry.getValue()); } else if (MAPPINGS.match(name, deprecationHandler)) { found = true; Map<String, Object> mappings = (Map<String, Object>) entry.getValue(); for (Map.Entry<String, Object> entry1 : mappings.entrySet()) { mapping(entry1.getKey(), (Map<String, Object>) entry1.getValue()); } } else if (ALIASES.match(name, deprecationHandler)) { found = true; aliases((Map<String, Object>) entry.getValue()); } } if (!found) { // the top level are settings, use them settings(source); } return this; }
public boolean createIndex(String type, XContentBuilder mappingBuilder) { try { if (this.instance() == null) return false; CreateIndexRequest request = new CreateIndexRequest(name); request.settings(Settings.builder() .put("index.number_of_shards", 1) .put("index.number_of_shards", 5)); if (mappingBuilder != null) request.mapping(type, mappingBuilder); CreateIndexResponse response = this.client.indices().create(request, RequestOptions.DEFAULT); return response.isAcknowledged(); } catch (IOException e) { log.error(e.getMessage()); return false; } }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ @SuppressWarnings("unchecked") public CreateIndexRequest mapping(String type, Map source) { if (mappings.containsKey(type)) { throw new IllegalStateException("mappings for type \"" + type + "\" were already defined"); } // wrap it in a type map if its not if (source.size() != 1 || !source.containsKey(type)) { source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map(); } try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); return mapping(type, builder); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequestBuilder addMapping(String type, String source, XContentType xContentType) { request.mapping(type, source, xContentType); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequestBuilder addMapping(String type, String source, XContentType xContentType) { request.mapping(type, source, xContentType); return this; }
createIndexRequest.settings(taskResultIndexSettings()); createIndexRequest.index(TASK_INDEX); createIndexRequest.mapping(TASK_TYPE, taskResultIndexMapping(), XContentType.JSON); createIndexRequest.cause("auto(task api)");
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @deprecated use {@link #addMapping(String, String, XContentType)} to avoid content type auto-detection */ @Deprecated public CreateIndexRequestBuilder addMapping(String type, String source) { request.mapping(type, source); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequest mapping(String type, String source, XContentType xContentType) { return mapping(type, new BytesArray(source), xContentType); }
/** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ public CreateIndexRequest mapping(String type, Object... source) { mapping(type, PutMappingRequest.buildFromSimplifiedDef(type, source)); return this; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @deprecated use {@link #mapping(String, String, XContentType)} to avoid content type detection */ @Deprecated public CreateIndexRequest mapping(String type, String source) { return mapping(type, new BytesArray(source), XContentFactory.xContentType(source)); }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public CreateIndexRequest mapping(String type, XContentBuilder source) { return mapping(type, source.bytes(), source.contentType()); }