本文整理汇总了Java中io.searchbox.indices.IndicesExists类的典型用法代码示例。如果您正苦于以下问题:Java IndicesExists类的具体用法?Java IndicesExists怎么用?Java IndicesExists使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndicesExists类属于io.searchbox.indices包,在下文中一共展示了IndicesExists类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateIndex
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
public void validateIndex(String indexName) {
try {
IndicesExists indicesExistsRequest = new IndicesExists.Builder(indexName).build();
logger.debug("created indexExistsRequests: {}", indicesExistsRequest);
JestResult existsResult = client.execute(indicesExistsRequest);
logger.debug("indexExistsRequests result: {}", existsResult);
if (!existsResult.isSucceeded()) {
Settings settings = Settings.builder()
// .put("index.analysis.analyzer.default.type", "keyword")
.put("index.store.type", "mmapfs")
.build();
CreateIndex createIndexRequest = new CreateIndex.Builder(indexName).settings(settings).build();
execute(createIndexRequest);
//TODO: Make this work. Using the above "keyword" configuration in the meantime.
PutMapping putMapping = new PutMapping.Builder(indexName, "_default_", STRING_NOT_ANALYZED).build();
execute(putMapping);
logger.info("created index with settings: {}, indexName: {}, putMapping: {}", settings, indexName, putMapping);
}
} catch (IOException e) {
logger.error("failed to connect to elastic cluster", e);
}
}
示例2: createIndex
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@Override
public boolean createIndex() {
JestClient client = esrResource.getClient();
try{
JestResult result = client.execute(new IndicesExists.Builder(index).build());
if(result.getResponseCode() != 200){
client.execute(new CreateIndex.Builder(index).build());
return true;
}
}catch(IOException ioe){
getMonitor().error("Unable to create index", ioe);
}
return false;
}
示例3: deleteAll
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@Override
public void deleteAll() throws IOException {
// Delete the index, if it exists.
JestResult result = client.execute(new IndicesExists.Builder(indexName).build());
if (result.isSucceeded()) {
result = client.execute(new DeleteIndex.Builder(indexName).build());
if (!result.isSucceeded()) {
throw new IOException(
String.format("Failed to delete index %s: %s", indexName, result.getErrorMessage()));
}
}
// Recreate the index.
result = client.execute(new CreateIndex.Builder(indexName).settings(getMappings()).build());
if (!result.isSucceeded()) {
String error =
String.format("Failed to create index %s: %s", indexName, result.getErrorMessage());
throw new IOException(error);
}
}
示例4: builderIndex_OneRecord
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
public void builderIndex_OneRecord(String json, boolean cleanBeforeInsert) {
long start = System.currentTimeMillis();
try {
if (cleanBeforeInsert) {
jestHttpClient.execute(new DeleteIndex(new DeleteIndex.Builder(_esIndexName)));
}
JestResult jestResult = jestHttpClient.execute(new IndicesExists.Builder(_esIndexName).build());
if (!jestResult.isSucceeded()) {
jestHttpClient.execute(new CreateIndex.Builder(_esIndexName).build());
}
Index index = new Index.Builder(json)
.index(_esIndexName)
.type(_esTypeName)
.build();
jestHttpClient.execute(index);
// jestHttpClient.shutdownClient();
} catch (Exception e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
LOG.info("->> One Record(default id): time for create index --> " + (end - start) + " milliseconds");
}
示例5: builderIndex_Bulk
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
public void builderIndex_Bulk(List<Entity> entityList, boolean cleanBeforeInsert) {
int nRecords = entityList.size();
long start = System.currentTimeMillis();
try {
if (cleanBeforeInsert) {
jestHttpClient.execute(new DeleteIndex(new DeleteIndex.Builder(_esIndexName)));
}
JestResult jestResult = jestHttpClient.execute(new IndicesExists.Builder(_esIndexName).build());
if (!jestResult.isSucceeded()) {
jestHttpClient.execute(new CreateIndex.Builder(_esIndexName).build());
}
SerializeBeans2JSON sb2json = new SerializeBeans2JSON();
Bulk.Builder bulkBuilder = new Bulk.Builder();
for (int i = 0; i < nRecords; i++) {
Index index = new Index
.Builder(sb2json.serializeBeans2JSON(entityList.get(i)))
.index(_esIndexName)
.type(_esTypeName)
.id(entityList.get(i).getEntityID())
.build();
bulkBuilder.addAction(index);
}
jestHttpClient.execute(bulkBuilder.build());
} catch (Exception e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
LOG.info("->> Bulk: total time for create index --> " + (end - start) + " milliseconds, # of records: " + nRecords);
}
示例6: indexExists
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
private boolean indexExists(String index) {
Action action = new IndicesExists.Builder(index).build();
try {
JestResult result = client.execute(action);
return result.isSucceeded();
} catch (IOException e) {
throw new ConnectException(e);
}
}
示例7: isIndexExists
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@Override
public final boolean isIndexExists(String indexName)
{
Action action = new IndicesExists.Builder(indexName).build();
JestResult result = jestClientHelper.executeAction(action);
return result.isSucceeded();
}
示例8: createIndex
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
/**
* Create an index in Elasticsearch. If necessary, this function should
* check whether a new index is required.
*
* @return true if a new index has been created, false otherwise
*/
public boolean createIndex() {
JestClient client = esrResource.getClient();
try {
JestResult result = client.execute(new IndicesExists.Builder(index).build());
if (result.getResponseCode() != 200) {
client.execute(new CreateIndex.Builder(index).build());
return true;
}
} catch (IOException ioe) {
getMonitor().error("Unable to create index", ioe);
}
return false;
}
示例9: init
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@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!");
}
}
示例10: initialize
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
/**
* Called to initialize the storage.
*/
@Override
public void initialize() {
try {
esClient.execute(new Health.Builder().build());
// TODO Do we need a loop to wait for all nodes to join the cluster?
Action<JestResult> action = new IndicesExists.Builder(getIndexName()).build();
JestResult result = esClient.execute(action);
if (! result.isSucceeded()) {
createIndex(getIndexName());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: initializeClient
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
/**
* 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();
JestResult result = client.execute(action);
if (!result.isSucceeded()) {
createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: indexExists
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@Override
public boolean indexExists(String indexName) {
return executeWithAcknowledge(new IndicesExists.Builder(indexName).build());
}
示例13: exists
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
@Override
protected boolean exists(String indexName) {
IndicesExists indicesExists = new IndicesExists.Builder(indexName).build();
JestResult result = execute(indicesExists, true);
return result.getJsonObject().get("found").getAsBoolean();
}
示例14: exists
import io.searchbox.indices.IndicesExists; //导入依赖的package包/类
/**
* Check if the given index exists.
*
* @param index the name of the index
* @return true if the index exists.
*/
public boolean exists(String index) {
return execute(new IndicesExists.Builder(index).build()).isSucceeded();
}