use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingOnClusterIT method compareMappingOnNodes.
private void compareMappingOnNodes(GetMappingsResponse previousMapping) {
// make sure all nodes have same cluster state
for (Client client : cluster().getClients()) {
GetMappingsResponse currentMapping = client.admin().indices().prepareGetMappings(INDEX).addTypes(TYPE).setLocal(true).get();
assertThat(previousMapping.getMappings().get(INDEX).get(TYPE).source(), equalTo(currentMapping.getMappings().get(INDEX).get(TYPE).source()));
}
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingIntegrationIT method testUpdateMappingWithoutType.
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\"}}}}"));
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingIntegrationIT method testUpdateDefaultMappingSettings.
@SuppressWarnings("unchecked")
public void testUpdateDefaultMappingSettings() throws Exception {
logger.info("Creating index with _default_ mappings");
client().admin().indices().prepareCreate("test").addMapping(MapperService.DEFAULT_MAPPING, JsonXContent.contentBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING).field("date_detection", false).endObject().endObject()).get();
GetMappingsResponse getResponse = client().admin().indices().prepareGetMappings("test").addTypes(MapperService.DEFAULT_MAPPING).get();
Map<String, Object> defaultMapping = getResponse.getMappings().get("test").get(MapperService.DEFAULT_MAPPING).sourceAsMap();
assertThat(defaultMapping, hasKey("date_detection"));
logger.info("Emptying _default_ mappings");
// now remove it
PutMappingResponse putResponse = client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(JsonXContent.contentBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING).endObject().endObject()).get();
assertThat(putResponse.isAcknowledged(), equalTo(true));
logger.info("Done Emptying _default_ mappings");
getResponse = client().admin().indices().prepareGetMappings("test").addTypes(MapperService.DEFAULT_MAPPING).get();
defaultMapping = getResponse.getMappings().get("test").get(MapperService.DEFAULT_MAPPING).sourceAsMap();
assertThat(defaultMapping, not(hasKey("date_detection")));
// now test you can change stuff that are normally unchangeable
logger.info("Creating _default_ mappings with an analyzed field");
putResponse = client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(JsonXContent.contentBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING).startObject("properties").startObject("f").field("type", "text").field("index", true).endObject().endObject().endObject().endObject()).get();
assertThat(putResponse.isAcknowledged(), equalTo(true));
logger.info("Changing _default_ mappings field from analyzed to non-analyzed");
putResponse = client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(JsonXContent.contentBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING).startObject("properties").startObject("f").field("type", "keyword").endObject().endObject().endObject().endObject()).get();
assertThat(putResponse.isAcknowledged(), equalTo(true));
logger.info("Done changing _default_ mappings field from analyzed to non-analyzed");
getResponse = client().admin().indices().prepareGetMappings("test").addTypes(MapperService.DEFAULT_MAPPING).get();
defaultMapping = getResponse.getMappings().get("test").get(MapperService.DEFAULT_MAPPING).sourceAsMap();
Map<String, Object> fieldSettings = (Map<String, Object>) ((Map) defaultMapping.get("properties")).get("f");
assertThat(fieldSettings, hasEntry("type", (Object) "keyword"));
// but we still validate the _default_ type
logger.info("Confirming _default_ mappings validation");
assertThrows(client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(JsonXContent.contentBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING).startObject("properties").startObject("f").field("type", "DOESNT_EXIST").endObject().endObject().endObject().endObject()), MapperParsingException.class);
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingIntegrationIT method testUpdateMappingOnAllTypes.
public void testUpdateMappingOnAllTypes() throws IOException {
assertAcked(prepareCreate("index").addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword"));
assertAcked(client().admin().indices().preparePutMapping("index").setType("type1").setUpdateAllTypes(true).setSource("f", "type=keyword,null_value=n/a").get());
GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type2").get();
MappingMetaData type2Mapping = mappings.getMappings().get("index").get("type2").get();
Map<String, Object> properties = (Map<String, Object>) type2Mapping.sourceAsMap().get("properties");
Map<String, Object> f = (Map<String, Object>) properties.get("f");
assertEquals("n/a", f.get("null_value"));
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingIntegrationIT method testUpdateMappingConcurrently.
public void testUpdateMappingConcurrently() throws Throwable {
createIndex("test1", "test2");
final AtomicReference<Exception> threadException = new AtomicReference<>();
final AtomicBoolean stop = new AtomicBoolean(false);
Thread[] threads = new Thread[3];
final CyclicBarrier barrier = new CyclicBarrier(threads.length);
final ArrayList<Client> clientArray = new ArrayList<>();
for (Client c : clients()) {
clientArray.add(c);
}
for (int j = 0; j < threads.length; j++) {
threads[j] = new Thread(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
try {
barrier.await();
for (int i = 0; i < 100; i++) {
if (stop.get()) {
return;
}
Client client1 = clientArray.get(i % clientArray.size());
Client client2 = clientArray.get((i + 1) % clientArray.size());
String indexName = i % 2 == 0 ? "test2" : "test1";
String typeName = "type" + (i % 10);
String fieldName = Thread.currentThread().getName() + "_" + i;
PutMappingResponse response = client1.admin().indices().preparePutMapping(indexName).setType(typeName).setSource(JsonXContent.contentBuilder().startObject().startObject(typeName).startObject("properties").startObject(fieldName).field("type", "text").endObject().endObject().endObject().endObject()).get();
assertThat(response.isAcknowledged(), equalTo(true));
GetMappingsResponse getMappingResponse = client2.admin().indices().prepareGetMappings(indexName).get();
ImmutableOpenMap<String, MappingMetaData> mappings = getMappingResponse.getMappings().get(indexName);
assertThat(mappings.containsKey(typeName), equalTo(true));
assertThat(((Map<String, Object>) mappings.get(typeName).getSourceAsMap().get("properties")).keySet(), Matchers.hasItem(fieldName));
}
} catch (Exception e) {
threadException.set(e);
stop.set(true);
}
}
});
threads[j].setName("t_" + j);
threads[j].start();
}
for (Thread t : threads) t.join();
if (threadException.get() != null) {
throw threadException.get();
}
}
Aggregations