本文整理了Java中org.elasticsearch.cluster.metadata.MappingMetaData
类的一些代码示例,展示了MappingMetaData
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MappingMetaData
类的具体详情如下:
包路径:org.elasticsearch.cluster.metadata.MappingMetaData
类名称:MappingMetaData
[英]Mapping configuration for a type.
[中]映射类型的配置。
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
client.admin().indices().prepareRefresh(index).get();
ImmutableOpenMap<String, MappingMetaData> mappings = client.admin().cluster().prepareState().get().getState().getMetaData()
.index(index).mappings();
logger.trace("mappings contains type {}: {}", type, mappings.containsKey(type));
if (mappings.containsKey(type)) {
MappingMetaData mapping = mappings.get(type);
if (client.admin().indices().prepareDeleteMapping(index).setType(type).get().isAcknowledged()) {
PutMappingResponse pmr = client.admin().indices().preparePutMapping(index).setType(type)
.setSource(mapping.getSourceAsMap()).get();
if (!pmr.isAcknowledged()) {
logger.error("Failed to put mapping {} / {} / {}.", index, type, mapping.source());
} else {
logger.info("Delete and recreate for index / type [{}] [{}] successfully executed.", index, type);
代码示例来源:origin: org.elasticsearch/elasticsearch
private int getTaskResultMappingVersion(IndexMetaData metaData) {
MappingMetaData mappingMetaData = metaData.getMappings().get(TASK_TYPE);
if (mappingMetaData == null) {
return 0;
}
@SuppressWarnings("unchecked") Map<String, Object> meta = (Map<String, Object>) mappingMetaData.sourceAsMap().get("_meta");
if (meta == null || meta.containsKey(TASK_RESULT_MAPPING_VERSION_META_FIELD) == false) {
return 1; // The mapping was created before meta field was introduced
}
return (int) meta.get(TASK_RESULT_MAPPING_VERSION_META_FIELD);
}
代码示例来源:origin: SonarSource/sonarqube
private void verifyFakeIndex() {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings();
MappingMetaData mapping = mappings.get("fakes").get("fake");
assertThat(mapping.type()).isEqualTo("fake");
assertThat(mapping.getSourceAsMap()).isNotEmpty();
assertThat(countMappingFields(mapping)).isEqualTo(2);
assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date");
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private synchronized Map<String, DocumentMapper> internalMerge(IndexMetaData indexMetaData, MergeReason reason,
boolean updateAllTypes, boolean onlyUpdateIfNeeded) {
Map<String, CompressedXContent> map = new LinkedHashMap<>();
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) {
MappingMetaData mappingMetaData = cursor.value;
if (onlyUpdateIfNeeded) {
DocumentMapper existingMapper = documentMapper(mappingMetaData.type());
if (existingMapper == null || mappingMetaData.source().equals(existingMapper.mappingSource()) == false) {
map.put(mappingMetaData.type(), mappingMetaData.source());
}
} else {
map.put(mappingMetaData.type(), mappingMetaData.source());
}
}
return internalMerge(map, reason, updateAllTypes);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
if (!blocks().indices().isEmpty()) {
builder.startObject("indices");
for (ObjectObjectCursor<String, Set<ClusterBlock>> entry : blocks().indices()) {
builder.field("cluster_uuid", metaData().clusterUUID());
builder.startObject("templates");
for (ObjectCursor<IndexTemplateMetaData> cursor : metaData().templates().values()) {
IndexTemplateMetaData templateMetaData = cursor.value;
builder.startObject(templateMetaData.name());
builder.startObject(indexMetaData.getIndex().getName());
builder.field("state", indexMetaData.getState().toString().toLowerCase(Locale.ENGLISH));
Settings settings = indexMetaData.getSettings();
settings.toXContent(builder, params);
builder.endObject();
for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.getMappings()) {
Map<String, Object> mapping = XContentHelper
.convertToMap(new BytesArray(cursor.value.source().uncompressed()), false).v2();
if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
for (ObjectCursor<String> cursor : indexMetaData.getAliases().keys()) {
builder.value(cursor.value);
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* @param concreteIndex The concrete index to check if routing is required
* @param type The type to check if routing is required
* @return Whether routing is required according to the mapping for the specified index and type
*/
public boolean routingRequired(String concreteIndex, String type) {
IndexMetaData indexMetaData = indices.get(concreteIndex);
if (indexMetaData != null) {
MappingMetaData mappingMetaData = indexMetaData.getMappings().get(type);
if (mappingMetaData != null) {
return mappingMetaData.routing().required();
}
}
return false;
}
代码示例来源: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: alibaba/canal
.getMetaData()
.getIndices()
.get(mapping.get_index())
.getMappings();
} catch (NullPointerException e) {
throw new IllegalArgumentException("Not found the mapping info of index: " + mapping.get_index());
MappingMetaData mappingMetaData = mappings.get(mapping.get_type());
if (mappingMetaData == null) {
throw new IllegalArgumentException("Not found the mapping info of index: " + mapping.get_index());
Map<String, Object> sourceMap = mappingMetaData.getSourceAsMap();
Map<String, Object> esMapping = (Map<String, Object>) sourceMap.get("properties");
for (Map.Entry<String, Object> entry : esMapping.entrySet()) {
代码示例来源:origin: org.elasticsearch/elasticsearch
public static void toXContent(IndexMetaData indexMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(indexMetaData.getIndex().getName());
builder.field(KEY_VERSION, indexMetaData.getVersion());
builder.field(KEY_MAPPING_VERSION, indexMetaData.getMappingVersion());
builder.field(KEY_SETTINGS_VERSION, indexMetaData.getSettingsVersion());
builder.field(KEY_ROUTING_NUM_SHARDS, indexMetaData.getRoutingNumShards());
for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.getMappings()) {
if (binary) {
builder.value(cursor.value.source().compressed());
} else {
builder.map(XContentHelper.convertToMap(new BytesArray(cursor.value.source().uncompressed()), true).v2());
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) {
AliasMetaData.Builder.toXContent(cursor.value, builder, params);
for (ObjectCursor<RolloverInfo> cursor : indexMetaData.getRolloverInfos().values()) {
cursor.value.toXContent(builder, params);
代码示例来源:origin: prestodb/presto
Iterator<String> indexIterator = mappings.keysIt();
while (indexIterator.hasNext()) {
MappingMetaData mappingMetaData = mappings.get(indexIterator.next()).get(tableDescription.getType());
JsonNode rootNode;
try {
rootNode = objecMapper.readTree(mappingMetaData.source().uncompressed());
代码示例来源:origin: com.scireum/sirius-search
private void outputMapping(Output output, ImmutableOpenMap<String, MappingMetaData> c) throws IOException {
Iterator<String> iter = c.keysIt();
while (iter.hasNext()) {
String property = iter.next();
MappingMetaData md = c.get(property);
output.line("routing: " + md.routing().toString());
for (Map.Entry<String, Object> e : md.getSourceAsMap().entrySet()) {
outputMappingRow(output, e);
}
}
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch5-plugin
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings
= context.getClient().admin().indices().prepareGetMappings().get().getMappings();
for (ObjectCursor<String> index : mappings.keys()) {
ImmutableOpenMap<String, MappingMetaData> types = mappings.get(index.value);
if (types == null) {
continue;
MappingMetaData elementMetadata = types.get(ELEMENT_DOCUMENT_MAPPER_NAME);
if (elementMetadata == null) {
continue;
Map<String, Map<String, String>> meta = (Map<String, Map<String, String>>) elementMetadata.getSourceAsMap().get("_meta");
if (meta == null) {
continue;
代码示例来源:origin: org.elasticsearch/elasticsearch
List<AliasMetaData> indexAliases = aliases.get(index);
if (indexAliases != null) {
for (final AliasMetaData alias : indexAliases) {
ImmutableOpenMap<String, MappingMetaData> indexMappings = mappings.get(index);
if (indexMappings != null) {
for (final ObjectObjectCursor<String, MappingMetaData> typeEntry : indexMappings) {
builder.field(typeEntry.key);
builder.map(typeEntry.value.sourceAsMap());
Settings indexSettings = settings.get(index);
if (indexSettings != null) {
indexSettings.toXContent(builder, params);
代码示例来源: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: karussell/elasticsearch-reindex
/**
* Creates a new index out of the settings from the old index.
*/
private void createIdenticalIndex(String oldIndex, String type,
String newIndex, int newIndexShards, Client client) throws IOException {
IndexMetaData indexData = client.admin().cluster().state(new ClusterStateRequest()).
actionGet().getState().metaData().indices().get(oldIndex);
Settings searchIndexSettings = indexData.settings();
ImmutableSettings.Builder settingBuilder = ImmutableSettings.settingsBuilder().put(searchIndexSettings);
if (newIndexShards > 0)
settingBuilder.put("index.number_of_shards", newIndexShards);
CreateIndexRequest createReq;
if(type.equals("*")) {
createReq = new CreateIndexRequest(newIndex);
for(ObjectObjectCursor<String, MappingMetaData> mapCursor : indexData.mappings()) {
createReq.mapping(mapCursor.key, mapCursor.value.sourceAsMap());
}
createReq.settings(settingBuilder.build());
}
else {
MappingMetaData mappingMeta = indexData.mapping(type);
createReq = new CreateIndexRequest(newIndex).
mapping(type, mappingMeta.sourceAsMap()).
settings(settingBuilder.build());
}
client.admin().indices().create(createReq).actionGet();
}
代码示例来源: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: org.elasticsearch/elasticsearch
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(type());
source().writeTo(out);
// routing
out.writeBoolean(routing().required());
if (out.getVersion().before(Version.V_6_0_0_alpha1)) {
// timestamp
out.writeBoolean(false); // enabled
out.writeString(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern());
out.writeOptionalString("now"); // 5.x default
out.writeOptionalBoolean(null);
}
out.writeBoolean(hasParentField());
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
@SuppressWarnings("unchecked")
private Map<String, Object> field(MappingMetaData mapping, String field) {
Map<String, Object> props = (Map<String, Object>) mapping.getSourceAsMap().get("properties");
return (Map<String, Object>) props.get(field);
}
代码示例来源:origin: dqeasycloud/easy-cloud
@Override
public Map<String, Object> getAllMapping(String indexName) throws Exception {
Assert.notNull(indexName, "No index defined for putMapping()");
Map<String, Object> map = new HashMap<>();
try {
ImmutableOpenMap<String, MappingMetaData> immutableOpenMap = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName))
.actionGet().getMappings().get(indexName);
Iterator<ObjectObjectCursor<String, MappingMetaData>> iterator = immutableOpenMap.iterator();
while (iterator.hasNext()) {
ObjectObjectCursor<String, MappingMetaData> objectObjectCursor = iterator.next();
map.put(objectObjectCursor.key, objectObjectCursor.value.getSourceAsMap());
}
} catch (Exception e) {
throw new Exception("Error while getting mapping for indexName : " + indexName + e.getMessage());
}
return map;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
if (Assertions.ENABLED
&& currentIndexMetaData != null
&& currentIndexMetaData.getCreationVersion().onOrAfter(Version.V_6_5_0)) {
if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) {
for (final ObjectCursor<MappingMetaData> mapping : newIndexMetaData.getMappings().values()) {
final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source();
final CompressedXContent newSource = mapping.value.source();
assert currentSource.equals(newSource) :
"expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] "
+ "to be the same as new mapping [" + newSource + "]";
final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type());
if (currentMapping != null) {
final CompressedXContent currentSource = currentMapping.source();
final CompressedXContent newSource = documentMapper.mappingSource();
assert currentSource.equals(newSource) == false :
内容来源于网络,如有侵权,请联系作者删除!