Java Code Examples for org.elasticsearch.index.mapper.object.ObjectMapper#name()

The following examples show how to use org.elasticsearch.index.mapper.object.ObjectMapper#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper parseNonDynamicArray(ParseContext context, ObjectMapper mapper, String lastFieldName, String arrayFieldName) throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
        if (token == XContentParser.Token.START_OBJECT) {
            return parseObject(context, mapper, lastFieldName);
        } else if (token == XContentParser.Token.START_ARRAY) {
            return parseArray(context, mapper, lastFieldName);
        } else if (token == XContentParser.Token.FIELD_NAME) {
            lastFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_NULL) {
            parseNullValue(context, mapper, lastFieldName);
        } else if (token == null) {
            throw new MapperParsingException("object mapping for [" + mapper.name() + "] with array for [" + arrayFieldName + "] tried to parse as array, but got EOF, is there a mismatch in types for the same field?");
        } else {
            return parseValue(context, mapper, lastFieldName, token);
        }
    }
    return null;
}
 
Example 2
Source File: DocumentParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static ObjectMapper parseValue(final ParseContext context, ObjectMapper parentMapper, String currentFieldName, XContentParser.Token token) throws IOException {
    if (currentFieldName == null) {
        throw new MapperParsingException("object mapping [" + parentMapper.name() + "] trying to serialize a value with no field associated with it, current value [" + context.parser().textOrNull() + "]");
    }
    Mapper mapper = parentMapper.getMapper(currentFieldName);
    if (mapper != null) {
        Mapper subUpdate = parseObjectOrField(context, mapper);
        if (subUpdate == null) {
            return null;
        }
        return parentMapper.mappingUpdate(subUpdate);
    } else {
        return parseDynamicValue(context, parentMapper, currentFieldName, token);
    }
}
 
Example 3
Source File: FetchPhase.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private InternalSearchHit.InternalNestedIdentity getInternalNestedIdentity(SearchContext context, int nestedSubDocId, LeafReaderContext subReaderContext, DocumentMapper documentMapper, ObjectMapper nestedObjectMapper) throws IOException {
    int currentParent = nestedSubDocId;
    ObjectMapper nestedParentObjectMapper;
    ObjectMapper current = nestedObjectMapper;
    String originalName = nestedObjectMapper.name();
    InternalSearchHit.InternalNestedIdentity nestedIdentity = null;
    do {
        Query parentFilter;
        nestedParentObjectMapper = documentMapper.findParentObjectMapper(current);
        if (nestedParentObjectMapper != null) {
            if (nestedParentObjectMapper.nested().isNested() == false) {
                current = nestedParentObjectMapper;
                continue;
            }
            parentFilter = nestedParentObjectMapper.nestedTypeFilter();
        } else {
            parentFilter = Queries.newNonNestedFilter();
        }

        Query childFilter = nestedObjectMapper.nestedTypeFilter();
        if (childFilter == null) {
            current = nestedParentObjectMapper;
            continue;
        }
        final Weight childWeight = context.searcher().createNormalizedWeight(childFilter, false);
        Scorer childScorer = childWeight.scorer(subReaderContext);
        if (childScorer == null) {
            current = nestedParentObjectMapper;
            continue;
        }
        DocIdSetIterator childIter = childScorer.iterator();

        BitSet parentBits = context.bitsetFilterCache().getBitSetProducer(parentFilter).getBitSet(subReaderContext);

        int offset = 0;
        int nextParent = parentBits.nextSetBit(currentParent);
        for (int docId = childIter.advance(currentParent + 1); docId < nextParent && docId != DocIdSetIterator.NO_MORE_DOCS; docId = childIter.nextDoc()) {
            offset++;
        }
        currentParent = nextParent;
        current = nestedObjectMapper = nestedParentObjectMapper;
        int currentPrefix = current == null ? 0 : current.name().length() + 1;
        nestedIdentity = new InternalSearchHit.InternalNestedIdentity(originalName.substring(currentPrefix), offset, nestedIdentity);
        if (current != null) {
            originalName = current.name();
        }
    } while (current != null);
    return nestedIdentity;
}
 
Example 4
Source File: DocumentParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static ObjectMapper parseObject(final ParseContext context, ObjectMapper mapper, String currentFieldName) throws IOException {
    if (currentFieldName == null) {
        throw new MapperParsingException("object mapping [" + mapper.name() + "] trying to serialize an object with no field associated with it, current value [" + context.parser().textOrNull() + "]");
    }
    context.path().add(currentFieldName);

    ObjectMapper update = null;
    Mapper objectMapper = mapper.getMapper(currentFieldName);
    if (objectMapper != null) {
        final Mapper subUpdate = parseObjectOrField(context, objectMapper);
        if (subUpdate != null) {
            // propagate mapping update
            update = mapper.mappingUpdate(subUpdate);
        }
    } else {
        ObjectMapper.Dynamic dynamic = mapper.dynamic();
        if (dynamic == null) {
            dynamic = dynamicOrDefault(context.root().dynamic());
        }
        if (dynamic == ObjectMapper.Dynamic.STRICT) {
            throw new StrictDynamicMappingException(mapper.fullPath(), currentFieldName);
        } else if (dynamic == ObjectMapper.Dynamic.TRUE) {
            // remove the current field name from path, since template search and the object builder add it as well...
            context.path().remove();
            Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "object");
            if (builder == null) {
                builder = MapperBuilders.object(currentFieldName).enabled(true).pathType(mapper.pathType());
                // if this is a non root object, then explicitly set the dynamic behavior if set
                if (!(mapper instanceof RootObjectMapper) && mapper.dynamic() != ObjectMapper.Defaults.DYNAMIC) {
                    ((ObjectMapper.Builder) builder).dynamic(mapper.dynamic());
                }
            }
            Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path());
            objectMapper = builder.build(builderContext);
            context.path().add(currentFieldName);
            update = mapper.mappingUpdate(parseAndMergeUpdate(objectMapper, context));
        } else {
            // not dynamic, read everything up to end object
            context.parser().skipChildren();
        }
    }

    context.path().remove();
    return update;
}