本文整理汇总了Java中org.elasticsearch.action.admin.indices.create.CreateIndexRequest.settings方法的典型用法代码示例。如果您正苦于以下问题:Java CreateIndexRequest.settings方法的具体用法?Java CreateIndexRequest.settings怎么用?Java CreateIndexRequest.settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.indices.create.CreateIndexRequest
的用法示例。
在下文中一共展示了CreateIndexRequest.settings方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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));
}
示例3: setUp
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
HazelcastConnection hazelcastConnection = Mockito.mock(HazelcastConnection.class);
hazelcastInstance = new TestHazelcastInstanceFactory(1).newHazelcastInstance();
ObjectMapper mapper = new ObjectMapper();
mapper.registerSubtypes(GroupResponse.class);
when(hazelcastConnection.getHazelcast()).thenReturn(hazelcastInstance);
Config config = new Config();
when(hazelcastConnection.getHazelcastConfig()).thenReturn(config);
//Create index for table meta. Not created automatically
elasticsearchServer = new MockElasticsearchServer(UUID.randomUUID().toString());
CreateIndexRequest createRequest = new CreateIndexRequest(TableMapStore.TABLE_META_INDEX);
Settings indexSettings = ImmutableSettings.settingsBuilder().put("number_of_replicas", 0).build();
createRequest.settings(indexSettings);
elasticsearchServer.getClient().admin().indices().create(createRequest).actionGet();
elasticsearchServer.getClient().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
ElasticsearchConnection elasticsearchConnection = Mockito.mock(ElasticsearchConnection.class);
when(elasticsearchConnection.getClient()).thenReturn(elasticsearchServer.getClient());
ElasticsearchUtils.initializeMappings(elasticsearchServer.getClient());
String DATA_MAP = "tablemetadatamap";
tableDataStore = hazelcastInstance.getMap(DATA_MAP);
distributedTableMetadataManager = new DistributedTableMetadataManager(hazelcastConnection,
elasticsearchConnection);
distributedTableMetadataManager.start();
}
示例4: 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;
}
示例5: 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;
}
示例6: prepareCreateIndexRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; //导入方法依赖的package包/类
static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest(final ShrinkRequest shrinkRequest, final ClusterState state
, final IntFunction<DocsStats> perShardDocStats, IndexNameExpressionResolver indexNameExpressionResolver) {
final String sourceIndex = indexNameExpressionResolver.resolveDateMathExpression(shrinkRequest.getSourceIndex());
final CreateIndexRequest targetIndex = shrinkRequest.getShrinkIndexRequest();
final String targetIndexName = indexNameExpressionResolver.resolveDateMathExpression(targetIndex.index());
final IndexMetaData metaData = state.metaData().index(sourceIndex);
final Settings targetIndexSettings = Settings.builder().put(targetIndex.settings())
.normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX).build();
int numShards = 1;
if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
numShards = IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings);
}
for (int i = 0; i < numShards; i++) {
Set<ShardId> shardIds = IndexMetaData.selectShrinkShards(i, metaData, numShards);
long count = 0;
for (ShardId id : shardIds) {
DocsStats docsStats = perShardDocStats.apply(id.id());
if (docsStats != null) {
count += docsStats.getCount();
}
if (count > IndexWriter.MAX_DOCS) {
throw new IllegalStateException("Can't merge index with more than [" + IndexWriter.MAX_DOCS
+ "] docs - too many documents in shards " + shardIds);
}
}
}
if (IndexMetaData.INDEX_ROUTING_PARTITION_SIZE_SETTING.exists(targetIndexSettings)) {
throw new IllegalArgumentException("cannot provide a routing partition size value when shrinking an index");
}
targetIndex.cause("shrink_index");
Settings.Builder settingsBuilder = Settings.builder().put(targetIndexSettings);
settingsBuilder.put("index.number_of_shards", numShards);
targetIndex.settings(settingsBuilder);
return new CreateIndexClusterStateUpdateRequest(targetIndex,
"shrink_index", targetIndex.index(), targetIndexName, true)
// mappings are updated on the node when merging in the shards, this prevents race-conditions since all mapping must be
// applied once we took the snapshot and if somebody fucks things up and switches the index read/write and adds docs we miss
// the mappings for everything is corrupted and hard to debug
.ackTimeout(targetIndex.timeout())
.masterNodeTimeout(targetIndex.masterNodeTimeout())
.settings(targetIndex.settings())
.aliases(targetIndex.aliases())
.customs(targetIndex.customs())
.waitForActiveShards(targetIndex.waitForActiveShards())
.shrinkFrom(metaData.getIndex());
}
示例7: 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;
}