Package org.elasticsearch.index.mapper

Examples of org.elasticsearch.index.mapper.FieldMappers


//        }
        return result;
    }

    public FieldMapper fieldMapper(String name) {
        FieldMappers fieldMappers = indexQueryParser.mapperService.smartNameFieldMappers(name);
        if (fieldMappers == null) {
            return null;
        }
        return fieldMappers.mapper();
    }
View Full Code Here


                    for (Object oField : doc.getFields()) {
                        Fieldable field = (Fieldable) oField;
                        String name = field.name();
                        Object value = null;
                        FieldMappers fieldMappers = docMapper.mappers().indexName(field.name());
                        if (fieldMappers != null) {
                            FieldMapper mapper = fieldMappers.mapper();
                            if (mapper != null) {
                                name = mapper.names().fullName();
                                value = mapper.valueForSearch(field);
                            }
                        }
                        if (value == null) {
                            if (field.isBinary()) {
                                value = field.getBinaryValue();
                            } else {
                                value = field.stringValue();
                            }
                        }

                        if (fields == null) {
                            fields = newHashMapWithExpectedSize(2);
                        }

                        GetField getField = fields.get(name);
                        if (getField == null) {
                            getField = new GetField(name, new ArrayList<Object>(2));
                            fields.put(name, getField);
                        }
                        getField.values().add(value);
                    }
                }

                // now, go and do the script thingy if needed
                if (gFields != null && gFields.length > 0) {
                    SearchLookup searchLookup = null;
                    for (String field : gFields) {
                        String script = null;
                        if (field.contains("_source.") || field.contains("doc[")) {
                            script = field;
                        } else {
                            FieldMappers x = docMapper.mappers().smartName(field);
                            if (x != null && !x.mapper().stored()) {
                                script = "_source." + x.mapper().names().fullName();
                            }
                        }
                        if (script != null) {
                            if (searchLookup == null) {
                                searchLookup = new SearchLookup(indexService.mapperService(), indexService.cache().fieldData());
                            }
                            SearchScript searchScript = scriptService.search(searchLookup, "mvel", script, null);
                            searchScript.setNextReader(docIdAndVersion.reader);
                            searchScript.setNextDocId(docIdAndVersion.docId);

                            try {
                                Object value = searchScript.run();
                                if (fields == null) {
                                    fields = newHashMapWithExpectedSize(2);
                                }
                                GetField getField = fields.get(field);
                                if (getField == null) {
                                    getField = new GetField(field, new ArrayList<Object>(2));
                                    fields.put(field, getField);
                                }
                                getField.values().add(value);
                            } catch (RuntimeException e) {
                                if (logger.isTraceEnabled()) {
                                    logger.trace("failed to execute get request script field [{}]", e, script);
                                }
                                // ignore
                            }
                        }
                    }
                }

                return new GetResponse(index, type, id, get.version(), get.exists(), source == null ? null : new BytesHolder(source), fields);
            } else {
                BytesHolder source = get.source();

                Map<String, GetField> fields = null;
                boolean sourceRequested = false;

                // we can only load scripts that can run against the source
                if (gFields == null) {
                    sourceRequested = true;
                } else if (gFields.length == 0) {
                    // no fields, and no source
                    sourceRequested = false;
                } else {
                    Map<String, Object> sourceAsMap = SourceLookup.sourceAsMap(source.bytes(), source.offset(), source.length());
                    SearchLookup searchLookup = null;
                    for (String field : gFields) {
                        if (field.equals("_source")) {
                            sourceRequested = true;
                            continue;
                        }
                        String script = null;
                        if (field.contains("_source.")) {
                            script = field;
                        } else {
                            FieldMappers x = docMapper.mappers().smartName(field);
                            if (x != null) {
                                script = "_source." + x.mapper().names().fullName();
                            }
                        }
                        if (script != null) {
                            if (searchLookup == null) {
                                searchLookup = new SearchLookup(indexService.mapperService(), indexService.cache().fieldData());
View Full Code Here

            return null;
        }

        FieldMappersFieldSelector fieldSelector = null;
        for (String fieldName : fields) {
            FieldMappers x = docMapper.mappers().smartName(fieldName);
            if (x != null && x.mapper().stored()) {
                if (fieldSelector == null) {
                    fieldSelector = new FieldMappersFieldSelector();
                }
                fieldSelector.add(x);
            }
View Full Code Here

        Fieldable f = doc.getFieldable("name");
        assertThat(f.name(), equalTo("name"));
        assertThat(f.stringValue(), equalTo("top_level"));
        assertThat(f.isStored(), equalTo(false));

        FieldMappers fieldMappers = docMapper.mappers().fullName("name");
        assertThat(fieldMappers.mappers().size(), equalTo(1));
        assertThat(fieldMappers.mapper().stored(), equalTo(false));

        f = doc.getFieldable("obj1.name");
        assertThat(f.name(), equalTo("obj1.name"));
        assertThat(f.isStored(), equalTo(true));

        fieldMappers = docMapper.mappers().fullName("obj1.name");
        assertThat(fieldMappers.mappers().size(), equalTo(1));
        assertThat(fieldMappers.mapper().stored(), equalTo(true));

        f = doc.getFieldable("obj1.obj2.name");
        assertThat(f.name(), equalTo("obj1.obj2.name"));
        assertThat(f.isStored(), equalTo(false));

        fieldMappers = docMapper.mappers().fullName("obj1.obj2.name");
        assertThat(fieldMappers.mappers().size(), equalTo(1));
        assertThat(fieldMappers.mapper().stored(), equalTo(false));
    }
View Full Code Here

        assertThat(f.name(), equalTo("name"));
        assertThat(f.stringValue(), equalTo("some name"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        FieldMappers fieldMappers = docMapper.mappers().fullName("name");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi1");
        assertThat(f.name(), equalTo("multi1"));
        assertThat(f.stringValue(), equalTo("multi 1"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(true));

        fieldMappers = docMapper.mappers().fullName("multi1");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi1.org");
        assertThat(f.name(), equalTo("multi1.org"));
        assertThat(f.stringValue(), equalTo("multi 1"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        fieldMappers = docMapper.mappers().fullName("multi1.org");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi2");
        assertThat(f.name(), equalTo("multi2"));
        assertThat(f.stringValue(), equalTo("multi 2"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(true));

        fieldMappers = docMapper.mappers().fullName("multi2");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi2.org");
        assertThat(f.name(), equalTo("multi2.org"));
        assertThat(f.stringValue(), equalTo("multi 2"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        fieldMappers = docMapper.mappers().fullName("multi2.org");
        assertThat(fieldMappers.mappers().size(), equalTo(1));
    }
View Full Code Here

        assertThat(f.name(), equalTo("name"));
        assertThat(f.stringValue(), equalTo("some name"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        FieldMappers fieldMappers = docMapper.mappers().fullName("name");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi1");
        assertThat(f.name(), equalTo("multi1"));
        assertThat(f.stringValue(), equalTo("multi 1"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(true));

        fieldMappers = docMapper.mappers().fullName("multi1");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi1.org");
        assertThat(f.name(), equalTo("multi1.org"));
        assertThat(f.stringValue(), equalTo("multi 1"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        fieldMappers = docMapper.mappers().fullName("multi1.org");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi2");
        assertThat(f.name(), equalTo("multi2"));
        assertThat(f.stringValue(), equalTo("multi 2"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(true));

        fieldMappers = docMapper.mappers().fullName("multi2");
        assertThat(fieldMappers.mappers().size(), equalTo(1));

        f = doc.getFieldable("multi2.org");
        assertThat(f.name(), equalTo("multi2.org"));
        assertThat(f.stringValue(), equalTo("multi 2"));
        assertThat(f.isIndexed(), equalTo(true));
        assertThat(f.isTokenized(), equalTo(false));

        fieldMappers = docMapper.mappers().fullName("multi2.org");
        assertThat(fieldMappers.mappers().size(), equalTo(1));
    }
View Full Code Here

    protected FieldMapper fieldMapper(String smartName) {
        if (parseContext.mapperService() == null) {
            return null;
        }
        FieldMappers fieldMappers = parseContext.mapperService().smartNameFieldMappers(smartName);
        if (fieldMappers == null) {
            return null;
        }
        return fieldMappers.mapper();
    }
View Full Code Here

                if (name.equals(SourceFieldMapper.NAME)) {
                    continue;
                }

                Object value = null;
                FieldMappers fieldMappers = documentMapper.mappers().indexName(field.name());
                if (fieldMappers != null) {
                    FieldMapper mapper = fieldMappers.mapper();
                    if (mapper != null) {
                        name = mapper.names().fullName();
                        value = mapper.valueForSearch(field);
                    }
                }
View Full Code Here

            return AllButSourceFieldSelector.INSTANCE;
        }

        FieldMappersFieldSelector fieldSelector = new FieldMappersFieldSelector();
        for (String fieldName : context.fieldNames()) {
            FieldMappers x = context.mapperService().smartNameFieldMappers(fieldName);
            if (x == null) {
                throw new FetchPhaseExecutionException(context, "No mapping for field [" + fieldName + "] in order to load it");
            }
            fieldSelector.add(x);
        }
View Full Code Here

                try {
                    DocumentMapper docMapper = indicesService.indexServiceSafe(concreteIndex).mapperService().documentMapper(request.type());
                    final Set<String> fields = newHashSet();
                    if (request.fields() != null) {
                        for (String field : request.fields()) {
                            FieldMappers fieldMappers = docMapper.mappers().smartName(field);
                            if (fieldMappers != null) {
                                fields.add(fieldMappers.mapper().names().indexName());
                            } else {
                                fields.add(field);
                            }
                        }
                    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.mapper.FieldMappers

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.