private void validateType(SourceToParse source) { if (docMapper.type().equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("It is forbidden to index into the default mapping [" + MapperService.DEFAULT_MAPPING + "]"); } if (Objects.equals(source.type(), docMapper.type()) == false) { throw new MapperParsingException("Type mismatch, provide type [" + source.type() + "] but mapper is of type [" + docMapper.type() + "]"); } }
/** * returns an immutable iterator over current document mappers. * * @param includingDefaultMapping indicates whether the iterator should contain the {@link #DEFAULT_MAPPING} document mapper. * As is this not really an active type, you would typically set this to false */ public Iterable<DocumentMapper> docMappers(final boolean includingDefaultMapping) { return () -> { final Collection<DocumentMapper> documentMappers; if (includingDefaultMapping) { documentMappers = mappers.values(); } else { documentMappers = mappers.values().stream() .filter(mapper -> !DEFAULT_MAPPING.equals(mapper.type())) .collect(Collectors.toList()); } return Collections.unmodifiableCollection(documentMappers).iterator(); }; }
private boolean assertSerialization(DocumentMapper mapper) { // capture the source now, it may change due to concurrent parsing final CompressedXContent mappingSource = mapper.mappingSource(); DocumentMapper newMapper = parse(mapper.type(), mappingSource, false); if (newMapper.mappingSource().equals(mappingSource) == false) { throw new IllegalStateException("DocumentMapper serialization result is different from source. \n--> Source [" + mappingSource + "]\n--> Result [" + newMapper.mappingSource() + "]"); } return true; }
private void checkPartitionedIndexConstraints(DocumentMapper newMapper) { if (indexSettings.getIndexMetaData().isRoutingPartitionedIndex()) { if (newMapper.parentFieldMapper().active()) { throw new IllegalArgumentException("mapping type name [" + newMapper.type() + "] cannot have a " + "_parent field for the partitioned index [" + indexSettings.getIndex().getName() + "]"); } if (!newMapper.routingFieldMapper().required()) { throw new IllegalArgumentException("mapping type [" + newMapper.type() + "] must have routing " + "required for partitioned index [" + indexSettings.getIndex().getName() + "]"); } } }
assert defaultMapper.type().equals(DEFAULT_MAPPING); mappers.put(DEFAULT_MAPPING, defaultMapper); results.put(DEFAULT_MAPPING, defaultMapper); documentMappers.forEach(mapper -> actualTypes.add(mapper.type())); actualTypes.remove(DEFAULT_MAPPING); if (actualTypes.size() > 1) { validateTypeName(mapper.type()); if (mapper.type().equals(mapper.parentFieldMapper().type())) { throw new IllegalArgumentException("The [_parent.type] option can't point to the same type"); DocumentMapper oldMapper = mappers.get(mapper.type()); DocumentMapper newMapper; if (oldMapper != null) { MapperMergeValidator.validateMapperStructure(newMapper.type(), objectMappers, fieldMappers, fieldAliasMappers, fullPathObjectMappers, fieldTypes, updateAllTypes); checkPartitionedIndexConstraints(newMapper); fieldTypes = fieldTypes.copyAndAddAll(newMapper.type(), fieldMappers, fieldAliasMappers, updateAllTypes); results.put(newMapper.type(), newMapper); mappers.put(newMapper.type(), newMapper); if (results.containsKey(updatedDocumentMapper.type())) { results.put(updatedDocumentMapper.type(), updatedDocumentMapper);
public MappingMetaData(DocumentMapper docMapper) { this.type = docMapper.type(); this.source = docMapper.mappingSource(); this.routing = new Routing(docMapper.routingFieldMapper().required()); this.hasParentField = docMapper.parentFieldMapper().active(); }
private boolean refreshIndexMapping(IndexService indexService, IndexMetaData.Builder builder) { boolean dirty = false; String index = indexService.index().getName(); try { List<String> updatedTypes = new ArrayList<>(); for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) { final String type = mapper.type(); if (!mapper.mappingSource().equals(builder.mapping(type).source())) { updatedTypes.add(type); } } // if a single type is not up-to-date, re-send everything if (updatedTypes.isEmpty() == false) { logger.warn("[{}] re-syncing mappings with cluster state because of types [{}]", index, updatedTypes); dirty = true; for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) { builder.putMapping(new MappingMetaData(mapper)); } } } catch (Exception e) { logger.warn(() -> new ParameterizedMessage("[{}] failed to refresh-mapping in cluster state", index), e); } return dirty; }
String mappingType = documentMapper.type(); CompressedXContent incomingMappingSource = newIndexMetaData.mapping(mappingType).source();
assert updatedEntries.isEmpty() == false; for (final DocumentMapper documentMapper : updatedEntries.values()) { final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type()); if (currentMapping != null) { final CompressedXContent currentSource = currentMapping.source(); final CompressedXContent newSource = documentMapper.mappingSource(); assert currentSource.equals(newSource) == false : "expected current mapping [" + currentSource + "] for type [" + documentMapper.type() + "] " + "to be different than new mapping";
private boolean assertSerialization(DocumentMapper mapper) { // capture the source now, it may change due to concurrent parsing final CompressedXContent mappingSource = mapper.mappingSource(); DocumentMapper newMapper = parse(mapper.type(), mappingSource, false); if (newMapper.mappingSource().equals(mappingSource) == false) { throw new IllegalStateException("DocumentMapper serialization result is different from source. \n--> Source [" + mappingSource + "]\n--> Result [" + newMapper.mappingSource() + "]"); } return true; }
mappingType = newMapper.type(); } else if (mappingType.equals(newMapper.type()) == false) { throw new InvalidTypeNameException("Type name provided does not match type name within mapping definition"); logger.debug("{} update_mapping [{}] with source [{}]", index, mergedMapper.type(), updatedSource); } else if (logger.isInfoEnabled()) { logger.info("{} update_mapping [{}]", index, mergedMapper.type());
for (DocumentMapper mapper : mapperService.docMappers(true)) { MappingMetaData mappingMd = new MappingMetaData(mapper); mappingsMetaData.put(mapper.type(), mappingMd);
private void validateType(SourceToParse source) { if (docMapper.type().equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("It is forbidden to index into the default mapping [" + MapperService.DEFAULT_MAPPING + "]"); } if (Objects.equals(source.type(), docMapper.type()) == false) { throw new MapperParsingException("Type mismatch, provide type [" + source.type() + "] but mapper is of type [" + docMapper.type() + "]"); } }
@Override public void beforeCreate(DocumentMapper mapper) { if (BatchPercolatorService.TYPE_NAME.equals(mapper.type())) { enableRealTimePercolator(); } }
@Override public void afterRemove(DocumentMapper mapper) { if (BatchPercolatorService.TYPE_NAME.equals(mapper.type())) { disableRealTimePercolator(); clear(); } }
private boolean isChildHit(SearchHit hit) { DocumentMapper hitDocumentMapper = mapperService.documentMapper(hit.getType()); return documentMapper.type().equals(hitDocumentMapper.parentFieldMapper().type()); } }
private void checkPartitionedIndexConstraints(DocumentMapper newMapper) { if (indexSettings.getIndexMetaData().isRoutingPartitionedIndex()) { if (newMapper.parentFieldMapper().active()) { throw new IllegalArgumentException("mapping type name [" + newMapper.type() + "] cannot have a " + "_parent field for the partitioned index [" + indexSettings.getIndex().getName() + "]"); } if (!newMapper.routingFieldMapper().required()) { throw new IllegalArgumentException("mapping type [" + newMapper.type() + "] must have routing " + "required for partitioned index [" + indexSettings.getIndex().getName() + "]"); } } }
private boolean assertSerialization(DocumentMapper mapper) { // capture the source now, it may change due to concurrent parsing final CompressedXContent mappingSource = mapper.mappingSource(); DocumentMapper newMapper = parse(mapper.type(), mappingSource, false); if (newMapper.mappingSource().equals(mappingSource) == false) { throw new IllegalStateException("DocumentMapper serialization result is different from source. \n--> Source [" + mappingSource + "]\n--> Result [" + newMapper.mappingSource() + "]"); } return true; }
public MappingMetaData(DocumentMapper docMapper) { this.type = docMapper.type(); this.source = docMapper.mappingSource(); this.routing = new Routing(docMapper.routingFieldMapper().required()); this.hasParentField = docMapper.parentFieldMapper().active(); }
public MappingMetaData(DocumentMapper docMapper) { this.type = docMapper.type(); this.source = docMapper.mappingSource(); this.routing = new Routing(docMapper.routingFieldMapper().required()); this.hasParentField = docMapper.parentFieldMapper().active(); }