org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IngestIndexCreationTest.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@Test
public void testIngestCreation() throws Exception {
    Settings settingsForIndex = Settings.settingsBuilder()
            .put("index.number_of_shards", 1)
            .build();
    Map<String,String> mappings = new HashMap<>();
    mappings.put("typename","{\"properties\":{\"message\":{\"type\":\"string\"}}}");
    final IngestTransportClient ingest = ClientBuilder.builder()
            .put(getSettings())
            .setMetric(new LongAdderIngestMetric())
            .toIngestTransportClient();
    try {
        ingest.newIndex("test", settingsForIndex, mappings);
        GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices("test");
        GetMappingsResponse getMappingsResponse =
                ingest.client().execute(GetMappingsAction.INSTANCE, getMappingsRequest).actionGet();
        MappingMetaData md = getMappingsResponse.getMappings().get("test").get("typename");
        assertEquals("{properties={message={type=string}}}", md.getSourceAsMap().toString());
    } finally {
        ingest.shutdown();
    }
}
 
Example #2
Source File: ElasticSearchEngine.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getDynamicFieldNames() throws SearchEngineException {
	List<String> fieldNames = new LinkedList<>();

	try {
		GetMappingsRequest req =
				new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE, configuration.getIndexName())
						.setTypes(configuration.getDocType())
						.request();
		GetMappingsResponse response = client.admin().indices().getMappings(req).actionGet();
		MappingMetaData metaData = response.getMappings()
				.get(configuration.getIndexName())
				.get(configuration.getDocType());
		Map<String, Object> sourceMap = metaData.getSourceAsMap();
		Object annotationField = ((Map)sourceMap.get("properties")).get(configuration.getAnnotationField());
		Map<String, Object> annotationProperties = (Map<String, Object>)((Map)annotationField).get("properties");

		if (annotationProperties != null) {
			for (String field : annotationProperties.keySet()) {
				if (field.matches(DYNAMIC_LABEL_FIELD_REGEX)) {
					fieldNames.add(field);
				}
			}
		}
	} catch (IOException e) {
		LOGGER.error("Caught IOException retrieving field source: {}", e.getMessage());
		throw new SearchEngineException(e);
	}

	return fieldNames;
}