.getMetaData() .getIndices() .get(mapping.get_index()) .getMappings(); } catch (NullPointerException e) { throw new IllegalArgumentException("Not found the mapping info of index: " + mapping.get_index()); MappingMetaData mappingMetaData = mappings.get(mapping.get_type()); if (mappingMetaData == null) { throw new IllegalArgumentException("Not found the mapping info of index: " + mapping.get_index());
@Override public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBuilder builder) throws Exception { GetIndexRequest.Feature[] features = getIndexRequest.features(); String[] indices = getIndexResponse.indices(); builder.startObject(); for (String index : indices) { builder.startObject(index); for (GetIndexRequest.Feature feature : features) { switch (feature) { case ALIASES: writeAliases(getIndexResponse.aliases().get(index), builder, channel.request()); break; case MAPPINGS: writeMappings(getIndexResponse.mappings().get(index), builder, channel.request()); break; case SETTINGS: writeSettings(getIndexResponse.settings().get(index), builder, channel.request()); break; default: throw new IllegalStateException("feature [" + feature + "] is not valid"); } } builder.endObject(); } builder.endObject(); return new BytesRestResponse(RestStatus.OK, builder); } private void writeAliases(List<AliasMetaData> aliases, XContentBuilder builder, ToXContent.Params params) throws IOException {
private void verifyFakeIndex() { ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings(); MappingMetaData mapping = mappings.get("fakes").get("fake"); assertThat(mapping.type()).isEqualTo("fake"); assertThat(mapping.getSourceAsMap()).isNotEmpty(); assertThat(countMappingFields(mapping)).isEqualTo(2); assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); }
private boolean doesMappingExist(final String index, final String mappingName) { GetMappingsRequest request = new GetMappingsRequest() .indices(index); try { GetMappingsResponse response = elasticSearchClient.admin() .indices() .getMappings(request) .get(); return response.getMappings() .get(index) .containsKey(mappingName); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
/** * Get a node by its id * * @param nodeId id of the wanted node * @return wanted node if it exists. Otherwise <code>null</code> */ public DiscoveryNode get(String nodeId) { return nodes.get(nodeId); }
/** * Get the master node * * @return master node */ public DiscoveryNode getMasterNode() { return nodes.get(masterNodeId); }
/** * Returns the nodes absolute data-path the given shard is allocated on or <code>null</code> if the information is not available. */ public String getDataPath(ShardRouting shardRouting) { return routingToDataPath.get(shardRouting); }
@Test public void recreate_index_on_definition_changes() { // v1 startNewCreator(new FakeIndexDefinition()); IndexType fakeIndexType = new IndexType("fakes", "fake"); String id = "1"; es.client().prepareIndex(fakeIndexType).setId(id).setSource(new FakeDoc().getFields()).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); // v2 startNewCreator(new FakeIndexDefinitionV2()); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings(); MappingMetaData mapping = mappings.get("fakes").get("fake"); assertThat(countMappingFields(mapping)).isEqualTo(3); assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); assertThat(field(mapping, "newField").get("type")).isEqualTo("integer"); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isFalse(); }
/** * Get the local node * * @return local node */ public DiscoveryNode getLocalNode() { return nodes.get(localNodeId); }
MappingMetaData mapping = mappings.get(type); if (client.admin().indices().prepareDeleteMapping(index).setType(type).get().isAcknowledged()) { PutMappingResponse pmr = client.admin().indices().preparePutMapping(index).setType(type)
public Map<String, String> getCustomData(final String key) { return this.customData.get(key); }
@Test @ExcludeOnTravis public void testMapping() throws Exception { configurationSource.save("foo", "bar"); refresh(); final GetMappingsResponse mappings = client.admin().indices().prepareGetMappings("stagemonitor-configuration").setTypes("configuration").get(); assertEquals(1, mappings.getMappings().size()); assertEquals("{\"configuration\":{" + "\"_all\":{\"enabled\":false}," + "\"properties\":{\"configuration\":{\"properties\":{" + "\"key\":{\"type\":\"keyword\"}," + "\"value\":{\"type\":\"keyword\"}}}}" + "}" + "}", mappings.getMappings().get("stagemonitor-configuration").get("configuration").source().toString()); } }
/** * Returns the shard size for the given shard routing or <code>null</code> it that metric is not available. */ public Long getShardSize(ShardRouting shardRouting) { return shardSizes.get(shardIdentifierFromRouting(shardRouting)); }
@Nullable public MappingMetaData mapping(String mappingType) { return mappings.get(mappingType); }
private int getTaskResultMappingVersion(IndexMetaData metaData) { MappingMetaData mappingMetaData = metaData.getMappings().get(TASK_TYPE); if (mappingMetaData == null) { return 0; } @SuppressWarnings("unchecked") Map<String, Object> meta = (Map<String, Object>) mappingMetaData.sourceAsMap().get("_meta"); if (meta == null || meta.containsKey(TASK_RESULT_MAPPING_VERSION_META_FIELD) == false) { return 1; // The mapping was created before meta field was introduced } return (int) meta.get(TASK_RESULT_MAPPING_VERSION_META_FIELD); }
/** * Determine if a given node exists * * @param node of the node which existence should be verified * @return <code>true</code> if the node exists. Otherwise <code>false</code> */ public boolean nodeExists(DiscoveryNode node) { DiscoveryNode existing = nodes.get(node.getId()); return existing != null && existing.equals(node); }
/** Returns true iff existing index has the same {@link IndexMetaData} instance */ public boolean hasIndexMetaData(final IndexMetaData indexMetaData) { return indices.get(indexMetaData.getIndex().getName()) == indexMetaData; }