本文整理汇总了Java中org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetMappingsRequest类的具体用法?Java GetMappingsRequest怎么用?Java GetMappingsRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetMappingsRequest类属于org.elasticsearch.action.admin.indices.mapping.get包,在下文中一共展示了GetMappingsRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIndexTypeMapping
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public static Map<String, List<String>> getIndexTypeMapping() {
Map<String, List<String>> indexTypeMapping = new HashMap<String, List<String>>();
List<String> typeList = null;
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> f = ESReport.getESClient().admin().indices().getMappings(new GetMappingsRequest()).actionGet().getMappings();
Object[] indexList = f.keys().toArray();
for (Object indexObj : indexList) {
String index = indexObj.toString();
ImmutableOpenMap<String, MappingMetaData> mapping = f.get(index);
typeList = new ArrayList<String>();
ClusterStateResponse resp = ESReport.getESClient().admin().cluster().prepareState().execute().actionGet();
ObjectLookupContainer<String> objectLookupContainer = resp.getState().metaData().index(index).getMappings().keys();
for(ObjectCursor<String> objectCursor:objectLookupContainer){
typeList.add(objectCursor.value);
}
indexTypeMapping.put(index, typeList);
}
return indexTypeMapping;
}
示例2: getTypeListWithPrefix
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的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;
}
示例3: createMapping
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的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;
}
示例4: should_create_index_with_mapping
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@Test
public void should_create_index_with_mapping() throws ExecutionException, InterruptedException {
String mapping = TestFilesUtils.readFromClasspath("com/github/obourgain/elasticsearch/http/handler/admin/indices/create_index_with_mapping.json");
CreateIndexResponse response = httpClient.admin().indices()
.createIndex(Requests.createIndexRequest(THE_INDEX)
.mapping(THE_TYPE, mapping))
.get();
Assertions.assertThat(response.isAcknowledged()).isTrue();
refresh();
GetMappingsResponse getMappingsResponse = transportClient.admin().indices().getMappings(new GetMappingsRequest().indices(THE_INDEX)).actionGet();
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> indexToMappings = getMappingsResponse.getMappings();
Assertions.assertThat(indexToMappings.iterator().hasNext()).isTrue();
Assertions.assertThat(indexToMappings.iterator().next().key).isEqualTo(THE_INDEX);
MappingMetaData actualMapping = indexToMappings.get(THE_INDEX).get(THE_TYPE);
assertMappingsEquals(mappingAsJsonToMap(mapping), actualMapping);
}
示例5: testIngestCreation
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@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();
}
}
示例6: testGetMappings
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public void testGetMappings() {
interceptTransportActions(GetMappingsAction.NAME);
GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().getMappings(getMappingsRequest).actionGet();
clearInterceptedActions();
assertSameIndices(getMappingsRequest, GetMappingsAction.NAME);
}
示例7: GetIndexMappings
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public ImmutableOpenMap<String, MappingMetaData> GetIndexMappings(Client client, String indexname)
throws UnknownHostException, InterruptedException, ExecutionException {
GetMappingsResponse res = client.admin().indices().getMappings(new GetMappingsRequest().indices(indexname))
.get();
mappingmetadata = res.mappings().get(indexname);
return mappingmetadata;
}
示例8: GetIndexMappings
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public ImmutableOpenMap<String, MappingMetaData> GetIndexMappings(Client client, String indexname) {
ImmutableOpenMap<String, MappingMetaData> mappingmetadata = null;
try {
GetMappingsResponse res = client.admin().indices().getMappings(new GetMappingsRequest().indices(indexname))
.get();
mappingmetadata = res.mappings().get(indexname);
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mappingmetadata;
}
示例9: CopyIndexMetadata
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public void CopyIndexMetadata(Client sourceclient, String sourceindex, Client targetclient, String targetindex)
throws UnknownHostException {
// TODO Auto-generated method stub
// 获取source settings
Settings.Builder settingbuilder = Settings.builder();
ClusterState cs = sourceclient.admin().cluster().prepareState().setIndices(sourceindex).execute().actionGet()
.getState();
IndexMetaData imd = cs.getMetaData().index(sourceindex);
Settings settings = imd.getSettings();
for (Map.Entry<String, String> m : settings.getAsMap().entrySet()) {
if (m.getKey().equals("index.uuid") || m.getKey().equals("index.version.created")
|| m.getKey().equals("index.creation_date")) {
continue;
} else {
settingbuilder.put(m.getKey(), m.getValue());
}
}
// 创建索引
targetclient.admin().indices().prepareCreate(targetindex).setSettings(settingbuilder).get();
// 获取source mappings并添加到target
try {
GetMappingsResponse res = sourceclient.admin().indices()
.getMappings(new GetMappingsRequest().indices(sourceindex)).get();
ImmutableOpenMap<String, MappingMetaData> mapping = res.mappings().get(sourceindex);
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
targetclient.admin().indices().preparePutMapping(targetindex).setType(c.key)
.setSource(c.value.getSourceAsMap()).get();
}
} catch (InterruptedException | ExecutionException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.info("Target index " + targetindex + " create complete!");
}
示例10: afterPropertiesSet
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
Map<String, String> map = new HashMap();
//基础名称
map.put("cluster.name", "my-application-A");
Settings.Builder settings = Settings.builder().put(map);
try {
transportClient = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
IndicesAdminClient indicesAdminClient = transportClient.admin().indices();
//查看索引是否存在,不存在就创建索引
if(!checkExistsIndex(indicesAdminClient,INDEX_NAME)){
indicesAdminClient.prepareCreate(INDEX_NAME).setSettings().execute().actionGet();
}
//查询mapping是否存在,已存在就不创建了
GetMappingsResponse getMappingsResponse = indicesAdminClient.getMappings(new GetMappingsRequest().indices(INDEX_NAME)).actionGet();
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> indexToMappings = getMappingsResponse.getMappings();
if(indexToMappings.get(INDEX_NAME).get(TIEABA_CONTENT_TYPE)==null) {
//创建zk分词mapping
PutMappingRequest mapping = Requests.putMappingRequest(INDEX_NAME).type(TIEABA_CONTENT_TYPE).source(createIKMapping(TIEABA_CONTENT_TYPE, TIEABA_CONTENT_FIELD).string());
mapping.updateAllTypes(true);
indicesAdminClient.putMapping(mapping).actionGet();
}
} catch (Exception e) {
log.error("初始化 elasticsearch cliet error"+e.getLocalizedMessage());
}
}
示例11: execute
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
public void execute(GetMappingsRequest request, final ActionListener<GetMappingsResponse> listener) {
// TODO tests
logger.debug("get mappings request {}", request);
try {
String indices = HttpRequestUtils.indicesOrAll(request);
RequestUriBuilder uriBuilder = new RequestUriBuilder(indices);
String types = Strings.arrayToCommaDelimitedString(request.types());
if (!types.isEmpty()) {
uriBuilder.type(types);
}
uriBuilder.addEndpoint("_mapping");
// lots of url patterns are accepted, but this one is the most practical for a generic impl
uriBuilder.addQueryParameter("master_timeout", request.masterNodeTimeout().toString());
indicesAdminClient.getHttpClient().submit(HttpClientRequest.createGet(uriBuilder.toString()))
.flatMap(HANDLES_404)
.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<GetMappingsResponse>>() {
@Override
public Observable<GetMappingsResponse> call(HttpClientResponse<ByteBuf> response) {
return response.getContent().flatMap(new Func1<ByteBuf, Observable<GetMappingsResponse>>() {
@Override
public Observable<GetMappingsResponse> call(ByteBuf byteBuf) {
return Observable.just(new GetMappingsResponse().parse
(byteBuf));
}
});
}
})
.single()
.subscribe(new ListenerCompleterObserver<>(listener));
} catch (Exception e) {
listener.onFailure(e);
}
}
示例12: should_put_mapping
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@Test
public void should_put_mapping() throws Exception {
String type = "test_type";
PutMappingRequest request = new PutMappingRequest(THE_INDEX)
.ignoreConflicts(true)
.type(type)
.source("{\n" +
" \"properties\" : {\n" +
" \"message\" : {\"type\" : \"string\", \"store\" : true }\n" +
" }\n" +
"}");
httpClient.admin().indices().putMapping(request).get();
GetMappingsResponse getMappingsResponse = transportClient.admin().indices().getMappings(new GetMappingsRequest().indices(THE_INDEX)).actionGet();
ImmutableOpenMap<String, MappingMetaData> mapping = getMappingsResponse.getMappings().get(THE_INDEX);
Assertions.assertThat(mapping.containsKey(type)).isTrue();
MappingMetaData mappingMetaData = mapping.get(type);
Map<String, Object> map = mappingMetaData.sourceAsMap();
Assertions.assertThat(map.containsKey("properties")).isTrue();
Assertions.assertThat(map.get("properties")).isInstanceOf(Map.class);
Map<String, Object> properties = (Map) map.get("properties");
Assertions.assertThat(properties.get("message")).isInstanceOf(Map.class);
Map<String, Object> message = (Map<String, Object>) properties.get("message");
Assertions.assertThat(message).contains(MapEntry.entry("type", "string"), MapEntry.entry("store", true));
}
示例13: should_get_empty_mappings
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@Test
public void should_get_empty_mappings() throws Exception {
createIndex("test_index_1", "test_index_2", "test_index_3");
GetMappingsResponse response = httpClient.admin().indices().getMappings(new GetMappingsRequest().indices("test_index_1", "test_index_2")).get();
Assertions.assertThat(response.getMappings()).hasSize(2)
.containsKey("test_index_1")
.containsKey("test_index_2");
}
示例14: should_get_random_mapping
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@Test
public void should_get_random_mapping() throws Exception {
createIndex("test_index_1", "test_index_2", "test_index_3");
transportClient.admin().indices().preparePutMapping("test_index_1", "test_index_2").setSource(Collections.singletonMap("twitter", Collections.emptyMap()));
transportClient.index(Requests.indexRequest().index("test_index_1").type(THE_TYPE).id(THE_ID).refresh(true)
.source(XContentFactory.jsonBuilder().startObject()
.field("the_string_field", "the_string_value")
.field("the_integer_field", 42)
.field("the_boolean_field", true)
.field("the_long_array_field", new Long[]{42L, 53L})
.endObject())
).actionGet();
transportClient.index(Requests.indexRequest().index("test_index_2").type(THE_TYPE).id(THE_ID).refresh(true)
.source(XContentFactory.jsonBuilder().startObject()
.field("the_string_field", "the_string_value")
.field("the_integer_field", 42)
.field("the_boolean_field", true)
.field("the_long_array_field", new Long[]{42L, 53L})
.endObject())
).actionGet();
GetMappingsResponse response = httpClient.admin().indices().getMappings(new GetMappingsRequest().indices("test_index_1", "test_index_2")).get();
Assertions.assertThat(response.getMappings())
.hasSize(2)
.containsKey("test_index_1")
.containsKey("test_index_2");
Map<String, MappingMetaData> test_index_1 = response.getMappings().get("test_index_1");
Assertions.assertThat(test_index_1).isNotEmpty();
Assertions.assertThat(response.getMappings().get("test_index_2")).isNotEmpty();
}
示例15: getDynamicFieldNames
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; //导入依赖的package包/类
@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;
}