本文整理了Java中org.elasticsearch.client.IndicesAdminClient.prepareGetMappings()
方法的一些代码示例,展示了IndicesAdminClient.prepareGetMappings()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndicesAdminClient.prepareGetMappings()
方法的具体详情如下:
包路径:org.elasticsearch.client.IndicesAdminClient
类名称:IndicesAdminClient
方法名:prepareGetMappings
[英]Get the complete mappings of one or more types
[中]获取一个或多个类型的完整映射
代码示例来源:origin: SonarSource/sonarqube
@Override
public void deleteIndexes(String name, String... otherNames) {
GetMappingsResponse mappings = client.nativeClient().admin().indices().prepareGetMappings("_all").get();
Set<String> existingIndices = Sets.newHashSet(mappings.mappings().keysIt());
Stream.concat(Stream.of(name), Arrays.stream(otherNames))
.distinct()
.filter(existingIndices::contains)
.forEach(this::deleteIndex);
}
代码示例来源:origin: Netflix/conductor
private void addMappingToIndex(String indexName, String mappingType, String mappingFilename)
throws IOException {
GetMappingsResponse getMappingsResponse = elasticSearchClient.admin()
.indices()
.prepareGetMappings(indexName)
.addTypes(mappingType)
.execute()
.actionGet();
if (getMappingsResponse.mappings().isEmpty()) {
logger.info("Adding the workflow type mappings");
InputStream stream = ElasticSearchDAOV5.class.getResourceAsStream(mappingFilename);
byte[] bytes = IOUtils.toByteArray(stream);
String source = new String(bytes);
try {
elasticSearchClient.admin()
.indices()
.preparePutMapping(indexName)
.setType(mappingType)
.setSource(source)
.execute()
.actionGet();
} catch (Exception e) {
logger.error("Failed to init index mappings", e);
}
}
}
代码示例来源:origin: SonarSource/sonarqube
private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings() {
return es.client().nativeClient().admin().indices().prepareGetMappings().get().mappings();
}
代码示例来源:origin: SonarSource/sonarqube
private Iterator<String> loadExistingIndices() {
return es.client().nativeClient().admin().indices().prepareGetMappings().get().mappings().keysIt();
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
@ExcludeOnTravis
public void testMapping() throws Exception {
configurationSource.save("foo", "bar");
refresh();
final GetMappingsResponse mappings = client.admin().indices().prepareGetMappings("stagemonitor-configuration").setTypes("configuration").get();
assertEquals(1, mappings.getMappings().size());
assertEquals("{\"configuration\":{" +
"\"_all\":{\"enabled\":false}," +
"\"properties\":{\"configuration\":{\"properties\":{" +
"\"key\":{\"type\":\"keyword\"}," +
"\"value\":{\"type\":\"keyword\"}}}}" +
"}" +
"}",
mappings.getMappings().get("stagemonitor-configuration").get("configuration").source().toString());
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
@Override
public void deleteIndexes(String name, String... otherNames) {
GetMappingsResponse mappings = client.nativeClient().admin().indices().prepareGetMappings("_all").get();
Set<String> existingIndices = Sets.newHashSet(mappings.mappings().keysIt());
Stream.concat(Stream.of(name), Arrays.stream(otherNames))
.distinct()
.filter(existingIndices::contains)
.forEach(this::deleteIndex);
}
代码示例来源:origin: cheng-li/pyramid
public Set<String> listAllFields() throws Exception{
GetMappingsResponse response = client.admin().indices().prepareGetMappings(this.indexName).
execute().actionGet();
MappingMetaData mappingMetaData = response.getMappings().get(this.indexName).get(this.documentType);
Map map = (Map)mappingMetaData.getSourceAsMap().get("properties");
Set<String> fields = new HashSet<>();
for (Object field: map.keySet()){
fields.add(field.toString());
}
return fields;
}
代码示例来源:origin: fr.pilato.elasticsearch/elasticsearch-beyonder
/**
* Check if a type already exists
* @param client Elasticsearch client
* @param index Index name
* @param type Type name
* @return true if type already exists
* @throws Exception if the elasticsearch call is failing
*/
@Deprecated
public static boolean isTypeExist(Client client, String index, String type) throws Exception {
return !client.admin().indices().prepareGetMappings(index).setTypes(type).get().getMappings().isEmpty();
}
代码示例来源:origin: dadoonet/elasticsearch-beyonder
/**
* Check if a type already exists
* @param client Elasticsearch client
* @param index Index name
* @param type Type name
* @return true if type already exists
* @throws Exception if the elasticsearch call is failing
*/
@Deprecated
public static boolean isTypeExist(Client client, String index, String type) throws Exception {
return !client.admin().indices().prepareGetMappings(index).setTypes(type).get().getMappings().isEmpty();
}
代码示例来源:origin: rmagen/elastic-gremlin
public static DeleteByQueryResponse clearIndex(Client client, String indexName){
DeleteByQueryResponse indexDeleteByQueryResponses = client.prepareDeleteByQuery(indexName).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings(indexName).execute().actionGet();
ArrayList<String> mappings = new ArrayList();
getMappingsResponse.getMappings().forEach(map -> {
map.value.forEach(map2 -> mappings.add(map2.value.type()));
});
if(mappings.size() > 0) {
DeleteMappingResponse deleteMappingResponse = client.admin().indices().prepareDeleteMapping(indexName).setType(mappings.toArray(new String[mappings.size()])).execute().actionGet();
}
return indexDeleteByQueryResponses;
}
代码示例来源:origin: org.apache.james/apache-james-backends-es
public static boolean mappingAlreadyExist(Client client, IndexName indexName, TypeName typeName) {
return Iterators.toStream(client.admin()
.indices()
.prepareGetMappings(indexName.getValue())
.execute()
.actionGet()
.getMappings()
.valuesIt())
.anyMatch(mapping -> mapping.keys().contains(typeName.getValue()));
}
代码示例来源:origin: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core
@Override
public boolean mappingExists(String indexName, String type) {
GetMappingsResponse mappings = client.admin().indices().prepareGetMappings(indexName).execute().actionGet();
if (mappings == null || mappings.getMappings().isEmpty()) {
return false;
}
// The real index might have another name if indexName is an alias so we check the mapping of the first item.
return mappings.getMappings().values().iterator().next().value.containsKey(type);
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-sail-elasticsearch
public Map<String, Object> getMappings()
throws IOException
{
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings = client.admin().indices().prepareGetMappings(
indexName).setTypes(documentType).execute().actionGet().getMappings();
ImmutableOpenMap<String, MappingMetaData> typeMappings = indexMappings.get(indexName);
MappingMetaData mappings = typeMappings.get(documentType);
return mappings.sourceAsMap();
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
/**
* Waits for the given mapping type to exists on the master node.
*/
public void assertMappingOnMaster(final String index, final String type, final String... fieldNames) throws Exception {
GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get();
ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get(index);
assertThat(mappings, notNullValue());
MappingMetaData mappingMetaData = mappings.get(type);
assertThat(mappingMetaData, notNullValue());
Map<String, Object> mappingSource = mappingMetaData.getSourceAsMap();
assertFalse(mappingSource.isEmpty());
assertTrue(mappingSource.containsKey("properties"));
for (String fieldName : fieldNames) {
Map<String, Object> mappingProperties = (Map<String, Object>) mappingSource.get("properties");
if (fieldName.indexOf('.') != -1) {
fieldName = fieldName.replace(".", ".properties.");
}
assertThat("field " + fieldName + " doesn't exists in mapping " + mappingMetaData.source().string(), XContentMapValues.extractValue(fieldName, mappingProperties), notNullValue());
}
}
代码示例来源:origin: kiegroup/appformer
public Optional<MappingMetaData> getMapping(String index,
String type) {
checkNotEmpty("index",
index);
checkNotEmpty("type",
type);
try {
GetMappingsResponse mappingResponse = this.getClient().admin().indices().prepareGetMappings(sanitizeIndex(index)).addTypes(sanitizeIndex(type)).get();
return Optional.ofNullable(mappingResponse.getMappings().getOrDefault(sanitizeIndex(index),
ImmutableOpenMap.of()).getOrDefault(sanitizeIndex(type),
null));
} catch (IndexNotFoundException ex) {
if (logger.isDebugEnabled()) {
logger.error(MessageFormat.format("Index not found trying to get mapping for {0}:{1}",
index,
type),
ex);
}
return Optional.empty();
}
}
代码示例来源:origin: org.uberfire/uberfire-metadata-backend-elasticsearch
public Optional<MappingMetaData> getMapping(String index,
String type) {
checkNotEmpty("index",
index);
checkNotEmpty("type",
type);
try {
GetMappingsResponse mappingResponse = this.getClient().admin().indices().prepareGetMappings(sanitizeIndex(index)).addTypes(sanitizeIndex(type)).get();
return Optional.ofNullable(mappingResponse.getMappings().getOrDefault(sanitizeIndex(index),
ImmutableOpenMap.of()).getOrDefault(sanitizeIndex(type),
null));
} catch (IndexNotFoundException ex) {
if (logger.isDebugEnabled()) {
logger.error(MessageFormat.format("Index not found trying to get mapping for {0}:{1}",
index,
type),
ex);
}
return Optional.empty();
}
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch5
private void loadExistingMappingIntoIndexInfo(Graph graph, IndexInfo indexInfo, String indexName) {
try {
indexRefreshTracker.refresh(client, indexName);
GetMappingsResponse mapping = client.admin().indices().prepareGetMappings(indexName).get();
for (ObjectCursor<String> mappingIndexName : mapping.getMappings().keys()) {
ImmutableOpenMap<String, MappingMetaData> typeMappings = mapping.getMappings().get(mappingIndexName.value);
for (ObjectCursor<String> typeName : typeMappings.keys()) {
MappingMetaData typeMapping = typeMappings.get(typeName.value);
Map<String, Map<String, String>> properties = getPropertiesFromTypeMapping(typeMapping);
if (properties == null) {
continue;
}
for (Map.Entry<String, Map<String, String>> propertyEntry : properties.entrySet()) {
String rawPropertyName = propertyEntry.getKey().replace(FIELDNAME_DOT_REPLACEMENT, ".");
loadExistingPropertyMappingIntoIndexInfo(graph, indexInfo, rawPropertyName);
}
}
}
} catch (IOException ex) {
throw new VertexiumException("Could not load type mappings", ex);
}
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch2
private void loadExistingMappingIntoIndexInfo(Graph graph, IndexInfo indexInfo, String indexName) {
try {
GetMappingsResponse mapping = client.admin().indices().prepareGetMappings(indexName).get();
for (ObjectCursor<String> mappingIndexName : mapping.getMappings().keys()) {
ImmutableOpenMap<String, MappingMetaData> typeMappings = mapping.getMappings().get(mappingIndexName.value);
for (ObjectCursor<String> typeName : typeMappings.keys()) {
MappingMetaData typeMapping = typeMappings.get(typeName.value);
Map<String, Map<String, String>> properties = getPropertiesFromTypeMapping(typeMapping);
if (properties == null) {
continue;
}
for (Map.Entry<String, Map<String, String>> propertyEntry : properties.entrySet()) {
String rawPropertyName = propertyEntry.getKey();
loadExistingPropertyMappingIntoIndexInfo(graph, indexInfo, rawPropertyName);
}
}
}
} catch (IOException ex) {
throw new VertexiumException("Could not load type mappings", ex);
}
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch-singledocument
private void loadExistingMappingIntoIndexInfo(Graph graph, IndexInfo indexInfo, String indexName) {
try {
GetMappingsResponse mapping = client.admin().indices().prepareGetMappings(indexName).get();
for (ObjectCursor<String> mappingIndexName : mapping.getMappings().keys()) {
ImmutableOpenMap<String, MappingMetaData> typeMappings = mapping.getMappings().get(mappingIndexName.value);
for (ObjectCursor<String> typeName : typeMappings.keys()) {
MappingMetaData typeMapping = typeMappings.get(typeName.value);
Map<String, Map<String, String>> properties = getPropertiesFromTypeMapping(typeMapping);
if (properties == null) {
continue;
}
for (Map.Entry<String, Map<String, String>> propertyEntry : properties.entrySet()) {
String rawPropertyName = propertyEntry.getKey();
loadExistingPropertyMappingIntoIndexInfo(graph, indexInfo, rawPropertyName);
}
}
}
} catch (IOException ex) {
throw new VertexiumException("Could not load type mappings", ex);
}
}
代码示例来源:origin: visallo/vertexium
private void loadExistingMappingIntoIndexInfo(Graph graph, IndexInfo indexInfo, String indexName) {
try {
indexRefreshTracker.refresh(client, indexName);
GetMappingsResponse mapping = client.admin().indices().prepareGetMappings(indexName).get();
for (ObjectCursor<String> mappingIndexName : mapping.getMappings().keys()) {
ImmutableOpenMap<String, MappingMetaData> typeMappings = mapping.getMappings().get(mappingIndexName.value);
for (ObjectCursor<String> typeName : typeMappings.keys()) {
MappingMetaData typeMapping = typeMappings.get(typeName.value);
Map<String, Map<String, String>> properties = getPropertiesFromTypeMapping(typeMapping);
if (properties == null) {
continue;
}
for (Map.Entry<String, Map<String, String>> propertyEntry : properties.entrySet()) {
String rawPropertyName = propertyEntry.getKey().replace(FIELDNAME_DOT_REPLACEMENT, ".");
loadExistingPropertyMappingIntoIndexInfo(graph, indexInfo, rawPropertyName);
}
}
}
} catch (IOException ex) {
throw new VertexiumException("Could not load type mappings", ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!