本文整理汇总了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()));
}
示例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);
}
}
示例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()
);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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"));
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 + "]");
}
示例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());
}
}
示例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);
}