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


Java PutMapping类代码示例

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


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

示例1: setUp

import io.searchbox.indices.mapping.PutMapping; //导入依赖的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.mapping.PutMapping; //导入依赖的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: createMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
/**
 * Create an explicit mapping.
 * @param client The client to connect to Elasticsearch.
 * @param index The index to write to Elasticsearch.
 * @param type The type to create mapping for.
 * @param schema The schema used to infer mapping.
 * @throws IOException from underlying JestClient
 */
public static void createMapping(JestClient client, String index, String type, Schema schema)
    throws IOException {
  ObjectNode obj = JsonNodeFactory.instance.objectNode();
  obj.set(type, inferMapping(schema));
  PutMapping putMapping = new PutMapping.Builder(index, type, obj.toString()).build();
  JestResult result = client.execute(putMapping);
  if (!result.isSucceeded()) {
    throw new ConnectException(
        "Cannot create mapping " + obj + " -- " + result.getErrorMessage()
    );
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:21,代码来源:Mapping.java

示例4: validateIndex

import io.searchbox.indices.mapping.PutMapping; //导入依赖的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: indexMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
@Override public void indexMapping(String indexName, String typeName, IndexMap im) throws IOException {
   PutMapping putMapping = new PutMapping.Builder(
           indexName,
           typeName,
           im.toEsJson()
   ).build();
   JestResult result = client.execute(putMapping);
   if(result.isSucceeded()) {
      logger.info("Successfully create or update index mapping for {}/{}", indexName, typeName);
   } else {
      logger.error("Failed to create or update index mapping for " + indexName + "/" + typeName);
      logger.error(result.getErrorMessage());
   }
}
 
开发者ID:chen0040,项目名称:spring-boot-slingshot,代码行数:15,代码来源:ElasticSearchServiceImpl.java

示例6: putMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public boolean putMapping(String indexName, String type, Object mapping) {
	Assert.notNull(indexName, "No index defined for putMapping()");
	Assert.notNull(type, "No type defined for putMapping()");

	try {
		Object source = null;
		if (mapping instanceof String) {
			source = String.valueOf(mapping);
		} else if (mapping instanceof Map) {
			XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
			builder.map((Map) mapping);
			source = builder.string();
		} else if (mapping instanceof XContentBuilder) {
			source = ((XContentBuilder) mapping).string();
		} else if (mapping instanceof DocumentMapper) {
			source = ((DocumentMapper) mapping).mappingSource().toString();
		}

		PutMapping.Builder requestBuilder = new PutMapping.Builder(indexName, type, source);

		return executeWithAcknowledge(requestBuilder.build());

	} catch (Exception e) {
		throw new ElasticsearchException("Failed to build mapping for " + indexName + ":" + type, e);
	}
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:29,代码来源:JestElasticsearchTemplate.java

示例7: validateNested

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
public JestResult validateNested(String index, String type, String path) {
    PutMapping putMapping = new PutMapping.Builder(
            index,
            type,
            "{ \"" + type + "\" : { \"properties\" : { \"" + path + "\" : {\"type\" : \"nested\"} } } }"
    ).build();
    logger.info("putting mapping for nested, mapping: {}", putMapping);
    return execute(putMapping);
}
 
开发者ID:unipop-graph,项目名称:unipop,代码行数:10,代码来源:ElasticClient.java

示例8: testArmorIndexAttack

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
@Test
public void testArmorIndexAttack() throws Exception {

    final Settings settings = Settings
            .settingsBuilder()
            .putArray("armor.authentication.authorization.settingsdb.roles.jacksonm", "root")
            .put("armor.authentication.settingsdb.user.jacksonm", "secret")
            .put("armor.authentication.authorizer.impl",
                    "com.petalmd.armor.authorization.simple.SettingsBasedAuthorizator")
            .put("armor.authentication.authorizer.cache.enable", "true")
            .put("armor.authentication.authentication_backend.impl",
                    "com.petalmd.armor.authentication.backend.simple.SettingsBasedAuthenticationBackend")
            .put("armor.authentication.authentication_backend.cache.enable", "true")
            .putArray("armor.restactionfilter.names", "readonly")
            .putArray("armor.restactionfilter.readonly.allowed_actions", "RestSearchAction").build();

    startES(settings);
    username = "jacksonm";
    password = "secret";
    setupTestData("ac_rules_1.json");
    executeIndex("ac_rules_1.json", "armor", "ac", "ac", false, false);
    executeIndex("ac_rules_1.json", "armor", "ac", "ac", true, true);
    executeIndex("ac_rules_1.json", "armor", "xx", "xx", false, false);

    final JestClient client = getJestClient(getServerUri(false), username, password);

    final JestResult jr = client.execute(new PutMapping.Builder("_all", "ac", "{" + "\"properties\" : {"
            + "\"rules\" : {\"type\" : \"string\", \"store\" : true }" + "}" + "}"
    ).setHeader(headers).build());

    Assert.assertNotNull(jr.getErrorMessage());
    log.debug(jr.getErrorMessage());
    Assert.assertTrue(jr.getErrorMessage().contains("to _all indices"));

}
 
开发者ID:petalmd,项目名称:armor,代码行数:36,代码来源:MiscTest.java

示例9: addMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
/**
 * Add a mapping to Elasticsearch. This will only be called if a new index
 * has been created
 */
public void addMapping(XContentBuilder mapping) {
	try {
		PutMapping putMapping = new PutMapping.Builder(index, type, mapping.string()).build();
		esrResource.getClient().execute(putMapping);
	} catch (IOException ioe) {
		getMonitor().error("Unable to add mapping to index", ioe);
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:13,代码来源:ElasticsearchTemplateRecordConsumer.java

示例10: addMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
@Override
public void addMapping(XContentBuilder mapping) {
	try{
		PutMapping putMapping = new PutMapping.Builder(index, type, mapping.string()).build();
		esrResource.getClient().execute(putMapping);
	}catch(IOException ioe){
		getMonitor().error("Unable to add mapping to index", ioe);
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:10,代码来源:ElasticsearchRest.java

示例11: createMappings

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
public void createMappings() {
    try {

        File mappingsDir = new ClassPathResource("/elasticsearch/mappings", getClass()).getFile();
        for (final File fileEntry : mappingsDir.listFiles()) {
            String filenameBase = fileEntry.getName().replaceAll("\\.json$", "");
            String mappingJson = StreamUtils.copyToString(new FileInputStream(fileEntry), Charset.forName("UTF-8"));
            PutMapping.Builder mapping = new PutMapping.Builder(index, filenameBase, mappingJson);
            execute(mapping.build());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:spring-io,项目名称:sagan,代码行数:15,代码来源:SearchIndexSetup.java

示例12: createIndex

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
private void createIndex(String pIndex) throws IOException {

        Settings settings = Settings.builder()
                .put("number_of_shards", indexerConfigManager.getNumberOfShards())
                .put("number_of_replicas", indexerConfigManager.getNumberOfReplicas())
                .put("auto_expand_replicas", indexerConfigManager.getAutoExpandReplicas())
                .build();

        JestResult result = esClient.execute(new CreateIndex.Builder(pIndex)
                .settings(settings.getAsMap())
                .build());

        if (!result.isSucceeded()) {
            LOGGER.log(Level.SEVERE, "Cannot create index settings: " + result.getErrorMessage());
            return;
        }

        result = esClient.execute(new PutMapping.Builder(pIndex,
                IndexerMapping.DEFAULT_TYPE,
                IndexerMapping.createSourceMapping()).build());


        if (!result.isSucceeded()) {
            LOGGER.log(Level.SEVERE, "Cannot create index DEFAULT_TYPE mappings: " + result.getErrorMessage());
            return;
        }

        result = esClient.execute(new PutMapping.Builder(pIndex,
                IndexerMapping.PART_TYPE,
                IndexerMapping.createPartIterationMapping()).build());


        if (!result.isSucceeded()) {
            LOGGER.log(Level.SEVERE, "Cannot create index PART_TYPE mappings: " + result.getErrorMessage());
            return;
        }

        result = esClient.execute(new PutMapping.Builder(pIndex,
                IndexerMapping.DOCUMENT_TYPE,
                IndexerMapping.createDocumentIterationMapping()).build());


        if (!result.isSucceeded()) {
            LOGGER.log(Level.SEVERE, "Cannot create index DOCUMENT_TYPE mappings: " + result.getErrorMessage());
            return;
        }

        LOGGER.log(Level.INFO, "Index created [" + pIndex + "]");

    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:51,代码来源:IndexerManagerBean.java

示例13: putMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
/**
 * Create or update the mapping for the given type.
 * 
 * @param index the name of the index holding the type
 * @param type the type for which the mapping is generated
 * @param mapping the mapping json
 */
public void putMapping(String index, String type, JsonObject mapping) {
  JestResult result = execute(new PutMapping.Builder(index, type, mapping).build());
  if (!result.isSucceeded()) {
    throw new ElasticsearchPutMappingException(index, type, result.getErrorMessage());
  }
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:14,代码来源:ElasticsearchDao.java

示例14: createMapping

import io.searchbox.indices.mapping.PutMapping; //导入依赖的package包/类
/**
 * Create Mapping ( for example mapping type : nested, geo_point  )
 * see http://www.elasticsearch.org/guide/reference/mapping/
 * <p/>
 * {
 * "tweet" : {
 * "properties" : {
 * "message" : {"type" : "string", "store" : "yes"}
 * }
 * }
 * }
 *  @param indexName
 * @param indexType
 * @param indexMapping
 */
public static JestRichResult createMapping(String indexName, String indexType, String indexMapping) {
    Logger.debug("ElasticSearch : creating mapping [" + indexName + "/" + indexType + "] :  " + indexMapping);
    final PutMapping build = new PutMapping.Builder(indexName, indexType, indexMapping).build();
    return execute(build);
}
 
开发者ID:CedricGatay,项目名称:play2-elasticsearch-jest,代码行数:21,代码来源:IndexService.java


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