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


Java IndicesAdminClient類代碼示例

本文整理匯總了Java中org.elasticsearch.client.IndicesAdminClient的典型用法代碼示例。如果您正苦於以下問題:Java IndicesAdminClient類的具體用法?Java IndicesAdminClient怎麽用?Java IndicesAdminClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IndicesAdminClient類屬於org.elasticsearch.client包,在下文中一共展示了IndicesAdminClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createChatsIndex

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的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);
}
 
開發者ID:korobi,項目名稱:ElasticMangos,代碼行數:26,代碼來源:IndexInitialiser.java

示例2: testCreateIndexWithoutSettings

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testCreateIndexWithoutSettings() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:24,代碼來源:ElasticsearchClientWrapperImplTest.java

示例3: testCreateIndex

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testCreateIndex() {
    // Test data
    final String indexName = "Index_Name";
    final Map<String, Object> settings = Collections.singletonMap("settings_key", "settings_value");
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.setSettings(settings)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName, settings);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例4: testRefreshIndex

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testRefreshIndex() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final RefreshRequestBuilder refreshRequestBuilder = createMock(RefreshRequestBuilder.class);
    final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareRefresh(indexName)).andReturn(refreshRequestBuilder);
    expect(refreshRequestBuilder.get()).andReturn(createMock(RefreshResponse.class));
    // Replay
    replayAll();
    // Run test scenario
    elasticsearchClientWrapper.refreshIndex(indexName);
    // Verify
    verifyAll();
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:23,代碼來源:ElasticsearchClientWrapperImplTest.java

