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


Java MappingMetaData类代码示例

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


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

示例1: getESFields

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public static List<String> getESFields(String index, String type) {
	List<String> fieldList = new ArrayList<String>();
	boolean indexExist = ESReport.getESClient().admin().indices().prepareExists(index).execute().actionGet().isExists();
	ClusterStateResponse resp = ESReport.getESClient().admin().cluster().prepareState().execute().actionGet();
	boolean typeExist = resp.getState().metaData().index(index).getMappings().containsKey(type);

	if (indexExist && typeExist) {
		ClusterState cs = ESReport.getESClient().admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
		IndexMetaData imd = cs.getMetaData().index(index);
		MappingMetaData mdd = imd.mapping(type);
		Map<String, Object> map = null;
		try {
			map = mdd.getSourceAsMap();
		} catch (IOException e) {
			e.printStackTrace();
		}
		fieldList = getList("", map);
	}
	return fieldList;
}
 
开发者ID:raghavendar-ts,项目名称:ElasticTab-Elasticsearch-to-Excel-Report,代码行数:21,代码来源:Util.java

示例2: loadExistingMappingIntoIndexInfo

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
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().replace(FIELDNAME_DOT_REPLACEMENT, ".");
                    loadExistingPropertyMappingIntoIndexInfo(graph, indexInfo, rawPropertyName);
                }
            }
        }
    } catch (IOException ex) {
        throw new MemgraphException("Could not load type mappings", ex);
    }
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:23,代码来源:Elasticsearch5SearchIndex.java

示例3: assertMappingOnMaster

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ESIntegTestCase.java

