本文整理汇总了Java中org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java PutMappingRequestBuilder类的具体用法?Java PutMappingRequestBuilder怎么用?Java PutMappingRequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PutMappingRequestBuilder类属于org.elasticsearch.action.admin.indices.mapping.put包,在下文中一共展示了PutMappingRequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMappingOnMaster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
public void updateMappingOnMaster(String index, String type, Mapping mappingUpdate, final TimeValue timeout, final MappingUpdateListener listener) {
final PutMappingRequestBuilder request = updateMappingRequest(index, type, mappingUpdate, timeout);
if (listener == null) {
request.execute();
} else {
final ActionListener<PutMappingResponse> actionListener = new ActionListener<PutMappingResponse>() {
@Override
public void onResponse(PutMappingResponse response) {
if (response.isAcknowledged()) {
listener.onMappingUpdate();
} else {
listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]"));
}
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
};
request.execute(actionListener);
}
}
示例2: call
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Boolean> call(String index) {
Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
PutMappingRequestBuilder request = elasticsearch.get().admin().indices()
.preparePutMapping(index)
.setSource(mapping)
.setType(type);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Request %s", Jsonify.toString(request)));
}
return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
.map(Optional::get)
.doOnNext(putMappingResponse -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Response %s", Jsonify.toString(putMappingResponse)));
}
})
.map(AcknowledgedResponse::isAcknowledged);
}
示例3: initCluster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
示例4: initCluster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
示例5: execute
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@Override
public Table execute() throws MetaModelException {
final MutableTable table = getTable();
final Map<String, ?> source = ElasticSearchUtils.getMappingSource(table);
final ElasticSearchDataContext dataContext = getUpdateCallback().getDataContext();
final IndicesAdminClient indicesAdmin = dataContext.getElasticSearchClient().admin().indices();
final String indexName = dataContext.getIndexName();
final PutMappingRequestBuilder requestBuilder =
new PutMappingRequestBuilder(indicesAdmin, PutMappingAction.INSTANCE).setIndices(indexName)
.setType(table.getName());
requestBuilder.setSource(source);
final PutMappingResponse result = requestBuilder.execute().actionGet();
logger.debug("PutMapping response: acknowledged={}", result.isAcknowledged());
dataContext.getElasticSearchClient().admin().indices().prepareRefresh(indexName).get();
final MutableSchema schema = (MutableSchema) getSchema();
schema.addTable(table);
return table;
}
示例6: updateMappingRequest
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) {
if (type.equals(MapperService.DEFAULT_MAPPING)) {
throw new IllegalArgumentException("_default_ mapping should not be updated");
}
return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON)
.setMasterNodeTimeout(timeout).setTimeout(timeout);
}
示例7: testPutMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@Test
public void testPutMapping() {
// Test data
final String indexName = "Index_Name";
final String documentType = "documentType";
final String mappings = "mappings";
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final PutMappingRequestBuilder putMappingRequestBuilder = createMock(PutMappingRequestBuilder.class);
final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
// Reset
resetAll();
// Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.preparePutMapping(indexName)).andReturn(putMappingRequestBuilder);
expect(putMappingRequestBuilder.setType(documentType)).andReturn(putMappingRequestBuilder);
expect(putMappingRequestBuilder.setSource(mappings)).andReturn(putMappingRequestBuilder);
expect(putMappingRequestBuilder.get()).andReturn(putMappingResponse);
// Replay
replayAll();
// Run test scenario
final boolean result = elasticsearchClientWrapper.putMapping(indexName, documentType, mappings);
// Verify
verifyAll();
assertEquals(putMappingResponse.isAcknowledged(), result);
}
示例8: updateMappingRequest
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
private PutMappingRequestBuilder updateMappingRequest(String index, String type, Mapping mappingUpdate, final TimeValue timeout) {
if (type.equals(MapperService.DEFAULT_MAPPING)) {
throw new IllegalArgumentException("_default_ mapping should not be updated");
}
return client.preparePutMapping(index).setType(type).setSource(mappingUpdate.toString())
.setMasterNodeTimeout(timeout).setTimeout(timeout);
}
示例9: initMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
public void initMapping(String indexName, String typeName) {
if (indexMappings.containsKey(indexName) && indexMappings.get(indexName).contains(typeName)) {
return;
}
Set<String> mappings = indexMappings.get(indexName);
if (mappings == null) {
mappings = new HashSet<>();
}
InputStream mappingInputStream = this.getClass().getClassLoader().getResourceAsStream("es-mappings/" + typeName + ".json");
String mapping = null;
try {
if (mappingInputStream != null) {
mapping = IOUtils.toString(mappingInputStream);
}
} catch (IOException e) {
e.printStackTrace();
}
if (mapping == null) {
mapping = "{\n" +
" \"properties\": {\n" +
" \"logType\": {\n" +
" \"type\": \"string\",\n" +
" \"index\": \"not_analyzed\"" +
" }\n" +
" }\n" +
" }";
}
PutMappingRequestBuilder putMappingRequestBuilder = elasticSearchService.getClient().admin().indices().preparePutMapping(indexName);
PutMappingResponse putMappingResponse = putMappingRequestBuilder.setType(typeName).setSource(mapping).get();
mappings.add(typeName);
indexMappings.put(indexName, mappings);
}
示例10: updateMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
protected boolean updateMapping(String indexId, MappingConfiguration mapping) throws SinkError {
double version = getCurrentVersion(indexId);
log.info("Existing mapping version is {}, vs. c version {}", version, mapping.getVersion());
if (version < 0) {
throw new SinkError("Database inconsistency. Metadata version not found in type %s", MetadataDataMapping.METADATA_TYPE_NAME);
}
if (version != mapping.getVersion()) {
throw new SinkError("Database schema version inconsistency. Version numbers don't match. Database version number %d != mapping version number %d",
version, mapping.getVersion());
}
// schema can be updated
Map<String, Object> schema = schemaGenerator.generate(mapping);
PutMappingRequestBuilder request = getClient().admin().indices()
.preparePutMapping(indexId)
.setType(mapping.getType())
.setSource(schema);
PutMappingResponse updateMappingResponse = request.get();
log.info("Update mapping of type {} acknowledged: {}", mapping.getType(), updateMappingResponse.isAcknowledged());
if (!updateMappingResponse.isAcknowledged()) {
log.error("Problem updating mapping for type {}", mapping.getType());
}
Map<String, Object> updatedMetadata = createUpdatedMetadata(indexId);
UpdateResponse mdUpdate = getClient().prepareUpdate(indexId, MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID)
.setDoc(updatedMetadata).get();
log.info("Update metadata record created: {} | id = {} @ {}/{}",
mdUpdate.isCreated(), mdUpdate.getId(), mdUpdate.getIndex(), mdUpdate.getType());
return (mdUpdate.getId().equals(MetadataDataMapping.METADATA_ROW_ID)
&& updateMappingResponse.isAcknowledged());
}
示例11: prepareMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
/**
* This method applies the supplied mapping to the index.
*
* @param index The name of the index
* @param defaultMappings The default mappings
* @return true if the mapping was successful
*/
@SuppressWarnings("unchecked")
private boolean prepareMapping(String index, Map<String, Object> defaultMappings) {
boolean success = true;
for (Map.Entry<String, Object> stringObjectEntry : defaultMappings.entrySet()) {
Map<String, Object> mapping = (Map<String, Object>) stringObjectEntry.getValue();
if (mapping == null) {
throw new RuntimeException("type mapping not defined");
}
PutMappingRequestBuilder putMappingRequestBuilder = client.admin().indices().preparePutMapping()
.setIndices(index);
putMappingRequestBuilder.setType(stringObjectEntry.getKey());
putMappingRequestBuilder.setSource(mapping);
if (log.isLoggable(Level.FINE)) {
log.fine("Elasticsearch create mapping for index '"
+ index + " and type '" + stringObjectEntry.getKey() + "': " + mapping);
}
PutMappingResponse resp = putMappingRequestBuilder.execute().actionGet();
if (resp.isAcknowledged()) {
if (log.isLoggable(Level.FINE)) {
log.fine("Elasticsearch mapping for index '"
+ index + " and type '" + stringObjectEntry.getKey() + "' was acknowledged");
}
} else {
success = false;
log.warning("Elasticsearch mapping creation was not acknowledged for index '"
+ index + " and type '" + stringObjectEntry.getKey() + "'");
}
}
return success;
}
示例12: putMappingFromString
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
public void putMappingFromString(String index, String type, String mapping) throws EsServerException {
IndicesAdminClient indicesAdminClient = getClient().admin().indices();
PutMappingRequestBuilder pmrb = new PutMappingRequestBuilder(indicesAdminClient);
pmrb.setIndices(index);
pmrb.setType(type);
pmrb.setSource(mapping);
pmrb.execute().actionGet().isAcknowledged();
}
示例13: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
public PutMappingResponse createMapping(final String index,
final BuilderCallback<PutMappingRequestBuilder> builder) {
final PutMappingResponse actionGet = builder
.apply(client().admin().indices().preparePutMapping(index))
.execute().actionGet();
if (!actionGet.isAcknowledged()) {
onFailure("Failed to create a mapping for " + index + ".",
actionGet);
}
return actionGet;
}
示例14: testPuttingMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@Test
public void testPuttingMappings() throws IOException {
// cannot support creating multiple mappings for types in a single call ?
// ATTENSION: BOTH setType(typeName) and the startObject(typeName) are needed, but startObject("mappings") is not needed
PutMappingRequestBuilder pmrb1 = client.admin().indices().preparePutMapping(indexName).setType(typeBranch).setSource(XContentFactory.jsonBuilder()
.startObject()
// .startObject("mappings")
.startObject(typeBranch)
.endObject()
// .endObject()
.endObject());
PutMappingRequestBuilder pmrb2 = client.admin().indices().preparePutMapping(indexName).setType(typeEmployee).setSource(XContentFactory.jsonBuilder()
.startObject()
// .startObject("mappings")
.startObject(typeEmployee)
.startObject("_parent")
.field("type", "branch")
.endObject()
.endObject()
// .endObject()
.endObject());
System.out.println(pmrb1.request().source());
System.out.println(pmrb2.request().source());
PutMappingResponse response1 = pmrb1.execute().actionGet();
PutMappingResponse response2 = pmrb2.execute().actionGet();
System.out.println(response1);
System.out.println(response2);
}
示例15: newMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; //导入依赖的package包/类
@Override
public BaseMetricTransportClient newMapping(String index, String type, Map<String, Object> mapping) {
new PutMappingRequestBuilder(client(), PutMappingAction.INSTANCE)
.setIndices(index)
.setType(type)
.setSource(mapping)
.execute().actionGet();
logger.info("mapping created for index {} and type {}", index, type);
return this;
}