io.searchbox.indices.IndicesExists Java Examples
The following examples show how to use
io.searchbox.indices.IndicesExists.
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: AbstractClientFactory.java From apiman with Apache License 2.0 | 7 votes |
/** * Called to initialize the storage. * @param client the jest client * @param indexName the name of the ES index to initialize * @param defaultIndexName the default ES index - used to determine which -settings.json file to use */ protected void initializeClient(JestClient client, String indexName, String defaultIndexName) { try { client.execute(new Health.Builder().build()); Action<JestResult> action = new IndicesExists.Builder(indexName).build(); // There was occasions where a race occurred here when multiple threads try to // create the index simultaneously. This caused a non-fatal, but annoying, exception. synchronized(AbstractClientFactory.class) { JestResult result = client.execute(action); if (!result.isSucceeded()) { createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$ } } } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: ElasticSearchClient.java From vind with Apache License 2.0 | 5 votes |
public boolean init(String elasticHost, String elasticPort, String elasticIndex, String logType, Path processResultMappingFile) { this.elasticHost = elasticHost; this.elasticPort = elasticPort; this.elasticIndex = elasticIndex; this.logType = logType; try { final JestClient client = getElasticSearchClient(); boolean indexExists = client.execute(new IndicesExists.Builder(elasticIndex).build()).isSucceeded(); if (!indexExists){ log.info("Creating elasticsearch index."); client.execute(new CreateIndex.Builder(elasticIndex).build()); } if (StringUtils.isNotBlank(logType) && (processResultMappingFile != null)) { log.info("Updating type mapping."); final String mappingJson = new String(ByteStreams.toByteArray(Files.newInputStream(processResultMappingFile))); client.execute(new PutMapping.Builder(elasticIndex, logType, mappingJson).build()); } log.info("Established elasticsearch connection to host '{}:{}', index '{}'.", elasticHost, elasticPort, elasticIndex); elasticClient = client; } catch (IOException e) { log.error("Error creating base index on ElasticSearch: {}", e.getMessage(), e); elasticClient = null; } return true; }
Example #3
Source File: IndexManagerBean.java From eplmp with Eclipse Public License 1.0 | 5 votes |
private boolean indexExists(String indexName) throws IndexerNotAvailableException { IndicesExists indicesExistsRequest = new IndicesExists.Builder(indexName).build(); try { JestResult execute = esClient.execute(indicesExistsRequest); return execute.isSucceeded(); } catch (IOException e) { throw new IndexerNotAvailableException(); } }
Example #4
Source File: IndexFunctionsDaoImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public final boolean isIndexExists(String indexName) { Action action = new IndicesExists.Builder(indexName).build(); JestResult result = jestClientHelper.execute(action); return result.isSucceeded(); }
Example #5
Source File: SearchIndexingServiceImpl.java From bearchoke with Apache License 2.0 | 5 votes |
@PostConstruct public void init() throws Exception { log.info("Instantiating jestSearchIndexingService..."); log.info(String.format("Checking if %s needs to be created", LOCATION_INDEX_NAME)); IndicesExists indicesExists = new IndicesExists.Builder(LOCATION_INDEX_NAME).build(); JestResult r = jestClient.execute(indicesExists); if (!r.isSucceeded()) { log.info("Index does not exist. Creating index..."); // create new index (if u have this in elasticsearch.yml and prefer // those defaults, then leave this out ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); settings.put("number_of_shards", 1); settings.put("number_of_replicas", 0); CreateIndex.Builder builder = new CreateIndex.Builder(LOCATION_INDEX_NAME); builder.settings(settings.build().getAsMap()); CreateIndex createIndex = builder.build(); log.info(createIndex.toString()); jestClient.execute(createIndex); log.info("Index created"); } else { log.info("Index already exist!"); } }
Example #6
Source File: HttpESMetricsDispatcher.java From gradle-metrics-plugin with Apache License 2.0 | 4 votes |
@Override protected boolean exists(String indexName) { IndicesExists indicesExists = new IndicesExists.Builder(indexName).build(); JestResult result = execute(indicesExists, true); return result.getJsonObject().get("found").getAsBoolean(); }
Example #7
Source File: Jest.java From easy-sync with Apache License 2.0 | 3 votes |
public boolean indexExists(String indexName) throws IOException { AliasIndices aliasIndices = new AliasIndices(indexName); JestResult jestResult = jestClient.execute(aliasIndices); //because index and alias can not be the same, alias found , means index not exists if (jestResult.isSucceeded()) { return false; } else if (jestResult.getResponseCode() == 404) { } else { throw new IOException(jestResult.getResponseCode()+","+jestResult.getErrorMessage()); } jestResult = jestClient.execute(new IndicesExists.Builder(indexName).build()); if (jestResult.isSucceeded()) { return true; }else if(jestResult.getResponseCode()==404){ return false; }else{ throw new IOException(jestResult.getResponseCode()+","+jestResult.getErrorMessage()); } }