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


Java GetMappingsResponse类代码示例

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


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

示例1: loadExistingMappingIntoIndexInfo

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的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

示例2: assertMappingOnMaster

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的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

示例3: testGetMappingsWithBlocks

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testGetMappingsWithBlocks() throws IOException {
    client().admin().indices().prepareCreate("test")
            .addMapping("typeA", getMappingForType("typeA"))
            .addMapping("typeB", getMappingForType("typeB"))
            .execute().actionGet();
    ensureGreen();

    for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) {
        try {
            enableIndexBlock("test", block);
            GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
            assertThat(response.mappings().size(), equalTo(1));
            assertThat(response.mappings().get("test").size(), equalTo(2));
        } finally {
            disableIndexBlock("test", block);
        }
    }

    try {
        enableIndexBlock("test", SETTING_BLOCKS_METADATA);
        assertBlocked(client().admin().indices().prepareGetMappings(), INDEX_METADATA_BLOCK);
    } finally {
        disableIndexBlock("test", SETTING_BLOCKS_METADATA);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SimpleGetMappingsIT.java

示例4: testUpdateMappingWithoutType

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testUpdateMappingWithoutType() throws Exception {
    client().admin().indices().prepareCreate("test")
            .setSettings(
                    Settings.builder()
                            .put("index.number_of_shards", 1)
                            .put("index.number_of_replicas", 0)
            ).addMapping("doc", "{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
            .execute().actionGet();
    client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();

    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("doc")
            .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
            .execute().actionGet();

    assertThat(putMappingResponse.isAcknowledged(), equalTo(true));

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet();
    assertThat(getMappingsResponse.mappings().get("test").get("doc").source().toString(),
            equalTo("{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"},\"date\":{\"type\":\"integer\"}}}}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:UpdateMappingIntegrationIT.java

示例5: testUpdateMappingWithoutTypeMultiObjects

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testUpdateMappingWithoutTypeMultiObjects() throws Exception {
    client().admin().indices().prepareCreate("test")
            .setSettings(
                    Settings.builder()
                            .put("index.number_of_shards", 1)
                            .put("index.number_of_replicas", 0)
            ).execute().actionGet();
    client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();

    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("doc")
            .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)
            .execute().actionGet();

    assertThat(putMappingResponse.isAcknowledged(), equalTo(true));

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet();
    assertThat(getMappingsResponse.mappings().get("test").get("doc").source().toString(),
            equalTo("{\"doc\":{\"properties\":{\"date\":{\"type\":\"integer\"}}}}"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:UpdateMappingIntegrationIT.java

示例6: testAddingParentToExistingMapping

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testAddingParentToExistingMapping() throws IOException {
    createIndex("test");
    ensureGreen();

    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource("number", "type=integer")
            .get();
    assertThat(putMappingResponse.isAcknowledged(), equalTo(true));

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").get();
    Map<String, Object> mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap();
    assertThat(mapping.size(), greaterThanOrEqualTo(1)); // there are potentially some meta fields configured randomly
    assertThat(mapping.get("properties"), notNullValue());

    try {
        // Adding _parent metadata field to existing mapping is prohibited:
        client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
                .startObject("_parent").field("type", "parent").endObject()
                .endObject().endObject()).get();
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.toString(), containsString("The _parent field's type option can't be changed: [null]->[parent]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:ChildQuerySearchIT.java

示例7: testMappingsPropagatedToMasterNodeImmediately

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testMappingsPropagatedToMasterNodeImmediately() throws IOException {
    createIndex("index");

    // works when the type has been dynamically created
    client().prepareIndex("index", "type", "1").setSource("foo", 3).get();
    GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get();
    assertMappingsHaveField(mappings, "index", "type", "foo");

    // works if the type already existed
    client().prepareIndex("index", "type", "1").setSource("bar", "baz").get();
    mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get();
    assertMappingsHaveField(mappings, "index", "type", "bar");

    // works if we indexed an empty document
    client().prepareIndex("index", "type2", "1").setSource().get();
    mappings = client().admin().indices().prepareGetMappings("index").setTypes("type2").get();
    assertTrue(mappings.getMappings().get("index").toString(), mappings.getMappings().get("index").containsKey("type2"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:DynamicMappingIT.java

示例8: testTypeNotCreatedOnIndexFailure

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public void testTypeNotCreatedOnIndexFailure() throws IOException, InterruptedException {
    XContentBuilder mapping = jsonBuilder().startObject().startObject("_default_")
            .field("dynamic", "strict")
            .endObject().endObject();

    IndexService indexService = createIndex("test", Settings.EMPTY, "_default_", mapping);

    try {
        client().prepareIndex().setIndex("test").setType("type").setSource(jsonBuilder().startObject().field("test", "test").endObject()).get();
        fail();
    } catch (StrictDynamicMappingException e) {

    }

    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").get();
    assertNull(getMappingsResponse.getMappings().get("test").get("type"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:DynamicMappingTests.java

示例9: testCompletionMultiField

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的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

示例10: testIpMultiField

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的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

示例11: getTypeListWithPrefix

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public List<String> getTypeListWithPrefix(Object object, Object object2) {
  ArrayList<String> typeList = new ArrayList<>();
  GetMappingsResponse res;
  try {
    res = getClient().admin().indices().getMappings(new GetMappingsRequest().indices(object.toString())).get();
    ImmutableOpenMap<String, MappingMetaData> mapping = res.mappings().get(object.toString());
    for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
      if (c.key.startsWith(object2.toString())) {
        typeList.add(c.key);
      }
    }
  } catch (InterruptedException | ExecutionException e) {
    LOG.error("Error whilst obtaining type list from Elasticsearch mappings.", e);
  }
  return typeList;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:17,代码来源:ESDriver.java

示例12: createMapping

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public boolean createMapping(Class<?> docType) {
	Mapping mapping = getMappingFromClass(docType);
	IndicesAdminClient idc = client.admin().indices();
	GetMappingsResponse gmr = idc.getMappings(new GetMappingsRequest()).actionGet();
	ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = gmr.getMappings();
	if (mappings.containsKey(mapping.getType())) {
		log.info("Found mapping for class " + docType.getName() + ".");
		return false;
	}
	log.info("Mapping not found for class " + docType.getName() + ". Auto-create...");
	PutMappingResponse pmr = idc.preparePutMapping(index).setType(mapping.getType()).setSource(mapping.getSource())
			.get();
	if (!pmr.isAcknowledged()) {
		throw new RuntimeException("Failed to create mapping for class:" + docType.getName() + ".");
	}
	return true;
}
 
开发者ID:michaelliao,项目名称:es-wrapper,代码行数:18,代码来源:SearchableClient.java

示例13: loadExistingMappingIntoIndexInfo

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的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 VertexiumException("Could not load type mappings", ex);
    }
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:23,代码来源:Elasticsearch5SearchIndex.java

示例14: collectIndex

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
public List<IndexTypeMetadata> collectIndex(String indexName) throws IOException {
	GetMappingsResponse response = client.admin().indices().prepareGetMappings(indexName).get();
	ImmutableOpenMap<String, MappingMetaData> mapping = response.getMappings().get(indexName);
	String[] indexTypes = mapping.keys().toArray(String.class);
	ObjectMapper mapper = new ObjectMapper();
	List<IndexTypeMetadata> typesMetadata = new ArrayList<>();
	FieldAnalyzer analyzer = new FieldAnalyzer(client, indexName, props);
	for(String indexType : indexTypes) {
		MappingMetaData meta = mapping.get(indexType);
		LOGGER.info("Index: {} Type: {}", indexName, indexType);
		String mappingsAsJson = meta.source().string();
		LOGGER.debug("JSON:\n{}", mappingsAsJson);

		JsonNode root = mapper.readValue(mappingsAsJson, JsonNode.class);
		JsonNode typeProp = root.path(indexType).path(PROPERTIES_PROP);
		ObjectTypeMetadata typeMeta = parseConfiguration(analyzer, typeProp, StringUtils.EMPTY, false);
		typesMetadata.add(new IndexTypeMetadata(indexName, indexType, typeMeta.getInnerMetadata()));
	}
	return typesMetadata;
}
 
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:21,代码来源:StatsCollector.java

示例15: setup

import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; //导入依赖的package包/类
/**
 * @param indices The names of all indices that will exist.
 * @param mappings The index mappings.
 * @return An object to test.
 */
public ElasticsearchColumnMetadataDao setup(
        String[] indices,
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {

  AdminClient adminClient = mock(AdminClient.class);
  IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
  GetIndexRequestBuilder getIndexRequestBuilder = mock(GetIndexRequestBuilder.class);
  GetIndexResponse getIndexResponse = mock(GetIndexResponse.class);
  ActionFuture getMappingsActionFuture = mock(ActionFuture.class);
  GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class);

  // setup the mocks so that a set of indices are available to the DAO
  when(adminClient.indices()).thenReturn(indicesAdminClient);
  when(indicesAdminClient.prepareGetIndex()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.setFeatures()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.get()).thenReturn(getIndexResponse);
  when(getIndexResponse.getIndices()).thenReturn(indices);

  // setup the mocks so that a set of mappings are available to the DAO
  when(indicesAdminClient.getMappings(any())).thenReturn(getMappingsActionFuture);
  when(getMappingsActionFuture.actionGet()).thenReturn(getMappingsResponse);
  when(getMappingsResponse.getMappings()).thenReturn(mappings);

  return new ElasticsearchColumnMetadataDao(adminClient);
}
 
开发者ID:apache,项目名称:metron,代码行数:31,代码来源:ElasticsearchColumnMetadataDaoTest.java


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