RestElasticClient implements ElasticClient { @SuppressWarnings("unchecked") public static void removeMapping(String parent, String key, Map<String,Object> data, String currentParent) { Iterator<Entry<String, Object>> it = data.entrySet().iterator(); while (it.hasNext()) { Entry<String, Object> entry = it.next(); if (Objects.equals(currentParent, parent) && entry.getKey().equals(key)) { it.remove(); } else if (entry.getValue() instanceof Map) { removeMapping(parent, key, (Map<String,Object>) entry.getValue(), entry.getKey()); } else if (entry.getValue() instanceof List) { ((List<Object>) entry.getValue()).stream() .filter(item -> item instanceof Map) .forEach(item -> removeMapping(parent, key, (Map<String,Object>) item, currentParent)); } } } RestElasticClient(RestClient client);  RestElasticClient(RestClient client, RestClient proxyClient, boolean enableRunAs); @Override double getVersion(); @Override List<String> getTypes(String indexName); @Override Map<String, Object> getMapping(String indexName, String type); @Override ElasticResponse search(String searchIndices, String type, ElasticRequest request); @Override ElasticResponse scroll(String scrollId, Integer scrollTime); @Override void clearScroll(Set<String> scrollIds); @Override void close(); @SuppressWarnings("unchecked") static void removeMapping(String parent, String key, Map<String,Object> data, String currentParent);  }
@Test public void testRemoveMapping() { Map<String,Object> data = createMap("key", "value"); RestElasticClient.removeMapping(null, "key", data, null); assertTrue(data.isEmpty()); data = createMap("key", "value", "parent", ImmutableMap.of("key", "value")); RestElasticClient.removeMapping(null, "key", data, null); assertEquals(data, ImmutableMap.of("parent", ImmutableMap.of("key", "value"))); data = ImmutableMap.of("key", "value", "parent", createMap("key", 10)); RestElasticClient.removeMapping("parent", "key", data, null); assertEquals(data, ImmutableMap.of("key", "value", "parent", new HashMap<>())); data = new HashMap<>(); RestElasticClient.removeMapping(null, "key", data, null); assertTrue(data.isEmpty()); data = ImmutableMap.of("parent", new HashMap<>()); RestElasticClient.removeMapping("parent", "key", data, null); assertEquals(data, ImmutableMap.of("parent", new HashMap<>())); data = createMap("key", ImmutableList.of(ImmutableMap.of("key", "value"), ImmutableMap.of("key","value","parent", createMap("key","value","key2","value2")))); RestElasticClient.removeMapping("parent", "key", data, null); assertEquals(data, createMap("key", ImmutableList.of(ImmutableMap.of("key", "value"), ImmutableMap.of("key","value","parent", createMap("key2","value2"))))); }