示例5: testAddAlias

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testAddAlias() {
    //Test data
    final String indexName = "index";
    final String aliasName = "alias";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesAliasesRequestBuilder indicesAliasesRequestBuilder = createMock(IndicesAliasesRequestBuilder.class);
    final IndicesAliasesResponse indicesAliasesResponse = createMock(IndicesAliasesResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareAliases()).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.addAlias(indexName, aliasName)).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.get()).andReturn(indicesAliasesResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.addAlias(indexName, aliasName);
    //Verify
    verifyAll();
    assertEquals(indicesAliasesResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例6: testDeleteIndex

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testDeleteIndex() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final DeleteIndexRequestBuilder deleteIndexRequestBuilder = createMock(DeleteIndexRequestBuilder.class);
    final DeleteIndexResponse deleteIndexResponse = createMock(DeleteIndexResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareDelete(indexName)).andReturn(deleteIndexRequestBuilder);
    expect(deleteIndexRequestBuilder.get()).andReturn(deleteIndexResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.deleteIndex(indexName);
    //Verify
    verifyAll();
    assertEquals(deleteIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:24,代碼來源:ElasticsearchClientWrapperImplTest.java

示例7: testIndexExists

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Test
public void testIndexExists() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesExistsRequestBuilder indicesExistsRequestBuilder = createMock(IndicesExistsRequestBuilder.class);
    final IndicesExistsResponse indicesExistsResponse = createMock(IndicesExistsResponse.class);
    final boolean exists = new Random().nextBoolean();
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareExists(indexName)).andReturn(indicesExistsRequestBuilder);
    expect(indicesExistsRequestBuilder.get()).andReturn(indicesExistsResponse);
    expect(indicesExistsResponse.isExists()).andReturn(exists);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.indexExists(indexName);
    //Verify
    verifyAll();
    assertEquals(exists, result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例8: before

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
@Before
public void before() throws IOException {
  final IndicesAdminClient indices = client.admin().indices();
  if(!indices.prepareExists(INDEX).execute().actionGet().isExists()) {
    indices.prepareCreate(INDEX).execute().actionGet();
  }
  final JsonSerializer<Person> serializer = mapper.serializer(Person.class);
  final BulkRequestBuilder bulk = client.prepareBulk();
  for (int i = 0; i < SIZE; i++) {

    final String name = UUID.randomUUID().toString();
    final IndexRequest request = new IndexRequest(INDEX, TYPE);
    request.source(serializer.apply(Person.builder().id("").firstname(name).lastname(name).build()), JSON);
    bulk.add(request);
  }

  client.bulk(bulk.request()).actionGet();
  flush(INDEX);
}
 
開發者ID:jloisel,項目名稱:elastic-crud,代碼行數:20,代碼來源:BulkIndexEsTest.java

示例9: update

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
private static void update() {
    try {
        IndicesAdminClient indicesAdminClient = client.admin().indices();
        if (indicesAdminClient.prepareExists(INDEX_NAME_v2).execute().actionGet().isExists()) {
            indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v2)).actionGet();
        }
        indicesAdminClient.prepareCreate(INDEX_NAME_v2).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet();
        //等待集群shard,防止No shard available for 異常
        ClusterAdminClient clusterAdminClient = client.admin().cluster();
        clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000);
        //0、更新mapping
        updateMapping();
        //1、更新數據
        reindexData(indicesAdminClient);

        //2、realias 重新建立連接
       indicesAdminClient.prepareAliases().removeAlias(INDEX_NAME_v1, ALIX_NAME).addAlias(INDEX_NAME_v2, ALIX_NAME).execute().actionGet();
    }catch (Exception e){
        log.error("beforeUpdate error:{}"+e.getLocalizedMessage());
    }

}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:23,代碼來源:UpdateMappingFieldDemo.java

示例10: prepareData

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
private static void prepareData(IndicesAdminClient indicesAdminClient) throws InterruptedException {
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    //批量添加
    for (int i = 0; i < 1000; i++) {
        ItemInfo iteminfo=new ItemInfo(i,"商品"+i, new Random().nextFloat(),new Date());
        // 當opType是Index時,如果文檔id存在,更新文檔,否則創建文檔 當opType是Create,如果文檔id存在,拋出文檔存在的錯誤 *
        IndexRequestBuilder indexRequestBuilder = client.prepareIndex(INDEX_NAME_v1, INDEX_TYPE).setId(i+"").setSource(JSONObject.toJSONString(iteminfo)).setOpType(IndexRequest.OpType.INDEX);
        bulkRequestBuilder.add(indexRequestBuilder);
        //數據日期不一樣
    }
    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
    if (bulkResponse.hasFailures()) {
     log.error("bulk index error:{}",bulkResponse.buildFailureMessage());
    } else {
        log.info("index docs : {}" , bulkResponse);
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:18,代碼來源:UpdateMappingFieldDemo.java

示例11: beforeUpdate

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
private static void beforeUpdate()  {
    try {
        IndicesAdminClient indicesAdminClient = client.admin().indices();
        indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v1)).actionGet();
        if (!indicesAdminClient.prepareExists(INDEX_NAME_v1).execute().actionGet().isExists()) {
            indicesAdminClient.prepareCreate(INDEX_NAME_v1).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet();
        }
        //等待集群shard,防止No shard available for 異常
        ClusterAdminClient clusterAdminClient = client.admin().cluster();
        clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000);
        //創建別名alias
        indicesAdminClient.prepareAliases().addAlias(INDEX_NAME_v1, ALIX_NAME).execute().actionGet();
        prepareData(indicesAdminClient);
    }catch (Exception e){
        log.error("beforeUpdate error:{}"+e.getLocalizedMessage());
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:18,代碼來源:UpdateMappingFieldDemo.java

示例12: analyze

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
/**
 * ttp://localhost:9200/index/_analyze?text=做人如果沒有夢想那和鹹魚有什麽區別勒&analyzer=pinyin_analyzer
 * ttp://localhost:9200/index/_analyze?text=今天是個好天氣啊&analyzer=ik_max_word
 */
private static void analyze() {
    IndicesAdminClient indicesAdminClient = client.admin().indices();
    String analyzerName="pinyin";
    String text="默認的拚音例子";
    showAnaylzerText(indicesAdminClient,analyzerName,text);
    //自定義分析器必須要指定indexName,插件的就不用了
     analyzerName="pinyin_analyzer";
    text="做人如果沒有夢想那和鹹魚有什麽區別勒";
    showAnaylzerText(indicesAdminClient,analyzerName,text);
    //官網的demo例子
    analyzerName="my_analyzer";
    text="The quick & brown fox is a dog";
    showAnaylzerText(indicesAdminClient,analyzerName,text);
    //驗證ik分詞
    analyzerName="ik_max_word";
    text="好好學習天天向上!";
    showAnaylzerText(indicesAdminClient,analyzerName,text);
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:23,代碼來源:CrudDemo.java

示例13: index

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
/**
     * http://es.xiaoleilu.com/010_Intro/25_Tutorial_Indexing.html
     * http://es.xiaoleilu.com/070_Index_Mgmt/05_Create_Delete.html
     * 索引相關的
     */
    private static void index() throws IOException, InterruptedException {
        // cluster(),產生一個允許從集群中執行action或操作的client;
        IndicesAdminClient indicesAdminClient = client.admin().indices();
        //創建索引
        if (checkExistsIndex(indicesAdminClient, INDEX_NAME)) {
            deleteIndex(indicesAdminClient, INDEX_NAME);
        }
//        String settings = getIndexSetting();
//        CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings(settings).execute().actionGet();

        CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings().execute().actionGet();
//        log.info("創建索引{}:{}", INDEX_NAME, createIndexResponse.getContext());

        //索引的相關配置操作
        indexConfig(indicesAdminClient, INDEX_NAME);

//        indexMapping(indicesAdminClient, INDEX_NAME, TYPE_NAME);
    }
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:24,代碼來源:CrudDemo.java

示例14: indexConfig

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
/**
 * 索引的相關操作
 *
 * @param indicesAdminClient
 * @param indexName
 * @throws IOException
 */
private static void indexConfig(IndicesAdminClient indicesAdminClient, String indexName) throws IOException {
    //settings 設置
    String settings = getIndexSetting();
    // PUT /my_temp_index/_settings updatesettings
    showIndexSettings(indicesAdminClient,indexName);
    UpdateSettingsResponse updateSettingsResponse = indicesAdminClient.prepareUpdateSettings(indexName).setSettings(settings).execute().actionGet();
    log.info("更新 index setting:{}", updateSettingsResponse);


    //更新索引settings之前要關閉索引
    indicesAdminClient.close(new CloseIndexRequest().indices(indexName)).actionGet();
    //配置拚音自定義分析器
    indicesAdminClient.prepareUpdateSettings(indexName).setSettings(getIndexPinYinSetting()).execute().actionGet();
    //自定義分析器
    indicesAdminClient.prepareUpdateSettings(indexName).setSettings(getIndexDemoSetting()).execute().actionGet();
    //打開索引
    indicesAdminClient.open(new OpenIndexRequest().indices(indexName)).actionGet();

    //索引別名映射
    createAliasIndex(indicesAdminClient);

    showIndexSettings(indicesAdminClient,indexName);
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:31,代碼來源:CrudDemo.java

示例15: createAliasIndex

import org.elasticsearch.client.IndicesAdminClient; //導入依賴的package包/類
/**
     * 索引 別名 就像一個快捷方式或軟連接,可以指向一個或多個索引,也可以給任何需要索引名的 API 使用。別名帶給我們極大的靈活性,
     * 比如 我們線上使用一個索引名為index_a的結構,裏麵有一個類型現在不滿足要求,現在需要修改,因為elasticsearch不支持直接修改類型,所以我們必須要重新建立一個新的索引
     * 然後將久索引的數據拷貝過去。 但是如果讓新的索引起作用,我們需要要修改引用代碼,因為索引名稱更換了,但是如果我們一開始創建索引的時候就給索引增加一個別名
     * 使用的時候都是使用index_alis 無論軟連接的指向是什麽索引,對外暴露的始終都是index_alis
     * @param indicesAdminClient
     */
    private static void createAliasIndex(IndicesAdminClient indicesAdminClient) {
//        1 創建索引 elsdb_alis_v1。
//        2 將別名 elsdb_alis 指向 elsdb_alis_v1
//        3 然後,我們決定修改索引elsdb_alis_v1中一個字段的映射。當然我們不能修改現存的映射,索引我們需要重新索引數據。首先,我們創建有新的映射的索引 elsdb_alis_v2。
//        4 然後我們從將數據從 elsdb_alis_v1 遷移到 elsdb_alis_v2,下麵的過程在【重新索引】中描述過了。一旦我們認為數據已經被正確的索引了,我們就將別名指向新的索引。


        //創建索引
        if (checkExistsIndex(indicesAdminClient, INDEX_ALIAS_NAME_VERSION_ONE)) {
            deleteIndex(indicesAdminClient, INDEX_ALIAS_NAME_VERSION_ONE);
        }

        indicesAdminClient.prepareCreate(INDEX_ALIAS_NAME_VERSION_ONE).setSettings().execute().actionGet();
        //添加alias 所有別名
        indicesAdminClient.prepareAliases().addAlias(INDEX_ALIAS_NAME_VERSION_ONE,INDEX_ALIAS_NAME_ALIS).execute().actionGet();

        GetAliasesResponse getAliasesResponse = indicesAdminClient.getAliases(new GetAliasesRequest().indices(INDEX_ALIAS_NAME_ALIS)).actionGet();
        //log.info("getAliasesResponse index setting:{}", getAliasesResponse.getAliases());

        indicesAdminClient.prepareAliases().removeAlias(INDEX_ALIAS_NAME_VERSION_ONE,INDEX_ALIAS_NAME_ALIS).addAlias(INDEX_ALIAS_NAME_VERSION_TWO,INDEX_ALIAS_NAME_ALIS);
    }
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:29,代碼來源:CrudDemo.java


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