本文整理汇总了Java中org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse类的典型用法代码示例。如果您正苦于以下问题:Java PutMappingResponse类的具体用法?Java PutMappingResponse怎么用?Java PutMappingResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PutMappingResponse类属于org.elasticsearch.action.admin.indices.mapping.put包,在下文中一共展示了PutMappingResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateMappingWithoutType
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的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\"}}}}"));
}
示例2: testUpdateMappingWithoutTypeMultiObjects
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的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\"}}}}"));
}
示例3: testUpdateMappingNoChanges
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
public void testUpdateMappingNoChanges() throws Exception {
client().admin().indices().prepareCreate("test")
.setSettings(
Settings.builder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 0)
).addMapping("type", "{\"type\":{\"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("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
.execute().actionGet();
//no changes, we return
assertThat(putMappingResponse.isAcknowledged(), equalTo(true));
}
示例4: testAddingParentToExistingMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的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]"));
}
}
示例5: testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() throws Exception {
String index = "foo";
String type = "mytype";
XContentBuilder builder =
jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
// check mapping again
assertSizeMappingEnabled(index, type, true);
// update some field in the mapping
XContentBuilder updateMappingBuilder =
jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "text")
.endObject().endObject().endObject();
PutMappingResponse putMappingResponse =
client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);
// make sure size field is still in mapping
assertSizeMappingEnabled(index, type, true);
}
示例6: testThatSizeCanBeSwitchedOnAndOff
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
String index = "foo";
String type = "mytype";
XContentBuilder builder =
jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
// check mapping again
assertSizeMappingEnabled(index, type, true);
// update some field in the mapping
XContentBuilder updateMappingBuilder =
jsonBuilder().startObject().startObject("_size").field("enabled", false).endObject().endObject();
PutMappingResponse putMappingResponse =
client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);
// make sure size field is still in mapping
assertSizeMappingEnabled(index, type, false);
}
示例7: testRefreshIndex
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
@Test
public void testRefreshIndex() {
// Test data
final String indexName = "Index_Name";
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final RefreshRequestBuilder refreshRequestBuilder = createMock(RefreshRequestBuilder.class);
final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
// Reset
resetAll();
// Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.prepareRefresh(indexName)).andReturn(refreshRequestBuilder);
expect(refreshRequestBuilder.get()).andReturn(createMock(RefreshResponse.class));
// Replay
replayAll();
// Run test scenario
elasticsearchClientWrapper.refreshIndex(indexName);
// Verify
verifyAll();
}
示例8: updateMappingOnMaster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
public void updateMappingOnMaster(String index, String type, Mapping mappingUpdate, final TimeValue timeout, final MappingUpdateListener listener) {
final PutMappingRequestBuilder request = updateMappingRequest(index, type, mappingUpdate, timeout);
if (listener == null) {
request.execute();
} else {
final ActionListener<PutMappingResponse> actionListener = new ActionListener<PutMappingResponse>() {
@Override
public void onResponse(PutMappingResponse response) {
if (response.isAcknowledged()) {
listener.onMappingUpdate();
} else {
listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]"));
}
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
};
request.execute(actionListener);
}
}
示例9: addOrUpdateMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
/**
* This method will update type and mapping under already created index.
*
* @param indexName String
* @param typeName String
* @param mapping String
* @return boolean
*/
@SuppressWarnings("deprecation")
public static boolean addOrUpdateMapping(String indexName, String typeName, String mapping) {
try {
PutMappingResponse response = ConnectionManager.getClient().admin().indices()
.preparePutMapping(indexName)
.setType(typeName).setSource(mapping).get();
if (response.isAcknowledged()) {
return true;
}
} catch (Exception e) {
ProjectLogger.log(e.getMessage(), e);
}
return false;
}
示例10: internalPutMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的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;
}
示例11: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的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;
}
示例12: setUp
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
if (client.admin().indices().prepareExists(getIndexName()).execute().actionGet().isExists()) {
DeleteIndexResponse deleteIndexResponse = client.admin().indices().prepareDelete(getIndexName())
.execute().actionGet();
Assert.assertTrue(deleteIndexResponse.isAcknowledged());
}
CreateIndexResponse createIndexResponse = client.admin().indices().prepareCreate(getIndexName())
.execute().actionGet();
Assert.assertTrue(createIndexResponse.isAcknowledged());
for (Map.Entry<String, String> esMapping : getEsMappings().entrySet()) {
String esMappingSource = IOUtils.toString(
AbstractEsTest.class.getClassLoader().getResourceAsStream(esMapping.getValue()));
PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(getIndexName())
.setType(esMapping.getKey()).setSource(esMappingSource).execute().actionGet();
Assert.assertTrue(putMappingResponse.isAcknowledged());
}
}
示例13: testPutMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
@Test
public void testPutMapping() {
String mapping = "" +
"{\n" +
" \"the_mapping\" : {\n" +
" \"properties\" : {\n" +
" \"name\" : {\n" +
" \"type\" : \"string\",\n" +
" \"analyzer\" : \"standard\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}" +
"";
PutMappingResponse putMappingResponse = operations.putMapping(mapping, "the_mapping").actionGet();
Assertions.assertThat(putMappingResponse.isAcknowledged()).isTrue();
}
示例14: putMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
@Override
public PutMappingResponse putMapping(Class clazz, String mapping) {
String typeName = MappingProcessor.getIndexTypeName(clazz);
if (logger.isDebugEnabled()) {
logger.debug("Put mapping for class: {}, type: {}, mapping: {}", clazz.getSimpleName(), typeName, mapping);
}
PutMappingResponse response = client.admin().indices().preparePutMapping(getIndexName()).setType(typeName).setSource(mapping).get();
if (!cache.isExist(CacheType.MAPPING, clazz)) {
cache.putCache(CacheType.MAPPING, clazz, mapping);
}
return response;
}
示例15: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入依赖的package包/类
public boolean createMapping(Class<?> mappingClass) {
this.startElasticSearchClient();
if (!EsIndexDataStructure.indexExist(this.clientElasticSearch, mappingClass)) {
ESIndex annotation = mappingClass.getAnnotation(ESIndex.class);
String message = "Index %s does not exist. You must create it before you create a type.";
message = message.replaceFirst("%s", (annotation == null ? "" : annotation.name()));
throw new RuntimeException(message);
}
PutMappingResponse response = EsIndexDataStructure.createMapping(this.clientElasticSearch, mappingClass);
if (this.configurationElasticSearch.isAutomaticClientClose()) {
this.shutdownElasticSearchClient();
}
return (response != null) ? response.isAcknowledged() : false;
}