當前位置: 首頁>>代碼示例>>Java>>正文


Java CreateIndexRequest.settings方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:thiguetta,項目名稱:elastikjay,代碼行數:24,代碼來源:IndexManagerImpl.java

示例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));
}
 
開發者ID:yakaz,項目名稱:elasticsearch-analysis-worddelimiter2,代碼行數:18,代碼來源:BaseESTest.java

示例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();
}
 
開發者ID:Flipkart,項目名稱:foxtrot,代碼行數:28,代碼來源:DistributedTableMetadataManagerTest.java

示例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;
}
 
開發者ID:szwork2013,項目名稱:elasticsearch-sentiment,代碼行數:30,代碼來源:BaseIngestTransportClient.java

示例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;
}
 
開發者ID:szwork2013,項目名稱:elasticsearch-sentiment,代碼行數:32,代碼來源:BulkNodeClient.java

示例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());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:49,代碼來源:TransportShrinkAction.java

示例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;
    }
 
開發者ID:fabric8io,項目名稱:openshift-elasticsearch-plugin,代碼行數:42,代碼來源:KibanaSeed.java


注:本文中的org.elasticsearch.action.admin.indices.create.CreateIndexRequest.settings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。