org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest.
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: TableCreator.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * if some orphaned partition with the same table name still exist, * delete them beforehand as they would create unwanted and maybe invalid * initial data. * * should never delete partitions of existing partitioned tables */ private void deleteOrphanedPartitions(final CreateTableResponseListener listener, TableIdent tableIdent) { String partitionWildCard = PartitionName.templateName(tableIdent.schema(), tableIdent.name()) + "*"; String[] orphans = indexNameExpressionResolver.concreteIndices(clusterService.state(), IndicesOptions.strictExpand(), partitionWildCard); if (orphans.length > 0) { if (logger.isDebugEnabled()) { logger.debug("Deleting orphaned partitions: {}", Joiner.on(", ").join(orphans)); } transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(orphans), new ActionListener<DeleteIndexResponse>() { @Override public void onResponse(DeleteIndexResponse response) { if (!response.isAcknowledged()) { warnNotAcknowledged("deleting orphans"); } listener.onResponse(SUCCESS_RESULT); } @Override public void onFailure(Throwable e) { listener.onFailure(e); } }); } else { listener.onResponse(SUCCESS_RESULT); } }
Example #2
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 #3
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 #4
Source File: TableCreator.java From Elasticsearch with Apache License 2.0 | 6 votes |
private void deleteOrphans(final CreateTableResponseListener listener, final CreateTableAnalyzedStatement statement) { if (clusterService.state().metaData().hasAlias(statement.tableIdent().fqn()) && PartitionName.isPartition( clusterService.state().metaData().getAliasAndIndexLookup().get(statement.tableIdent().fqn()).getIndices().iterator().next().getIndex())) { logger.debug("Deleting orphaned partitions with alias: {}", statement.tableIdent().fqn()); transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(statement.tableIdent().fqn()), new ActionListener<DeleteIndexResponse>() { @Override public void onResponse(DeleteIndexResponse response) { if (!response.isAcknowledged()) { warnNotAcknowledged("deleting orphaned alias"); } deleteOrphanedPartitions(listener, statement.tableIdent()); } @Override public void onFailure(Throwable e) { listener.onFailure(e); } }); } else { deleteOrphanedPartitions(listener, statement.tableIdent()); } }
Example #5
Source File: TwitterHistoryElasticsearchIT.java From streams with Apache License 2.0 | 6 votes |
@BeforeClass public void prepareTest() throws Exception { testConfiguration = new StreamsConfigurator<>(TwitterHistoryElasticsearchConfiguration.class).detectCustomConfiguration(); testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED); IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); if(indicesExistsResponse.isExists()) { DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex()); DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); assertTrue(deleteIndexResponse.isAcknowledged()); }; }
Example #6
Source File: HdfsElasticsearchIT.java From streams with Apache License 2.0 | 6 votes |
@BeforeClass public void prepareTest() throws Exception { testConfiguration = new StreamsConfigurator<>(HdfsElasticsearchConfiguration.class).detectCustomConfiguration("HdfsElasticsearchIT"); testClient = ElasticsearchClientManager.getInstance(testConfiguration.getDestination()).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED); IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); if(indicesExistsResponse.isExists()) { DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getDestination().getIndex()); DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); assertTrue(deleteIndexResponse.isAcknowledged()); }; }
Example #7
Source File: IndexController.java From blog-sample with Apache License 2.0 | 6 votes |
/** * 删除索引 * @param index 索引名 * @author jitwxs * @since 2018/10/9 15:08 */ @DeleteMapping("/index/delete/{index}") public ResultBean deleteIndex(@PathVariable String index) { if (StringUtils.isBlank(index)) { return ResultBean.error("参数错误,索引为空!"); } try { // 删除索引 DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(index); DeleteIndexResponse response = transportClient.admin().indices().delete(deleteIndexRequest).get(); logger.info("删除索引结果:{}",response.isAcknowledged()); return ResultBean.success("删除索引成功!"); } catch (Exception e) { logger.error("删除索引失败!要删除的索引为{},异常为:",index,e.getMessage(),e); return ResultBean.error("删除索引失败!"); } }
Example #8
Source File: DeleteAllPartitions.java From crate with Apache License 2.0 | 6 votes |
@Override public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) { if (partitions.isEmpty()) { consumer.accept(InMemoryBatchIterator.of(new Row1(0L), SentinelRow.SENTINEL), null); } else { /* * table is partitioned, in case of concurrent "delete from partitions" * it could be that some partitions are already deleted, * so ignore it if some are missing */ DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(partitions().toArray(new String[0])) .indicesOptions(IndicesOptions.lenientExpandOpen()); executor.transportActionProvider().transportDeleteIndexAction().execute( deleteIndexRequest, new OneRowActionListener<>(consumer, r -> Row1.ROW_COUNT_UNKNOWN) ); } }
Example #9
Source File: TestElasticSearchDAOV5.java From conductor with Apache License 2.0 | 6 votes |
private void deleteAllIndices() { ImmutableOpenMap<String, IndexMetaData> indices = elasticSearchClient.admin().cluster() .prepareState().get().getState() .getMetaData().getIndices(); indices.forEach(cursor -> { try { elasticSearchClient.admin() .indices() .delete(new DeleteIndexRequest(cursor.value.getIndex().getName())) .get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }); }
Example #10
Source File: ElasticsearchPersistWriterIT.java From streams with Apache License 2.0 | 6 votes |
@BeforeClass public void prepareTestPersistWriter() throws Exception { testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchPersistWriterIT"); testClient = ElasticsearchClientManager.getInstance(testConfiguration).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED); IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); if(indicesExistsResponse.isExists()) { DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex()); DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); assertTrue(deleteIndexResponse.isAcknowledged()); } }
Example #11
Source File: ElasticSearchPercolateTest.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
@After public void cleanup() throws IOException { try { DeleteIndexResponse delete = store.client.admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).actionGet(); if (!delete.isAcknowledged()) { logger.error("Index wasn't deleted"); } store.disconnect(); } catch (NoNodeAvailableException e) { //This indicates that elasticsearch is not running on a particular machine. //Silently ignore in this case. } }
Example #12
Source File: XmlPluginTest.java From elasticsearch-xml with Apache License 2.0 | 6 votes |
@Test public void testBigAndFatResponse() throws Exception { Client client = client("1"); for (int i = 0; i < 10000; i++) { client.index(new IndexRequest("test", "test", Integer.toString(i)) .source("{\"random\":\""+randomString(32)+ " " + randomString(32) + "\"}")).actionGet(); } client.admin().indices().refresh(new RefreshRequest("test")).actionGet(); InetSocketTransportAddress httpAddress = findHttpAddress(client); if (httpAddress == null) { throw new IllegalArgumentException("no HTTP address found"); } URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort()); URL url = new URL(base, "/test/test/_search?xml&pretty&size=10000"); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); int count = 0; String line; while ((line = reader.readLine()) != null) { count += line.length(); } assertTrue(count >= 2309156); reader.close(); client.admin().indices().delete(new DeleteIndexRequest("test")); }
Example #13
Source File: Elasticsearch5SearchIndex.java From vertexium with Apache License 2.0 | 6 votes |
@Override public void drop(Graph graph) { this.indexInfosLock.writeLock().lock(); try { if (this.indexInfos == null) { loadIndexInfos(); } Set<String> indexInfosSet = new HashSet<>(this.indexInfos.keySet()); for (String indexName : indexInfosSet) { try { DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indexName); getClient().admin().indices().delete(deleteRequest).actionGet(); } catch (Exception ex) { throw new VertexiumException("Could not delete index " + indexName, ex); } this.indexInfos.remove(indexName); initializeIndex(indexName); } } finally { this.indexInfosLock.writeLock().unlock(); } }
Example #14
Source File: IndexTransaction.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 删除索引 * * @param index_type */ public boolean deleteIndex(String index_type) { try { AdminClient adminClient = ESClient.getClient().admin(); if (adminClient.indices().prepareExists(index_type).execute().actionGet().isExists()) { ESClient.getClient().admin().indices().delete(new DeleteIndexRequest(index_type)); } if (adminClient.indices().prepareExists(index_type + "_1").execute().actionGet() .isExists()) { ESClient.getClient().admin().indices() .delete(new DeleteIndexRequest(index_type + "_1")); } if (adminClient.indices().prepareExists(index_type + "_2").execute().actionGet() .isExists()) { ESClient.getClient().admin().indices() .delete(new DeleteIndexRequest(index_type + "_2")); } return true; } catch (Exception e) { log.error("delete index fail,indexname:{}", index_type); } return false; }
Example #15
Source File: ElasticsearchInterpreterTest.java From zeppelin with Apache License 2.0 | 6 votes |
@AfterClass public static void clean() { if (transportInterpreter != null) { transportInterpreter.close(); } if (httpInterpreter != null) { httpInterpreter.close(); } if (elsClient != null) { elsClient.admin().indices().delete(new DeleteIndexRequest("*")).actionGet(); elsClient.close(); } if (elsNode != null) { elsNode.close(); } }
Example #16
Source File: ElasticsearchTestUtils.java From foxtrot with Apache License 2.0 | 5 votes |
public static void cleanupIndices(final ElasticsearchConnection elasticsearchConnection) { try { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("_all"); final DeleteIndexResponse deleteIndexResponse = elasticsearchConnection.getClient() .admin() .indices() .delete(deleteIndexRequest) .get(); log.info("Delete index response: {}", deleteIndexResponse); } catch (Exception e) { log.error("Index Cleanup failed", e); } }
Example #17
Source File: MockElasticsearchServer.java From foxtrot with Apache License 2.0 | 5 votes |
public void shutdown() throws IOException { node.client() .admin() .indices() .delete(new DeleteIndexRequest("table-meta")); node.close(); deleteDataDirectory(); }
Example #18
Source File: GCDangingArtifactsPlan.java From crate with Apache License 2.0 | 5 votes |
@Override public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) { OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L)); dependencies.transportActionProvider().transportDeleteIndexAction().execute( new DeleteIndexRequest(IndexParts.DANGLING_INDICES_PREFIX_PATTERNS.toArray(new String[0])), listener ); }
Example #19
Source File: ElasticsearchParentChildWriterIT.java From streams with Apache License 2.0 | 5 votes |
@BeforeClass public void prepareTestParentChildPersistWriter() throws Exception { testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchParentChildWriterIT"); testClient = ElasticsearchClientManager.getInstance(testConfiguration).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED); IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); if (indicesExistsResponse.isExists()) { DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex()); DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); assertTrue(deleteIndexResponse.isAcknowledged()); } PutIndexTemplateRequestBuilder putTemplateRequestBuilder = testClient.admin().indices().preparePutTemplate("mappings"); URL templateURL = ElasticsearchParentChildWriterIT.class.getResource("/ActivityChildObjectParent.json"); ObjectNode template = MAPPER.readValue(templateURL, ObjectNode.class); String templateSource = MAPPER.writeValueAsString(template); putTemplateRequestBuilder.setSource(templateSource); testClient.admin().indices().putTemplate(putTemplateRequestBuilder.request()).actionGet(); Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json")) .setScanners(new SubTypesScanner())); objectTypes = reflections.getSubTypesOf(ActivityObject.class); Path testdataDir = Paths.get("target/dependency/activitystreams-testdata"); files = Files.list(testdataDir).collect(Collectors.toList()); assert( files.size() > 0); }
Example #20
Source File: HadoopFormatIOElasticTest.java From beam with Apache License 2.0 | 5 votes |
/** Shutdown the embedded instance. */ static void shutdown() throws IOException { DeleteIndexRequest indexRequest = new DeleteIndexRequest(ELASTIC_INDEX_NAME); node.client().admin().indices().delete(indexRequest).actionGet(); LOG.info("Deleted index " + ELASTIC_INDEX_NAME + " from elastic in memory server"); node.close(); LOG.info("Closed elastic in memory server node."); deleteElasticDataDirectory(); }
Example #21
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
/** * removes any existing index and creates a new one */ protected void recreateIndex() { IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet(); if (response.isExists()) { client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet(); } // create index createIndex(); }
Example #22
Source File: ElasticSearchUtils.java From bdt with Apache License 2.0 | 5 votes |
/** * Drop an ES Index * * @param indexName * @return true if the index exists * @throws ElasticsearchException */ public boolean dropSingleIndex(String indexName) throws ElasticsearchException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName); try { this.client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT); } catch (IOException e) { throw new ElasticsearchException("Error dropping index: " + indexName); } return indexExists(indexName); }
Example #23
Source File: DeletePartitions.java From crate with Apache License 2.0 | 5 votes |
@Override public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) { ArrayList<String> indexNames = getIndices( plannerContext.transactionContext(), dependencies.functions(), params, subQueryResults); DeleteIndexRequest request = new DeleteIndexRequest(indexNames.toArray(new String[0])); request.indicesOptions(IndicesOptions.lenientExpandOpen()); dependencies.transportActionProvider().transportDeleteIndexAction() .execute(request, new OneRowActionListener<>(consumer, r -> Row1.ROW_COUNT_UNKNOWN)); }
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: ElasticsearchResource.java From newsleak with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a new elasticsearch index and adds a mapping for the document type. * Previously existing indexes will be removed. * * @throws Exception * the exception */ private void createIndex() throws Exception { boolean exists = client.admin().indices().prepareExists(mIndex).execute().actionGet().isExists(); // remove preexisting index if (exists) { logger.log(Level.INFO, "Preexisting index " + mIndex + " will be removed."); DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest(mIndex)) .actionGet(); if (deleteResponse.isAcknowledged()) { logger.log(Level.INFO, "Preexisting index " + mIndex + " successfully removed."); exists = false; } } // create schema mapping from file logger.log(Level.INFO, "Index " + mIndex + " will be created."); String docMapping = new String(Files.readAllBytes(Paths.get(documentMappingFile))); XContentBuilder builder = XContentFactory.jsonBuilder(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(docMapping.getBytes()); parser.close(); builder.copyCurrentStructure(parser); CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(mIndex); createIndexRequestBuilder.addMapping(DOCUMENT_TYPE, builder); createIndexRequestBuilder.execute().actionGet(); }
Example #26
Source File: ElasticIndexManager.java From cicada with MIT License | 5 votes |
/** * 删除elastic search中超过保存期限的索引. */ public void removeExpireIndice() { final List<String> expireIndice = getExpireIndice(); for (final String index : expireIndice) { client.admin().indices().delete(new DeleteIndexRequest(index)).actionGet(); } }
Example #27
Source File: ElasticsearchRule.java From datashare with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void after() { try { client.indices().delete(new DeleteIndexRequest(indexName), RequestOptions.DEFAULT); client.close(); } catch (IOException e) { printStackTrace(e); } }
Example #28
Source File: AlterTableOperation.java From crate with Apache License 2.0 | 5 votes |
private CompletableFuture<Long> deleteIndex(String... indexNames) { DeleteIndexRequest request = new DeleteIndexRequest(indexNames); FutureActionListener<AcknowledgedResponse, Long> listener = new FutureActionListener<>(r -> 0L); transportDeleteIndexAction.execute(request, listener); return listener; }
Example #29
Source File: DeletePlanner.java From crate with Apache License 2.0 | 5 votes |
@Override public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) { WhereClause where = detailedQuery.toBoundWhereClause( table.tableInfo(), executor.functions(), params, subQueryResults, plannerContext.transactionContext() ); if (!where.partitions().isEmpty() && !where.hasQuery()) { DeleteIndexRequest request = new DeleteIndexRequest(where.partitions().toArray(new String[0])); request.indicesOptions(IndicesOptions.lenientExpandOpen()); executor.transportActionProvider().transportDeleteIndexAction() .execute(request, new OneRowActionListener<>(consumer, o -> new Row1(-1L))); return; } ExecutionPlan executionPlan = deleteByQuery(table, plannerContext, where); NodeOperationTree nodeOpTree = NodeOperationTreeGenerator.fromPlan(executionPlan, executor.localNodeId()); executor.phasesTaskFactory() .create(plannerContext.jobId(), Collections.singletonList(nodeOpTree)) .execute(consumer, plannerContext.transactionContext()); }
Example #30
Source File: Postgres2ElasticsearchIndexer.java From newsleak with GNU Affero General Public License v3.0 | 5 votes |
/** * The main method. * * @param args * the arguments * @throws Exception * the exception */ public static void main(String[] args) throws Exception { Postgres2ElasticsearchIndexer indexer = new Postgres2ElasticsearchIndexer(); indexer.getConfiguration(args); indexer.initDb(indexer.dbName, indexer.dbUrl, indexer.dbUser, indexer.dbPass); indexer.setElasticsearchDefaultAnalyzer(indexer.defaultLanguage); TransportClient client; Settings settings = Settings.builder().put("cluster.name", indexer.esClustername).build(); st.setFetchSize(BATCH_SIZE); try { client = TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(indexer.esHost), Integer.parseInt(indexer.esPort))); // remove existing index client.admin().indices().delete(new DeleteIndexRequest(indexer.esIndex)).actionGet(); // create index with all extracted data indexer.documentIndexer(client, indexer.esIndex, "document"); } catch (Exception e) { e.printStackTrace(); System.exit(0); } conn.close(); }