当前位置: 首页>>代码示例>>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;未经允许,请勿转载。