本文整理汇总了Java中org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest类的典型用法代码示例。如果您正苦于以下问题:Java PutMappingRequest类的具体用法?Java PutMappingRequest怎么用?Java PutMappingRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PutMappingRequest类属于org.elasticsearch.action.admin.indices.mapping.put包,在下文中一共展示了PutMappingRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initializeAdditionalMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
similarity = randomFrom("classic", "BM25");
mapperService.merge(PARENT_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
STRING_FIELD_NAME_2, "type=keyword",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge(CHILD_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(CHILD_TYPE,
"_parent", "type=" + PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
"custom_string", "type=text,similarity=" + similarity,
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:HasChildQueryBuilderTests.java
示例2: testDisabledFieldNamesField
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
public void testDisabledFieldNamesField() throws Exception {
QueryShardContext context = createShardContext();
context.getMapperService().merge("new_type",
new CompressedXContent(
PutMappingRequest.buildFromSimplifiedDef("new_type",
"foo", "type=text",
"_field_names", "enabled=false").string()),
MapperService.MergeReason.MAPPING_UPDATE, true);
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder("foo:*");
Query query = queryBuilder.toQuery(context);
Query expected = new WildcardQuery(new Term("foo", "*"));
assertThat(query, equalTo(expected));
context.getMapperService().merge("new_type",
new CompressedXContent(
PutMappingRequest.buildFromSimplifiedDef("new_type",
"foo", "type=text",
"_field_names", "enabled=true").string()),
MapperService.MergeReason.MAPPING_UPDATE, true);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:QueryStringQueryBuilderTests.java
示例3: initializeAdditionalMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge(PARENT_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge(CHILD_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(CHILD_TYPE,
"_parent", "type=" + PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ParentIdQueryBuilderTests.java
示例4: initializeAdditionalMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge(PARENT_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
STRING_FIELD_NAME_2, "type=keyword",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge(CHILD_TYPE, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(CHILD_TYPE,
"_parent", "type=" + PARENT_TYPE,
STRING_FIELD_NAME, "type=text",
STRING_FIELD_NAME_2, "type=keyword",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge("just_a_type", new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef("just_a_type"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:HasParentQueryBuilderTests.java
示例5: internalPutMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
private static PutMappingResponse internalPutMapping(Client client, String indexName, IElasticSearchMapping mapping) throws IOException {
final PutMappingRequest putMappingRequest = new PutMappingRequest(indexName)
.type(mapping.getIndexType())
.source(mapping.getMapping().string());
final PutMappingResponse putMappingResponse = client
.admin()
.indices()
.putMapping(putMappingRequest)
.actionGet();
if(log.isDebugEnabled()) {
log.debug("PutMappingResponse: isAcknowledged {}", putMappingResponse.isAcknowledged());
}
return putMappingResponse;
}
开发者ID:bytefish,项目名称:ElasticUtils,代码行数:19,代码来源:ElasticSearchUtils.java
示例6: zkfc
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
private static SearchResponse zkfc(String indexName, String zkType, TransportClient client) throws IOException {
//返回一个可以执行管理性操作的客户端
//1) cluster(),产生一个允许从集群中执行action或操作的client;
//2) indices(),产生一个允许从索引中执行action或操作的client。
//创建zk分词
PutMappingRequest mapping = Requests.putMappingRequest(indexName).type(zkType).source(createIKMapping(zkType).string());
client.admin().indices().putMapping(mapping).actionGet();
Goods goodsOne= new Goods( 1,"iphone7 iphone7plus 钢化膜 玻璃膜 苹果 苹果7/7plus 贴膜 买就送清水","http://m.ule.com/item/detail/1771161");
Goods goodsTwo=new Goods( 2,"苹果 (Apple) iPhone 7 移动联通电信4G手机 土豪金 32G 标配","http://m.ule.com/item/detail/1799356");
Goods goodsThree=new Goods( 3,"苹果 Apple iPhone 7 (A1660) 128G 金色 移动联通电信 全网通 4G手机","http://m.ule.com/item/detail/1781429");
client.prepareIndex(indexName,zkType).setId(1+"").setSource(JSONObject.toJSONString(goodsOne)).execute().actionGet();
client.prepareIndex(indexName,zkType).setId(2+"").setSource(JSONObject.toJSONString(goodsTwo)).execute().actionGet();
client.prepareIndex(indexName,zkType).setId(3+"").setSource(JSONObject.toJSONString(goodsThree)).execute().actionGet();
SearchResponse response = client.prepareSearch(indexName)
.setTypes(zkType)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery( QueryBuilders.matchQuery("title", "苹果")
).execute().actionGet();
return response;
}
开发者ID:ggj2010,项目名称:javabase,代码行数:22,代码来源:SearchDemo.java
示例7: initCluster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:22,代码来源:ConfigurationAnalyzerIntegrationTest.java
示例8: initCluster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@BeforeClass
public void initCluster() throws IOException {
client = getClient();
CreateIndexRequest indexRequest = new CreateIndexRequest(INDEX_NAME);
assertTrue(client.admin().indices().create(indexRequest).actionGet().isAcknowledged());
String mapping = ResourceUtils.asString("mapping_request.json");
PutMappingRequestBuilder builder = new PutMappingRequestBuilder(client, PutMappingAction.INSTANCE);
PutMappingRequest request = builder.setIndices(INDEX_NAME).setType(INDEX_TYPE).setSource(mapping).request();
assertTrue(client.admin().indices().putMapping(request).actionGet().isAcknowledged());
String doc01 = ResourceUtils.asString("documents/doc01.json");
String doc02 = ResourceUtils.asString("documents/doc02.json");
IndexRequestBuilder indexBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE, INDEX_NAME).setType(INDEX_TYPE);
assertTrue(client.index(indexBuilder.setId("1").setSource(doc01).request()).actionGet().isCreated());
assertTrue(client.index(indexBuilder.setId("2").setSource(doc02).request()).actionGet().isCreated());
client.admin().indices().flush(new FlushRequest(INDEX_NAME)).actionGet();
defaultProperties = new DefaultProperties("default.properties");
}
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:20,代码来源:StatsCollectorIntegrationTest.java
示例9: executeBlocking
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
private void executeBlocking(final ActionRequest action) {
try {
if (action instanceof PutMappingRequest) {
getDataContext().getElasticSearchClient().createMapping((PutMappingRequest) action);
} else {
final ActionResponse result = getDataContext().getElasticSearchClient().execute(action);
if (result instanceof BulkResponse && ((BulkResponse) result).hasFailures()) {
BulkItemResponse[] failedItems = ((BulkResponse) result).getItems();
for (int i = 0; i < failedItems.length; i++) {
if (failedItems[i].isFailed()) {
final BulkItemResponse failedItem = failedItems[i];
logger.error("Bulk failed with item no. {} of {}: id={} op={} status={} error={}", i + 1,
failedItems.length, failedItem.getId(), failedItem.getOpType(), failedItem.status(),
failedItem.getFailureMessage());
}
}
}
}
} catch (IOException e) {
logger.warn("Could not execute command {} ", action, e);
throw new MetaModelException("Could not execute " + action, e);
}
}
开发者ID:apache,项目名称:metamodel,代码行数:25,代码来源:ElasticSearchRestUpdateCallback.java
示例10: initializeAdditionalMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
queryField = randomAsciiOfLength(4);
docType = randomAsciiOfLength(4);
mapperService.merge("query_type", new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef("query_type",
queryField, "type=percolator"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge(docType, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(docType,
STRING_FIELD_NAME, "type=text"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:PercolateQueryBuilderTests.java
示例11: prepareRequest
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
putMappingRequest.type(request.param("type"));
putMappingRequest.source(request.content(), request.getXContentType());
putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false));
putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout()));
putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout()));
putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions()));
return channel -> client.admin().indices().putMapping(putMappingRequest, new AcknowledgedRestListener<>(channel));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:RestPutMappingAction.java
示例12: initializeAdditionalMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge("nested_doc", new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef("nested_doc",
STRING_FIELD_NAME, "type=text",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date",
OBJECT_FIELD_NAME, "type=object",
GEO_POINT_FIELD_NAME, "type=geo_point",
"nested1", "type=nested"
).string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:NestedQueryBuilderTests.java
示例13: testPutMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
public void testPutMapping() {
interceptTransportActions(PutMappingAction.NAME);
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases())
.type("type")
.source("field", "type=text");
internalCluster().coordOnlyNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();
clearInterceptedActions();
assertSameIndices(putMappingRequest, PutMappingAction.NAME);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:IndicesRequestIT.java
示例14: handleRequest
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
putMappingRequest.type(request.param("type"));
putMappingRequest.source(request.content().toUtf8());
putMappingRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false));
putMappingRequest.reindex(request.paramAsBoolean("reindex", false));
putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout()));
putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout()));
putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions()));
client.admin().indices().putMapping(putMappingRequest, new AcknowledgedRestListener<PutMappingResponse>(channel));
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:RestPutMappingAction.java
示例15: testCreateMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
@Test
public void testCreateMapping() throws Exception {
PutMappingRequest putMappingRequest = new PutMappingRequest();
putMappingRequest.indices("blog");
putMappingRequest.type("");
client.admin().indices().putMapping(putMappingRequest);
}
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:8,代码来源:IndexDemo.java
示例16: bulkProcess
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
/**
* 批量添加索引
* @throws Exception
*/
public static void bulkProcess(IndexNameEnum indexName, IndexTypeEnum indexType, String... args) throws Exception {
Client c = ESUtils.getClientInstance();
if (null == c) {
return;
}
//判断索引是否存在
if( !isExistsIndex(indexName.getName()) ){
XContentBuilder settings = null;
if(indexName.getName().equals(IndexNameEnum.FILE_PROP.getName())){
settings = FileIndexSchema.getFileIndexSetting();
System.out.println(settings.string());
}
c.admin().indices().prepareCreate(indexName.getName()).setSettings(settings).execute().actionGet();
}
XContentBuilder schema = SchemaFactory.create(indexName, indexType);
if(null == schema){
return;
}
//判断类型是否存在
if( !isExistsIndexAndType(indexName.getName(), indexType.getName()) ){
PutMappingRequest mapping = Requests.putMappingRequest(indexName.getName()).type(indexType.getName()).source(schema);
c.admin().indices().putMapping(mapping).actionGet();
}
//判断填充哪部分索引
if(indexName.getName().equals(IndexNameEnum.FILE_PROP.getName())){
//第二个参数为路径
FileIndexDataSource.putDataSource(c, args[0]);
}
}
开发者ID:clw87,项目名称:fileadmin,代码行数:40,代码来源:ESIndexBuilder.java
示例17: afterPropertiesSet
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的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());
}
}
开发者ID:ggj2010,项目名称:javabase,代码行数:29,代码来源:ElasticSearch.java
示例18: indexMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
/**
*
* @param indicesAdminClient
* @param indexName
* @param typeName
* @throws IOException
*/
private static void indexMapping(IndicesAdminClient indicesAdminClient, String indexName, String typeName) throws IOException {
//type就相当于表的
String typeSource=getIndexTypeSource(typeName,FIELD_NAME);
//typetwo
PutMappingRequest mapping = Requests.putMappingRequest(indexName).type(typeName).source("typeSource");
PutMappingResponse putMappingResponseTwo = indicesAdminClient.putMapping(mapping).actionGet();
}
开发者ID:ggj2010,项目名称:javabase,代码行数:16,代码来源:CrudDemo.java
示例19: execute
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的package包/类
public void execute(PutMappingRequest request, final ActionListener<PutMappingResponse> listener) {
logger.debug("put mapping request {}", request);
try {
String indices = HttpRequestUtils.indicesOrAll(request);
RequestUriBuilder uriBuilder = new RequestUriBuilder(indices, request.type()).addEndpoint("_mapping");
uriBuilder.addIndicesOptions(request);
uriBuilder.addQueryParameter("ignore_conflicts", request.ignoreConflicts());
uriBuilder.addQueryParameter("timeout", request.timeout().toString());
uriBuilder.addQueryParameter("master_timeout", request.masterNodeTimeout().toString());
indicesAdminClient.getHttpClient().submit(HttpClientRequest.createPost(uriBuilder.toString())
.withContent(request.source()))
.flatMap(ErrorHandler.AS_FUNC)
.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<PutMappingResponse>>() {
@Override
public Observable<PutMappingResponse> call(final HttpClientResponse<ByteBuf> response) {
return response.getContent().flatMap(new Func1<ByteBuf, Observable<PutMappingResponse>>() {
@Override
public Observable<PutMappingResponse> call(ByteBuf byteBuf) {
return PutMappingResponse.parse(byteBuf, response.getStatus().code());
}
});
}
})
.single()
.subscribe(new ListenerCompleterObserver<>(listener));
} catch (Exception e) {
listener.onFailure(e);
}
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:33,代码来源:PutMappingActionHandler.java
示例20: should_put_mapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; //导入依赖的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));
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:34,代码来源:PutMappingActionHandlerTest.java
注:本文中的org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论