本文整理匯總了Java中org.elasticsearch.action.admin.indices.create.CreateIndexRequest.mapping方法的典型用法代碼示例。如果您正苦於以下問題:Java CreateIndexRequest.mapping方法的具體用法?Java CreateIndexRequest.mapping怎麽用?Java CreateIndexRequest.mapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.admin.indices.create.CreateIndexRequest
的用法示例。
在下文中一共展示了CreateIndexRequest.mapping方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createChatsIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
private void createChatsIndex(IndicesAdminClient indices) {
CreateIndexRequest createBuilder = new CreateIndexRequest("chats");
try {
// @formatter:off
XContentBuilder mappingBuilder = XContentFactory.jsonBuilder()
.startObject()
.startObject("chat")
.startObject("properties")
.startObject("date")
.field("type", "long")
.endObject()
.startObject("type")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject();
createBuilder.mapping("chat", mappingBuilder);
// @formatter:on
} catch (IOException e) {
e.printStackTrace();
}
indices.create(createBuilder);
}
示例2: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
@Override
public void createIndex(String indexName, String indexType, Object source) {
logger.info(String.format("Generating index %s ...", indexName));
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
if (indexType != null) {
String settings = generateSettings(source);
if (settings != null) {
logger.info("Setting up...");
createIndexRequest.settings(settings);
}
}
logger.info("Mapping...");
String mapping = generateMapping(source);
createIndexRequest.mapping(indexType, mapping);
try {
CreateIndexResponse response = elasticSearchClient.admin().indices().create(createIndexRequest).actionGet();
if (response.isAcknowledged()) {
logger.info(String.format("Index %s created!", indexName));
}
} catch (ElasticsearchException ex) {
logger.error(String.format("Index %s was not created due some errors.", indexName), ex);
}
}
示例3: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
@BeforeMethod
protected void createIndex() {
logger.info("creating index [" + INDEX + "]");
CreateIndexRequest createIndexRequest = createIndexRequest(INDEX);
String settings = getSettings();
if (settings != null)
createIndexRequest.settings(getSettings());
String mapping = getMapping();
if (mapping != null)
createIndexRequest.mapping(TYPE, getMapping());
assertThat("Index creation", node.client().admin().indices().create(createIndexRequest).actionGet().isAcknowledged());
logger.info("Running Cluster Health");
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
}
示例4: createChannelsIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
private void createChannelsIndex(IndicesAdminClient indices) {
CreateIndexRequest createBuilder = new CreateIndexRequest("channels");
try {
// @formatter:off
XContentBuilder mappingBuilder = XContentFactory.jsonBuilder()
.startObject()
.startObject("channel")
.startObject("properties")
.startObject("topic")
.field("type", "object") // we only have one so don't use type 'nested'
.endObject()
.startObject("topic.time")
.field("type", "long")
.endObject()
.startObject("last_activity")
.field("type", "long")
.endObject()
.startObject("added_at")
.field("type", "long")
.endObject()
.startObject("last_activity_valid") // was last_valid_content_at
.field("type", "long")
.endObject()
.startObject("_name_suggest")
.field("payloads", true)
.field("index_analyzer", "simple")
.field("search_analyzer", "simple")
.field("type", "completion")
.endObject()
.endObject()
.endObject()
.endObject();
createBuilder.mapping("channel", mappingBuilder);
// @formatter:on
} catch (IOException e) {
e.printStackTrace();
}
indices.create(createBuilder);
}
示例5: doExecute
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
@Override
protected void doExecute(final Task task, final IndexRequest request, final ActionListener<IndexResponse> listener) {
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
ClusterState state = clusterService.state();
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request);
createIndexRequest.index(request.index());
createIndexRequest.mapping(request.type());
createIndexRequest.cause("auto(index api)");
createIndexRequest.masterNodeTimeout(request.timeout());
createIndexAction.execute(task, createIndexRequest, new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(task, request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
try {
innerExecute(task, request, listener);
} catch (Throwable e1) {
listener.onFailure(e1);
}
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(task, request, listener);
}
}
示例6: newIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
@Override
public BaseIngestTransportClient newIndex(String index) {
if (client == null) {
logger.warn("no client for create index");
return this;
}
if (index == null) {
logger.warn("no index name given to create index");
return this;
}
CreateIndexRequest request = new CreateIndexRequest(index).listenerThreaded(false);
if (getSettings() != null) {
request.settings(getSettings());
}
if (getMappings() != null) {
for (Map.Entry<String, String> me : getMappings().entrySet()) {
request.mapping(me.getKey(), me.getValue());
}
}
logger.info("creating index {} with settings = {}, mappings = {}",
index, getSettings() != null ? getSettings().getAsMap() : null, getMappings());
try {
client.admin().indices().create(request).actionGet();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
logger.info("index {} created", index);
return this;
}
示例7: newIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
@Override
public BulkNodeClient newIndex(String index) {
if (closed) {
throw new ElasticsearchIllegalStateException("client is closed");
}
if (client == null) {
logger.warn("no client");
return this;
}
if (index == null) {
logger.warn("no index name given to create index");
return this;
}
CreateIndexRequest request = new CreateIndexRequest(index);
if (getSettings() != null) {
request.settings(getSettings());
}
if (getMappings() != null) {
for (Map.Entry<String, String> me : getMappings().entrySet()) {
request.mapping(me.getKey(), me.getValue());
}
}
logger.info("creating index {} with settings = {}, mappings = {}",
index, getSettings() != null ? getSettings().getAsMap() : "", getMappings());
try {
client.admin().indices().create(request).actionGet();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return this;
}
示例8: initialSeedKibanaIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //導入方法依賴的package包/類
private boolean initialSeedKibanaIndex(final OpenshiftRequestContext context, Client esClient) {
try {
String userIndex = context.getKibanaIndex();
boolean kibanaIndexExists = pluginClient.indexExists(userIndex);
LOGGER.debug("Kibana index '{}' exists? {}", userIndex, kibanaIndexExists);
// copy the defaults if the userindex is not the kibanaindex
if (!kibanaIndexExists && !defaultKibanaIndex.equals(userIndex)) {
LOGGER.debug("Copying '{}' to '{}'", defaultKibanaIndex, userIndex);
GetIndexRequest getRequest = new GetIndexRequest().indices(defaultKibanaIndex);
getRequest.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
GetIndexResponse getResponse = esClient.admin().indices().getIndex(getRequest).get();
CreateIndexRequest createRequest = new CreateIndexRequest().index(userIndex);
createRequest.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
createRequest.settings(getResponse.settings().get(defaultKibanaIndex));
Map<String, Object> configMapping = getResponse.mappings().get(defaultKibanaIndex).get("config")
.getSourceAsMap();
createRequest.mapping("config", configMapping);
esClient.admin().indices().create(createRequest).actionGet();
// Wait for health status of YELLOW
ClusterHealthRequest healthRequest = new ClusterHealthRequest().indices(new String[] { userIndex })
.waitForYellowStatus();
esClient.admin().cluster().health(healthRequest).actionGet().getStatus();
return true;
}
} catch (ExecutionException | InterruptedException | IOException e) {
LOGGER.error("Unable to create initial Kibana index", e);
}
return false;
}