@CheckForNull @SuppressWarnings("unchecked") private Map<String, Object> field(MappingMetaData mapping, String field) { Map<String, Object> props = (Map<String, Object>) mapping.getSourceAsMap().get("properties"); return (Map<String, Object>) props.get(field); }
private int countMappingFields(MappingMetaData mapping) { return ((Map) mapping.getSourceAsMap().get("properties")).size(); }
Map<String, Object> sourceMap = mappingMetaData.getSourceAsMap(); Map<String, Object> esMapping = (Map<String, Object>) sourceMap.get("properties"); for (Map.Entry<String, Object> entry : esMapping.entrySet()) {
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"); }
if (client.admin().indices().prepareDeleteMapping(index).setType(type).get().isAcknowledged()) { PutMappingResponse pmr = client.admin().indices().preparePutMapping(index).setType(type) .setSource(mapping.getSourceAsMap()).get(); if (!pmr.isAcknowledged()) { logger.error("Failed to put mapping {} / {} / {}.", index, type, mapping.source());
@Override public Map<String, Object> getSourceAsMap() throws IOException { return this.mappingMetaData.getSourceAsMap(); } }
@SuppressWarnings("unchecked") private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException { return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties"); }
@SuppressWarnings("unchecked") private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException { return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties"); }
@SuppressWarnings("unchecked") private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException { return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties"); }
@SuppressWarnings("unchecked") private Map<String, Map<String, String>> getPropertiesFromTypeMapping(MappingMetaData typeMapping) throws IOException { return (Map<String, Map<String, String>>) typeMapping.getSourceAsMap().get("properties"); }
public Set<String> listAllFields() throws Exception{ GetMappingsResponse response = client.admin().indices().prepareGetMappings(this.indexName). execute().actionGet(); MappingMetaData mappingMetaData = response.getMappings().get(this.indexName).get(this.documentType); Map map = (Map)mappingMetaData.getSourceAsMap().get("properties"); Set<String> fields = new HashSet<>(); for (Object field: map.keySet()){ fields.add(field.toString()); } return fields; }
private void outputMapping(Output output, ImmutableOpenMap<String, MappingMetaData> c) throws IOException { Iterator<String> iter = c.keysIt(); while (iter.hasNext()) { String property = iter.next(); MappingMetaData md = c.get(property); output.line("routing: " + md.routing().toString()); for (Map.Entry<String, Object> e : md.getSourceAsMap().entrySet()) { outputMappingRow(output, e); } } }
@Override public Map<String, Object> getAllMapping(String indexName) throws Exception { Assert.notNull(indexName, "No index defined for putMapping()"); Map<String, Object> map = new HashMap<>(); try { ImmutableOpenMap<String, MappingMetaData> immutableOpenMap = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName)) .actionGet().getMappings().get(indexName); Iterator<ObjectObjectCursor<String, MappingMetaData>> iterator = immutableOpenMap.iterator(); while (iterator.hasNext()) { ObjectObjectCursor<String, MappingMetaData> objectObjectCursor = iterator.next(); map.put(objectObjectCursor.key, objectObjectCursor.value.getSourceAsMap()); } } catch (Exception e) { throw new Exception("Error while getting mapping for indexName : " + indexName + e.getMessage()); } return map; }
@Override public Map<String, Object> getMapping(String indexName, String type) throws Exception { Assert.notNull(indexName, "No index defined for putMapping()"); Assert.notNull(type, "No type defined for putMapping()"); Map mappings = null; try { mappings = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName).types(type)) .actionGet().getMappings().get(indexName).get(type).getSourceAsMap(); } catch (Exception e) { throw new Exception("Error while getting mapping for indexName : " + indexName + " type : " + type + " " + e.getMessage()); } return mappings; }
Map<String, Map<String, String>> meta = (Map<String, Map<String, String>>) elementMetadata.getSourceAsMap().get("_meta"); if (meta == null) { continue;
/** * Waits for the given mapping type to exists on the master node. */ public void assertMappingOnMaster(final String index, final String type, final String... fieldNames) throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get(); ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get(index); assertThat(mappings, notNullValue()); MappingMetaData mappingMetaData = mappings.get(type); assertThat(mappingMetaData, notNullValue()); Map<String, Object> mappingSource = mappingMetaData.getSourceAsMap(); assertFalse(mappingSource.isEmpty()); assertTrue(mappingSource.containsKey("properties")); for (String fieldName : fieldNames) { Map<String, Object> mappingProperties = (Map<String, Object>) mappingSource.get("properties"); if (fieldName.indexOf('.') != -1) { fieldName = fieldName.replace(".", ".properties."); } assertThat("field " + fieldName + " doesn't exists in mapping " + mappingMetaData.source().string(), XContentMapValues.extractValue(fieldName, mappingProperties), notNullValue()); } }
@Override public List<String> getDynamicFieldNames() throws SearchEngineException { List<String> fieldNames = new LinkedList<>(); try { GetMappingsRequest req = new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE, configuration.getIndexName()) .setTypes(configuration.getDocType()) .request(); GetMappingsResponse response = client.admin().indices().getMappings(req).actionGet(); MappingMetaData metaData = response.getMappings() .get(configuration.getIndexName()) .get(configuration.getDocType()); Map<String, Object> sourceMap = metaData.getSourceAsMap(); Object annotationField = ((Map)sourceMap.get("properties")).get(configuration.getAnnotationField()); Map<String, Object> annotationProperties = (Map<String, Object>)((Map)annotationField).get("properties"); if (annotationProperties != null) { for (String field : annotationProperties.keySet()) { if (field.matches(DYNAMIC_LABEL_FIELD_REGEX)) { fieldNames.add(field); } } } } catch (IOException e) { LOGGER.error("Caught IOException retrieving field source: {}", e.getMessage()); throw new SearchEngineException(e); } return fieldNames; }
public void updateMetaModel(KObject object, MetaObject metaObject) { List<MetaProperty> dirtyProperties = new ArrayList<>(); Optional<MappingMetaData> mappingOptional = this.indexProvider.getMapping(object.getClusterId(), object.getType().getName()); if (!mappingOptional.isPresent()) { this.indexProvider.putMapping(object.getClusterId(), object.getType().getName(), metaObject); } else { Map<String, Object> mapping = mappingOptional.get().getSourceAsMap(); Optional.ofNullable(object.getProperties()) .ifPresent(kProperties -> { for (final KProperty property : object.getProperties()) { Object config = mapping.get(property.getName()); if (config == null) { Optional<MetaProperty> prop = metaObject.getProperty(property.getName()); prop.ifPresent(metaProperty -> dirtyProperties.add(metaProperty)); } } }); this.indexProvider.putMapping(object.getClusterId(), object.getType().getName(), dirtyProperties); } }
public void updateMetaModel(KObject object, MetaObject metaObject) { List<MetaProperty> dirtyProperties = new ArrayList<>(); Optional<MappingMetaData> mappingOptional = this.indexProvider.getMapping(object.getClusterId(), object.getType().getName()); if (!mappingOptional.isPresent()) { this.indexProvider.putMapping(object.getClusterId(), object.getType().getName(), metaObject); } else { Map<String, Object> mapping = mappingOptional.get().getSourceAsMap(); Optional.ofNullable(object.getProperties()) .ifPresent(kProperties -> { for (final KProperty property : object.getProperties()) { Object config = mapping.get(property.getName()); if (config == null) { Optional<MetaProperty> prop = metaObject.getProperty(property.getName()); prop.ifPresent(metaProperty -> dirtyProperties.add(metaProperty)); } } }); this.indexProvider.putMapping(object.getClusterId(), object.getType().getName(), dirtyProperties); } }
public ImmutableIndexInfo(String name, IndexService indexService, MappingMetaData mappingMetaData, MetaData metadata, boolean versionLessEngine) throws IOException { this.name = name; this.versionLessEngine = versionLessEngine; this.indexService = indexService; this.mapping = mappingMetaData.sourceAsMap(); this.type = mappingMetaData.type(); Map<String,Object> mappingMap = (Map<String,Object>)mappingMetaData.getSourceAsMap(); Map<String,Object> metaMap = (mappingMap == null) ? null : (Map<String,Object>)mappingMap.get("_meta"); this.refresh = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_SYNCHRONOUS_REFRESH_SETTING); this.snapshot = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_SNAPSHOT_WITH_SSTABLE_SETTING); this.includeNodeId = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INCLUDE_NODE_ID_SETTING); this.index_on_compaction = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_ON_COMPACTION_SETTING); this.index_static_columns = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_STATIC_COLUMNS_SETTING); this.index_static_only = getMetaSettings(metadata.settings(), indexService.getIndexSettings(), metaMap, IndexMetaData.INDEX_INDEX_STATIC_ONLY_SETTING); }