Java Examples for io.searchbox.indices.mapping.PutMapping
The following java examples will help you to understand the usage of io.searchbox.indices.mapping.PutMapping. These source code samples are taken from different open source projects.
Example 1
| Project: metamodel-master File: JestElasticSearchCreateTableBuilder.java View source code |
@Override
public Table execute() throws MetaModelException {
final MutableTable table = getTable();
final Map<String, ?> source = ElasticSearchUtils.getMappingSource(table);
final ElasticSearchRestDataContext dataContext = getUpdateCallback().getDataContext();
final String indexName = dataContext.getIndexName();
final PutMapping putMapping = new PutMapping.Builder(indexName, table.getName(), source).build();
getUpdateCallback().execute(putMapping);
final MutableSchema schema = (MutableSchema) getSchema();
schema.addTable(table);
return table;
}Example 2
| Project: sagan-master File: SearchIndexSetup.java View source code |
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);
}
}Example 3
| Project: Jest-master File: PutMappingIntegrationTest.java View source code |
@Test
public void testPutMapping() throws IOException {
PutMapping putMapping = new PutMapping.Builder(INDEX_NAME, INDEX_TYPE, "{ \"document\" : { \"properties\" : { \"message_1\" : {\"type\" : \"string\", \"store\" : \"yes\"} } } }").build();
JestResult result = client.execute(putMapping);
assertTrue(result.getErrorMessage(), result.isSucceeded());
}Example 4
| Project: lucene-solr-talk-master File: Indexer.java View source code |
public void prepareIndex() throws Exception {
// delete the index if it exists
boolean indexExists = client.execute(new IndicesExists.Builder("jug").build()).isSucceeded();
if (indexExists) {
client.execute(new DeleteIndex.Builder("jug").build());
}
client.execute(new CreateIndex.Builder("jug").build());
// add the mapping
String mapping = "\"talk\": { ".concat(" \"properties\" : {").concat(" \"path\" : { \"type\" : \"string\", \"index\" : \"not_analyzed\" },").concat(" \"title\" : { \"type\" : \"string\", \"analyzer\" : \"german\" },").concat(" \"category\" : {\"type\" : \"string\", \"index\" : \"not_analyzed\" },").concat(" \"speaker\" : {\"type\" : \"string\", \"index\" : \"not_analyzed\" },").concat(" \"date\" : {\"type\" : \"date\" },").concat(" \"content\" : { \"type\" : \"string\", \"analyzer\" : \"german\" },").concat(" \"organizer\" : {\"type\" : \"string\", \"index\" : \"not_analyzed\" }").concat("} }");
log.info(mapping);
PutMapping.Builder putMapping = new PutMapping.Builder("jug", "talk", mapping);
client.execute(putMapping.build());
}Example 5
| Project: xwiki-platform-master File: DefaultPingSender.java View source code |
@Override
public void sendPing() throws Exception {
JestClient client = this.jestClientManager.getClient();
// Step 1: Create index (if already exists then it'll just be ignored)
client.execute(new CreateIndex.Builder(JestClientManager.INDEX).build());
// Step 2: Create a mapping so that we can search distribution versions containing hyphens (otherwise they
// are removed by the default tokenizer/analyzer). If mapping already exists then it'll just be ignored.
PutMapping putMapping = new PutMapping.Builder(JestClientManager.INDEX, JestClientManager.TYPE, constructJSONMapping()).build();
client.execute(putMapping);
// Step 3: Index the data
Index index = new Index.Builder(constructIndexJSON()).index(JestClientManager.INDEX).type(JestClientManager.TYPE).build();
JestResult result = client.execute(index);
if (!result.isSucceeded()) {
throw new Exception(result.getErrorMessage());
}
}Example 6
| Project: jmxtrans-master File: ElasticWriter.java View source code |
private static void createMappingIfNeeded(JestClient jestClient, String indexName, String typeName) throws ElasticWriterException, IOException {
synchronized (CREATE_MAPPING_LOCK) {
IndicesExists indicesExists = new IndicesExists.Builder(indexName).build();
boolean indexExists = jestClient.execute(indicesExists).isSucceeded();
if (!indexExists) {
CreateIndex createIndex = new CreateIndex.Builder(indexName).build();
jestClient.execute(createIndex);
URL url = ElasticWriter.class.getResource("/elastic-mapping.json");
String mapping = Resources.toString(url, Charsets.UTF_8);
PutMapping putMapping = new PutMapping.Builder(indexName, typeName, mapping).build();
JestResult result = jestClient.execute(putMapping);
if (!result.isSucceeded()) {
throw new ElasticWriterException(String.format("Failed to create mapping: %s", result.getErrorMessage()));
} else {
log.info("Created mapping for index {}", indexName);
}
}
}
}Example 7
| Project: tsdr-master File: ElasticsearchStore.java View source code |
/**
* Setup elasticsearch data storage index, related types, and mappings.
*/
private void setupStorage(boolean indexExists) throws IOException {
// Create an index if it doesn't exist.
if (!indexExists) {
execute(new CreateIndex.Builder(INDEX).build());
}
// Setup mappings for types.
for (RecordType type : RecordType.values()) {
if (!Strings.isNullOrEmpty(type.mapping)) {
execute(new PutMapping.Builder(INDEX, type.name, type.mapping).build());
}
}
}Example 8
| Project: shopizer-master File: SearchDelegateImpl.java View source code |
//https://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/indices/CreateIndexIntegrationTest.java
/* (non-Javadoc)
* @see com.shopizer.search.services.impl.SearchService#createIndice(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void createIndice(String mapping, String settings, String index, String object) throws Exception {
//Client client = searchClient.getClient();
JestClient client = searchClient.getClient();
CreateIndex.Builder createIndex = new CreateIndex.Builder(index);
//set settings to the index
if (settings != null) {
createIndex.settings(Settings.settingsBuilder().loadFromSource(settings).build().getAsMap());
}
client.execute(createIndex.build());
PutMapping.Builder putMapping = new PutMapping.Builder(index, object, mapping);
JestResult result = client.execute(putMapping.build());
if (result != null && !StringUtils.isBlank(result.getErrorMessage())) {
log.error("An error occured while creating an index " + result.getErrorMessage());
}
}Example 9
| Project: baleen-master File: ElasticsearchRest.java View source code |
@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);
}
}Example 10
| Project: play2-elasticsearch-jest-master File: IndexService.java View source code |
/**
* 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);
}