org.elasticsearch.client.IndicesAdminClient Java Examples
The following examples show how to use
org.elasticsearch.client.IndicesAdminClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SetupDao.java From usergrid with Apache License 2.0 | 7 votes |
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException { String key; CreateIndexResponse ciResp; Reflections reflections = new Reflections("org.apache.usergrid.chop.webapp.dao"); Set<Class<? extends Dao>> daoClasses = reflections.getSubTypesOf(Dao.class); IndicesAdminClient client = elasticSearchClient.getClient().admin().indices(); for (Class<? extends Dao> daoClass : daoClasses) { key = daoClass.getDeclaredField("DAO_INDEX_KEY").get(null).toString(); if (!client.exists(new IndicesExistsRequest(key)).actionGet().isExists()) { ciResp = client.create(new CreateIndexRequest(key)).actionGet(); if (ciResp.isAcknowledged()) { LOG.debug("Index for key {} didn't exist, now created", key); } else { LOG.debug("Could not create index for key: {}", key); } } else { LOG.debug("Key {} already exists", key); } } }
Example #2
Source File: UpdateMappingFieldDemo.java From javabase with Apache License 2.0 | 6 votes |
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); } }
Example #3
Source File: Elasticsearch.java From baleen with Apache License 2.0 | 6 votes |
private void setMapping(final String index) throws IOException { // Create index (if needed) final IndicesAdminClient indices = esResource.getClient().admin().indices(); if (!indices.exists(Requests.indicesExistsRequest(index)).actionGet().isExists()) { // We must submit all the mappings at once for parent child indices .prepareCreate(index) .addMapping(documentType, createDocumentMapping(XContentFactory.jsonBuilder())) .addMapping(mentionType, createMentionMapping(XContentFactory.jsonBuilder())) .addMapping(entityType, createEntityMapping(XContentFactory.jsonBuilder())) .addMapping(relationType, createRelationMapping(XContentFactory.jsonBuilder())) .execute() .actionGet(); } }
Example #4
Source File: ElasticToMongoProvider.java From mongolastic with MIT License | 6 votes |
@Override public long getCount() { long count = 0; IndicesAdminClient admin = elastic.getClient().admin().indices(); IndicesExistsRequestBuilder builder = admin.prepareExists(config.getMisc().getDindex().getName()); if (builder.execute().actionGet().isExists()) { SearchResponse countResponse = elastic.getClient().prepareSearch(config.getMisc().getDindex().getName()) .setTypes(config.getMisc().getCtype().getName()) .setSearchType(SearchType.QUERY_THEN_FETCH) .setSize(0) .execute().actionGet(); count = countResponse.getHits().getTotalHits(); } else { logger.info("Index/Type does not exist or does not contain the record"); System.exit(-1); } logger.info("Elastic Index/Type count: " + count); return count; }
Example #5
Source File: ElasticsearchClient.java From hawkular-apm with Apache License 2.0 | 6 votes |
/** * Removes all data associated with tenant. * * @param tenantId index */ public void clearTenant(String tenantId) { String index = getIndex(tenantId); synchronized (knownIndices) { IndicesAdminClient indices = client.admin().indices(); boolean indexExists = indices.prepareExists(index) .execute() .actionGet() .isExists(); if (indexExists) { indices.prepareDelete(index) .execute() .actionGet(); } knownIndices.remove(index); } }
Example #6
Source File: ElasticsearchTestUtils.java From components with Apache License 2.0 | 6 votes |
/** * Deletes an index and block until deletion is complete. * * @param index The index to delete * @param client The client which points to the Elasticsearch instance * @throws InterruptedException if blocking thread is interrupted or index existence check failed * @throws java.util.concurrent.ExecutionException if index existence check failed * @throws IOException if deletion failed */ static void deleteIndex(String index, Client client) throws InterruptedException, java.util.concurrent.ExecutionException, IOException { IndicesAdminClient indices = client.admin().indices(); IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get(); if (indicesExistsResponse.isExists()) { indices.prepareClose(index).get(); // delete index is an asynchronous request, neither refresh or upgrade // delete all docs before starting tests. WaitForYellow() and delete directory are too slow, // so block thread until it is done (make it synchronous!!!) AtomicBoolean indexDeleted = new AtomicBoolean(false); AtomicBoolean waitForIndexDeletion = new AtomicBoolean(true); indices.delete( Requests.deleteIndexRequest(index), new DeleteActionListener(indexDeleted, waitForIndexDeletion)); while (waitForIndexDeletion.get()) { Thread.sleep(100); } if (!indexDeleted.get()) { throw new IOException("Failed to delete index " + index); } } }
Example #7
Source File: AnalyzeHelper.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 获取当前有效的索引名 * * @return */ public static String getCurrentValidIndex() { IndexType indexType = IndexType.RESOURCES; if (indexName != null) { if (reLoad) { synchronized (AnalyzeHelper.class) { if (reLoad) { reLoad = false; indexName = indexName.equals(indexType.index_type_1()) ? indexType .index_type_2() : indexType.index_type_1(); } } } return indexName; } IndicesAdminClient adminClient = ESClient.getClient().admin().indices(); if (adminClient.prepareExists(indexType.index_type_1()).execute().actionGet().isExists()) { indexName = indexType.index_type_1(); } else if (adminClient.prepareExists(indexType.index_type_2()).execute().actionGet() .isExists()) { indexName = indexType.index_type_2(); } return indexName; }
Example #8
Source File: UpgradeUtil.java From fess with Apache License 2.0 | 6 votes |
public static boolean addFieldMapping(final IndicesAdminClient indicesClient, final String index, final String type, final String field, final String source) { final GetFieldMappingsResponse gfmResponse = indicesClient.prepareGetFieldMappings(index).addTypes(type).setFields(field).execute().actionGet(); final FieldMappingMetadata fieldMappings = gfmResponse.fieldMappings(index, type, field); if (fieldMappings == null || fieldMappings.isNull()) { try { final AcknowledgedResponse pmResponse = indicesClient.preparePutMapping(index).setSource(source, XContentType.JSON).execute().actionGet(); if (!pmResponse.isAcknowledged()) { logger.warn("Failed to add {} to {}/{}", field, index, type); } else { return true; } } catch (final Exception e) { logger.warn("Failed to add " + field + " to " + index + "/" + type, e); } } return false; }
Example #9
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * 索引 别名 就像一个快捷方式或软连接,可以指向一个或多个索引,也可以给任何需要索引名的 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); }
Example #10
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * 索引的相关操作 * * @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); }
Example #11
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * 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); }
Example #12
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * 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); }
Example #13
Source File: UpdateMappingFieldDemo.java From javabase with Apache License 2.0 | 6 votes |
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()); } }
Example #14
Source File: UpdateMappingFieldDemo.java From javabase with Apache License 2.0 | 6 votes |
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()); } }
Example #15
Source File: BulkIndexEsTest.java From elastic-crud with Apache License 2.0 | 6 votes |
@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); }
Example #16
Source File: UpgradeUtil.java From fess with Apache License 2.0 | 5 votes |
public static void deleteIndex(final IndicesAdminClient indicesClient, final String index, final Consumer<AcknowledgedResponse> comsumer) { indicesClient.prepareDelete(index).execute(new ActionListener<AcknowledgedResponse>() { @Override public void onResponse(final AcknowledgedResponse response) { logger.info("Deleted {} index.", index); comsumer.accept(response); } @Override public void onFailure(final Exception e) { logger.warn("Failed to delete " + index + " index.", e); } }); }
Example #17
Source File: ESUtil.java From ns4_gear_watchdog with Apache License 2.0 | 5 votes |
/** * 不存在就创建索引 * */ public boolean createIndexIfNotExist(String index, String type) { IndicesAdminClient adminClient = client.admin().indices(); IndicesExistsRequest request = new IndicesExistsRequest(index); IndicesExistsResponse response = adminClient.exists(request).actionGet(); if (!response.isExists()) { return createIndex(index, type); } return true; }
Example #18
Source File: TestMongoToElastic.java From mongolastic with MIT License | 5 votes |
public long getCount(ElasticConfiguration elastic, YamlConfiguration config) { IndicesAdminClient admin = elastic.getClient().admin().indices(); IndicesExistsRequestBuilder builder = admin.prepareExists(config.getMisc().getDindex().getAs()); assertThat(builder.execute().actionGet().isExists(), is(true)); elastic.getClient().admin().indices().flush(new FlushRequest(config.getMisc().getDindex().getAs())).actionGet(); SearchResponse response = elastic.getClient().prepareSearch(config.getMisc().getDindex().getAs()) .setTypes(config.getMisc().getCtype().getAs()) .setSearchType(SearchType.QUERY_THEN_FETCH) .setSize(0) .execute().actionGet(); long count = response.getHits().getTotalHits(); return count; }
Example #19
Source File: ElasticBulkService.java From mongolastic with MIT License | 5 votes |
@Override public void dropDataSet() { final String indexName = config.getMisc().getDindex().getAs(); IndicesAdminClient admin = client.getClient().admin().indices(); IndicesExistsRequestBuilder builder = admin.prepareExists(indexName); if (builder.execute().actionGet().isExists()) { DeleteIndexResponse delete = admin.delete(new DeleteIndexRequest(indexName)).actionGet(); if (delete.isAcknowledged()) logger.info(String.format("The current index %s was deleted.", indexName)); else logger.info(String.format("The current index %s was not deleted.", indexName)); } }
Example #20
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #21
Source File: EmbeddedElasticsearchCluster.java From elasticsearch-reindex-tool with Apache License 2.0 | 5 votes |
public void recreateIndex(final String sourceIndex) { IndicesAdminClient indices = dataNode.client().admin().indices(); if (indices.prepareExists(sourceIndex).get().isExists()) { indices.prepareDelete(sourceIndex).get(); } indices.prepareCreate(sourceIndex).get(); }
Example #22
Source File: SearchIndexServiceImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void deleteIndex(final String indexName) { // make sure dangling requests don't resurrect this index flushBulkProcessors(); IndicesAdminClient indices = indicesAdminClient(); if (indices.prepareExists(indexName).execute().actionGet().isExists()) { indices.prepareDelete(indexName).execute().actionGet(); } }
Example #23
Source File: AdminUpgradeAction.java From fess with Apache License 2.0 | 5 votes |
private void upgradeFrom12_1() { final IndicesAdminClient indicesClient = fessEsClient.admin().indices(); UpgradeUtil.putMapping(indicesClient, "fess_log.search_log", "search_log", "{\"dynamic_templates\": [" + "{\"documents\": {\"path_match\": \"documents.*\",\"mapping\": {\"type\": \"keyword\"}}}"// + "]}"); UpgradeUtil.addFieldMapping(indicesClient, "fess_log.click_log", "click_log", "urlId", "{\"properties\":{\"urlId\":{\"type\":\"keyword\"}}}"); }
Example #24
Source File: AliasMonitorService.java From es-service-parent with Apache License 2.0 | 5 votes |
private void doService() { List<IndexType> indexs = IndexType.getAllIndex(); IndicesAdminClient adminClient = ESClient.getClient().admin().indices(); for (IndexType indexType : indexs) { String indexname = indexType.getIndexName().toLowerCase(); String lastIndexName = null; try { lastIndexName = updateLogger.getLastIndexName(indexType); } catch (Exception e) { e.printStackTrace(); } if (adminClient.prepareExists(indexType.index_type_1()).execute().actionGet() .isExists() && adminClient .aliasesExist( new GetAliasesRequest().indices(indexType.index_type_1()) .aliases(indexname)).actionGet().isExists()) { if (adminClient.prepareExists(indexType.index_type_2()).execute().actionGet() .isExists() && adminClient .aliasesExist( new GetAliasesRequest().indices(indexType.index_type_2()) .aliases(indexname)).actionGet().isExists()) { log.error("indexname:{},{} alias:{}", indexType.index_type_1(), indexType.index_type_2(), indexname); if (lastIndexName != null && indexType.index_type_1().equals(lastIndexName)) { adminClient.delete(new DeleteIndexRequest(indexType.index_type_2()));// 删除索引 } else { adminClient.delete(new DeleteIndexRequest(indexType.index_type_1()));// 删除索引 } } } } }
Example #25
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #26
Source File: AdminUpgradeAction.java From fess with Apache License 2.0 | 5 votes |
private void upgradeFrom12_6() { final IndicesAdminClient indicesClient = fessEsClient.admin().indices(); UpgradeUtil.deleteIndex(indicesClient, ".fess_config.web_config_to_role", res -> {}); UpgradeUtil.deleteIndex(indicesClient, ".fess_config.file_config_to_role", res -> {}); UpgradeUtil.deleteIndex(indicesClient, ".fess_config.data_config_to_role", res -> {}); UpgradeUtil.addFieldMapping(indicesClient, "fess_log.search_log", "search_log", "hitCountRelation", "{\"properties\":{\"hitCountRelation\":{\"type\":\"keyword\"}}}"); }
Example #27
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #28
Source File: BulkIndexEsTest.java From elastic-crud with Apache License 2.0 | 5 votes |
@After public void after() { final IndicesAdminClient indices = client.admin().indices(); if(indices.prepareExists(INDEX).execute().actionGet().isExists()) { indices.prepareDelete(INDEX).execute().actionGet(); } }
Example #29
Source File: KPIDataLoader.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
/** * Checks if KPI's elasticsearch Index and Type exists */ public KPIDataLoader assertESTypesExists() { final IndicesAdminClient admin = elasticsearchClient.admin() .indices(); // // Check index exists final String esSearchIndex = kpi.getESSearchIndex(); final GetIndexResponse indexResponse = admin.prepareGetIndex() .addIndices(esSearchIndex) .get(); final List<String> indexesFound = Arrays.asList(indexResponse.getIndices()); if (!indexesFound.contains(esSearchIndex)) { throw new AdempiereException("ES index '" + esSearchIndex + "' not found in " + indexesFound); } logger.debug("Indexes found: {}", indexesFound); // // Check type exists final String esTypes = kpi.getESSearchTypes(); final boolean esTypesExists = admin.prepareTypesExists(esSearchIndex) .setTypes(kpi.getESSearchTypes()) .get() .isExists(); if (!esTypesExists) { throw new AdempiereException("Elasticseatch types " + esTypes + " does not exist"); } // All good return this; }
Example #30
Source File: CrudDemo.java From javabase with Apache License 2.0 | 5 votes |
private static void showAnaylzerText(IndicesAdminClient indicesAdminClient,String analyzerName, String text) { AnalyzeResponse analyzeResponse = indicesAdminClient.analyze(new AnalyzeRequest(INDEX_NAME).analyzer(analyzerName).text(text)).actionGet(); List<AnalyzeResponse.AnalyzeToken> token=analyzeResponse.getTokens(); for (AnalyzeResponse.AnalyzeToken analyzeToken : token) { log.info(analyzerName+": {}",analyzeToken.getTerm()); } }