当前位置: 首页>>代码示例>>Java>>正文


Java CreateIndex类代码示例

本文整理汇总了Java中io.searchbox.indices.CreateIndex的典型用法代码示例。如果您正苦于以下问题:Java CreateIndex类的具体用法?Java CreateIndex怎么用?Java CreateIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateIndex类属于io.searchbox.indices包,在下文中一共展示了CreateIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
@PostConstruct
public void setUp() throws IOException {
	CountResult result = client.execute(new Count.Builder()
			.addIndex(AddOnInfoAndVersions.ES_INDEX)
			.build());
	if (result.isSucceeded()) {
		logger.info("Existing ES index with " + result.getCount() + " documents");
	} else {
		// need to create the index
		logger.info("Creating new ES index: " + AddOnInfoAndVersions.ES_INDEX);
		handleError(client.execute(new CreateIndex.Builder(AddOnInfoAndVersions.ES_INDEX).build()));
	}
	logger.info("Updating mappings on ES index");
	handleError(client.execute(new PutMapping.Builder(AddOnInfoAndVersions.ES_INDEX,
			AddOnInfoAndVersions.ES_TYPE,
			loadResource("elasticsearch/addOnInfoAndVersions-mappings.json")).build()));
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:18,代码来源:ElasticSearchIndex.java

示例2: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
public void createIndex() {
    Settings.Builder settingsBuilder = Settings.settingsBuilder();
    settingsBuilder.put("number_of_shards", esConfig.getNumberOfShards());
    settingsBuilder.put("number_of_replicas", esConfig.getNumberOfReplicas());

    // No nice way to build this with elasticsearch library
    String mappings = "{ \"" + DEFAULT_TYPE + "\" : { \"properties\" : { \"@timestamp\" : {\"type\" : \"date\", \"format\" : \"epoch_millis\"}}}}";

    try {
        logger.info("Creating test index on ES, named {} with {} shards and {} replicas", indexName, esConfig.getNumberOfShards(), esConfig.getNumberOfReplicas());
        client.execute(new CreateIndex.Builder(indexName).settings(settingsBuilder.build().getAsMap()).build());
        client.execute(new PutMapping.Builder(indexName, DEFAULT_TYPE, mappings).build());

        indexCreated = true;

    } catch (IOException e) {
        throw new RuntimeException("Could not create index in elasticsearch!", e);
    }
}
 
开发者ID:logzio,项目名称:elasticsearch-benchmark-tool,代码行数:20,代码来源:ElasticsearchController.java

示例3: createIndicesForTopics

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
public void createIndicesForTopics(Set<String> assignedTopics) {
  for (String index : indicesForTopics(assignedTopics)) {
    if (!indexExists(index)) {
      CreateIndex createIndex = new CreateIndex.Builder(index).build();
      try {
        JestResult result = client.execute(createIndex);
        if (!result.isSucceeded()) {
          String msg = result.getErrorMessage() != null ? ": " + result.getErrorMessage() : "";
          throw new ConnectException("Could not create index '" + index + "'" + msg);
        }
      } catch (IOException e) {
        throw new ConnectException(e);
      }
    }
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:17,代码来源:ElasticsearchWriter.java

示例4: validateIndex

import io.searchbox.indices.CreateIndex; //导入依赖的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);
        }
    }
 
开发者ID:unipop-graph,项目名称:unipop,代码行数:23,代码来源:ElasticClient.java

示例5: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:18,代码来源:ElasticsearchRest.java

示例6: deleteAll

import io.searchbox.indices.CreateIndex; //导入依赖的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);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:AbstractElasticIndex.java

示例7: builderIndex_OneRecord

import io.searchbox.indices.CreateIndex; //导入依赖的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"); 
}
 
开发者ID:faustineinsun,项目名称:WiseCrowdRec,代码行数:24,代码来源:JestElasticsearchManipulator.java

示例8: builderIndex_Bulk

import io.searchbox.indices.CreateIndex; //导入依赖的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); 
}
 
开发者ID:faustineinsun,项目名称:WiseCrowdRec,代码行数:32,代码来源:JestElasticsearchManipulator.java

示例9: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
private static void createIndex(String indexName, JestClient client) {
	try {
		client.execute(new CreateIndex.Builder(indexName).build());
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:8,代码来源:ElasticApp.java

示例10: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
@Override
public boolean createIndex(String indexName, Object settings) {

	CreateIndex.Builder createIndexBuilder = new CreateIndex.Builder(indexName);

	if (settings instanceof String) {
		createIndexBuilder.settings(String.valueOf(settings));
	} else if (settings instanceof Map) {
		createIndexBuilder.settings(settings);
	} else if (settings instanceof XContentBuilder) {
		createIndexBuilder.settings(settings);
	}

	return executeWithAcknowledge(createIndexBuilder.build());
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:16,代码来源:JestElasticsearchTemplate.java

示例11: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
/**
 * Create an index with the given settings as json.
 * 
 * @param index the name of the index
 * @param settings the settings json
 */
public void createIndex(String index, JsonObject settings) {
  JestResult result = execute(new CreateIndex.Builder(index).settings(settings).build());
  if (!result.isSucceeded()) {
    throw new ElasticsearchIndexCreateException(index, result.getErrorMessage());
  }
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:13,代码来源:ElasticsearchDao.java

示例12: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:20,代码来源:ElasticsearchTemplateRecordConsumer.java

示例13: init

import io.searchbox.indices.CreateIndex; //导入依赖的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!");
    }
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:29,代码来源:SearchIndexingServiceImpl.java

示例14: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
/**
 * @param indexName
 * @throws Exception
 */
private void createIndex(String indexName) throws Exception {
    URL settings = getClass().getResource("index-settings.json"); //$NON-NLS-1$
    String source = IOUtils.toString(settings);
    JestResult response = esClient.execute(new CreateIndex.Builder(indexName).settings(source).build());
    if (!response.isSucceeded()) {
        throw new StorageException("Failed to create index " + indexName + ": " + response.getErrorMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:13,代码来源:EsStorage.java

示例15: createIndex

import io.searchbox.indices.CreateIndex; //导入依赖的package包/类
/**
 * Creates an index.
 * @param indexName
 * @throws Exception
 */
protected void createIndex(JestClient client, String indexName, String settingsName) throws Exception {
    URL settings = AbstractClientFactory.class.getResource(settingsName);
    String source = IOUtils.toString(settings);
    JestResult response = client.execute(new CreateIndex.Builder(indexName).settings(source).build());
    if (!response.isSucceeded()) {
        // When running in e.g. Wildfly, the Gateway exists as two separate WARs - the API and the
        // runtime Gateway itself.  They both create a registry and thus they both try to initialize
        // the ES index if it doesn't exist.  A race condition could result in both WARs trying to
        // create the index.  So a result of "IndexAlreadyExistsException" should be ignored.
        if (!response.getErrorMessage().startsWith("IndexAlreadyExistsException")) { //$NON-NLS-1$
            throw new Exception("Failed to create index: '" + indexName + "' Reason: " + response.getErrorMessage()); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:20,代码来源:AbstractClientFactory.java


注:本文中的io.searchbox.indices.CreateIndex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。