示例4: recoverFromLocalShards

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public boolean recoverFromLocalShards(BiConsumer<String, MappingMetaData> mappingUpdateConsumer, List<IndexShard> localShards) throws IOException {
    assert shardRouting.primary() : "recover from local shards only makes sense if the shard is a primary shard";
    assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS : "invalid recovery type: " + recoveryState.getRecoverySource();
    final List<LocalShardSnapshot> snapshots = new ArrayList<>();
    try {
        for (IndexShard shard : localShards) {
            snapshots.add(new LocalShardSnapshot(shard));
        }

        // we are the first primary, recover from the gateway
        // if its post api allocation, the index should exists
        assert shardRouting.primary() : "recover from local shards only makes sense if the shard is a primary shard";
        StoreRecovery storeRecovery = new StoreRecovery(shardId, logger);
        return storeRecovery.recoverFromLocalShards(mappingUpdateConsumer, this, snapshots);
    } finally {
        IOUtils.close(snapshots);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:IndexShard.java

示例5: internalMerge

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MapperService.java

示例6: readFrom

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < size; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
        for (int j = 0; j < valueSize; j++) {
            typeMapBuilder.put(in.readString(), new MappingMetaData(in));
        }
        indexMapBuilder.put(key, typeMapBuilder.build());
    }
    mappings = indexMapBuilder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:GetMappingsResponse.java

示例7: process

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public void process(@Nullable MappingMetaData mappingMd, String concreteIndex) {
    if (mappingMd != null) {
        // might as well check for routing here
        if (mappingMd.routing().required() && routing == null) {
            throw new RoutingMissingException(concreteIndex, type, id);
        }

        if (parent != null && !mappingMd.hasParentField()) {
            throw new IllegalArgumentException("Can't specify parent if no parent field has been configured");
        }
    } else {
        if (parent != null) {
            throw new IllegalArgumentException("Can't specify parent if no parent field has been configured");
        }
    }

    // generate id if not already provided
    if (id == null) {
        assert autoGeneratedTimestamp == -1 : "timestamp has already been generated!";
        autoGeneratedTimestamp = Math.max(0, System.currentTimeMillis()); // extra paranoia
        id(UUIDs.base64UUID());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:IndexRequest.java

示例8: testCompletionMultiField

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public void testCompletionMultiField() throws Exception {
    assertAcked(
            client().admin().indices().prepareCreate("my-index")
                    .addMapping("my-type", createMappingSource("completion"))
    );

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
    assertThat(aField.size(), equalTo(6));
    assertThat(aField.get("type").toString(), equalTo("completion"));
    assertThat(aField.get("fields"), notNullValue());

    Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
    assertThat(bField.size(), equalTo(1));
    assertThat(bField.get("type").toString(), equalTo("keyword"));

    client().prepareIndex("my-index", "my-type", "1").setSource("a", "complete me").setRefreshPolicy(IMMEDIATE).get();
    SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "complete me")).get();
    assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MultiFieldsIntegrationIT.java

示例9: testIpMultiField

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public void testIpMultiField() throws Exception {
    assertAcked(
            client().admin().indices().prepareCreate("my-index")
                    .addMapping("my-type", createMappingSource("ip"))
    );

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
    assertThat(aField.size(), equalTo(2));
    assertThat(aField.get("type").toString(), equalTo("ip"));
    assertThat(aField.get("fields"), notNullValue());

    Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
    assertThat(bField.size(), equalTo(1));
    assertThat(bField.get("type").toString(), equalTo("keyword"));

    client().prepareIndex("my-index", "my-type", "1").setSource("a", "127.0.0.1").setRefreshPolicy(IMMEDIATE).get();
    SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "127.0.0.1")).get();
    assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MultiFieldsIntegrationIT.java

示例10: testMappingMetaDataParsed

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public void testMappingMetaDataParsed() throws Exception {
    logger.info("--> starting 1 nodes");
    internalCluster().startNode();

    logger.info("--> creating test index, with meta routing");
    client().admin().indices().prepareCreate("test")
            .addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing")
                .field("required", true).endObject().endObject().endObject())
            .execute().actionGet();

    logger.info("--> verify meta _routing required exists");
    MappingMetaData mappingMd = client().admin().cluster().prepareState().execute().actionGet().getState().metaData()
        .index("test").mapping("type1");
    assertThat(mappingMd.routing().required(), equalTo(true));

    logger.info("--> restarting nodes...");
    internalCluster().fullRestart();

    logger.info("--> waiting for yellow status");
    ensureYellow();

    logger.info("--> verify meta _routing required exists");
    mappingMd = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().index("test").mapping("type1");
    assertThat(mappingMd.routing().required(), equalTo(true));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:GatewayIndexStateIT.java

示例11: testCustomDefaultMapping

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
/**
 * Tests that putting custom default mapping and then putting a type mapping will have the default mapping merged
 * to the type mapping.
 */
public void testCustomDefaultMapping() throws Exception {
    logger.info("--> start master node / non data");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));

    logger.info("--> start data node / non master node");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false));

    createIndex("test");
    assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));

    MappingMetaData defaultMapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("_default_");
    Map<?,?> properties = (Map<?, ?>) defaultMapping.getSourceAsMap().get("properties");
    assertThat(properties.get("timestamp"), notNullValue());

    assertAcked(client().admin().indices().preparePutMapping("test").setType("_default_").setSource("timestamp", "type=date"));

    assertAcked(client().admin().indices().preparePutMapping("test").setType("type1").setSource("foo", "enabled=true"));
    MappingMetaData type1Mapping = client().admin().cluster().prepareState().get().getState().getMetaData().getIndices().get("test").getMappings().get("type1");
    properties = (Map<?, ?>) type1Mapping.getSourceAsMap().get("properties");
    assertThat(properties.get("timestamp"), notNullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SpecificMasterNodesIT.java

示例12: buildValuesMap

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
@Nullable
private static Map<String, Object> buildValuesMap(PartitionName partitionName, MappingMetaData mappingMetaData) throws Exception{
    int i = 0;
    Map<String, Object> valuesMap = new HashMap<>();
    Iterable<Tuple<ColumnIdent, DataType>> partitionColumnInfoIterable = PartitionedByMappingExtractor.extractPartitionedByColumns(mappingMetaData.sourceAsMap());
    for (Tuple<ColumnIdent, DataType> columnInfo : partitionColumnInfoIterable) {
        String columnName = columnInfo.v1().sqlFqn();
        // produce string type values as string, not bytesref
        Object value = BytesRefs.toString(partitionName.values().get(i));
        if (!columnInfo.v2().equals(DataTypes.STRING)) {
            value = columnInfo.v2().value(value);
        }
        valuesMap.put(columnName, value);
        i++;
    }
    return valuesMap;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:PartitionInfos.java

示例13: readFrom

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < size; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
        for (int j = 0; j < valueSize; j++) {
            typeMapBuilder.put(in.readString(), MappingMetaData.PROTO.readFrom(in));
        }
        indexMapBuilder.put(key, typeMapBuilder.build());
    }
    mappings = indexMapBuilder.build();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:GetMappingsResponse.java

示例14: GetIndexResponse

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
GetIndexResponse(String[] indices, ImmutableOpenMap<String, List<IndexWarmersMetaData.Entry>> warmers,
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings,
        ImmutableOpenMap<String, List<AliasMetaData>> aliases, ImmutableOpenMap<String, Settings> settings) {
    this.indices = indices;
    if (warmers != null) {
        this.warmers = warmers;
    }
    if (mappings != null) {
        this.mappings = mappings;
    }
    if (aliases != null) {
        this.aliases = aliases;
    }
    if (settings != null) {
        this.settings = settings;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:GetIndexResponse.java

示例15: resolveAndValidateRouting

import org.elasticsearch.cluster.metadata.MappingMetaData; //导入依赖的package包/类
public static void resolveAndValidateRouting(final MetaData metaData, String concreteIndex, DeleteRequest request) {
    request.routing(metaData.resolveIndexRouting(request.routing(), request.index()));
    if (metaData.hasIndex(concreteIndex)) {
        // check if routing is required, if so, throw error if routing wasn't specified
        MappingMetaData mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
        if (mappingMd != null && mappingMd.routing().required()) {
            if (request.routing() == null) {
                if (request.versionType() != VersionType.INTERNAL) {
                    // TODO: implement this feature
                    throw new IllegalArgumentException("routing value is required for deleting documents of type [" + request.type()
                        + "] while using version_type [" + request.versionType() + "]");
                }
                throw new RoutingMissingException(concreteIndex, request.type(), request.id());
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportDeleteAction.java


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