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"); }
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
private void initMappers(Map<String, Object> withoutType) { if (withoutType.containsKey("_routing")) { boolean required = false; Map<String, Object> routingNode = (Map<String, Object>) withoutType.get("_routing"); for (Map.Entry<String, Object> entry : routingNode.entrySet()) { String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); if (fieldName.equals("required")) { try { required = nodeBooleanValue(fieldNode); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException("Failed to create mapping for type [" + this.type() + "]. " + "Illegal value in field [_routing.required].", ex); } } } this.routing = new Routing(required); } else { this.routing = Routing.EMPTY; } if (withoutType.containsKey("_parent")) { this.hasParentField = true; } else { this.hasParentField = false; } }
@SuppressWarnings("unchecked") private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate<String> fieldPredicate) throws IOException { if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { return mappingMetaData; } Map<String, Object> sourceAsMap = XContentHelper.convertToMap(mappingMetaData.source().compressedReference(), true).v2(); Map<String, Object> mapping; if (sourceAsMap.size() == 1 && sourceAsMap.containsKey(mappingMetaData.type())) { mapping = (Map<String, Object>) sourceAsMap.get(mappingMetaData.type()); } else { mapping = sourceAsMap; } Map<String, Object> properties = (Map<String, Object>)mapping.get("properties"); if (properties == null || properties.isEmpty()) { return mappingMetaData; } filterFields("", properties, fieldPredicate); return new MappingMetaData(mappingMetaData.type(), sourceAsMap); }
private synchronized Map<String, DocumentMapper> internalMerge(IndexMetaData indexMetaData, MergeReason reason, boolean updateAllTypes, boolean onlyUpdateIfNeeded) { Map<String, CompressedXContent> map = new LinkedHashMap<>(); for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMetaData = cursor.value; if (onlyUpdateIfNeeded) { DocumentMapper existingMapper = documentMapper(mappingMetaData.type()); if (existingMapper == null || mappingMetaData.source().equals(existingMapper.mappingSource()) == false) { map.put(mappingMetaData.type(), mappingMetaData.source()); } } else { map.put(mappingMetaData.type(), mappingMetaData.source()); } } return internalMerge(map, reason, updateAllTypes); }
final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source(); final CompressedXContent newSource = mapping.value.source(); assert currentSource.equals(newSource) : "expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] " + "to be the same as new mapping [" + newSource + "]";
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }
for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) { String parentType = newMapper.parentFieldMapper().type(); if (parentType.equals(mapping.value.type()) && mapperService.getParentTypes().contains(parentType) == false) { throw new IllegalArgumentException("can't add a _parent field that points to an " +
@Override public void writeTo(StreamOutput out) throws IOException { out.writeString(type()); source().writeTo(out); // routing out.writeBoolean(routing().required()); if (out.getVersion().before(Version.V_6_0_0_alpha1)) { // timestamp out.writeBoolean(false); // enabled out.writeString(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern()); out.writeOptionalString("now"); // 5.x default out.writeOptionalBoolean(null); } out.writeBoolean(hasParentField()); }
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws IOException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws ElasticsearchParseException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
/** * Converts the serialized compressed form of the mappings into a parsed map. */ public Map<String, Object> sourceAsMap() throws IOException { Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2(); if (mapping.size() == 1 && mapping.containsKey(type())) { // the type name is the root value, reduce it mapping = (Map<String, Object>) mapping.get(type()); } return mapping; }
public static DeleteByQueryResponse clearIndex(Client client, String indexName){ DeleteByQueryResponse indexDeleteByQueryResponses = client.prepareDeleteByQuery(indexName).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings(indexName).execute().actionGet(); ArrayList<String> mappings = new ArrayList(); getMappingsResponse.getMappings().forEach(map -> { map.value.forEach(map2 -> mappings.add(map2.value.type())); }); if(mappings.size() > 0) { DeleteMappingResponse deleteMappingResponse = client.admin().indices().prepareDeleteMapping(indexName).setType(mappings.toArray(new String[mappings.size()])).execute().actionGet(); } return indexDeleteByQueryResponses; }
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); }
@Override public void writeTo(StreamOutput out) throws IOException { out.writeString(type()); source().writeTo(out); // routing out.writeBoolean(routing().required()); // timestamp out.writeBoolean(timestamp().enabled()); out.writeString(timestamp().format()); out.writeOptionalString(timestamp().defaultTimestamp()); out.writeOptionalBoolean(timestamp().ignoreMissing()); out.writeBoolean(hasParentField()); }