Package org.elasticsearch.index.mapper

Examples of org.elasticsearch.index.mapper.FieldMapper$Names


        if (fieldName == null) {
            throw new QueryParsingException(parseContext.index(), "terms filter requires a field name, followed by array of terms");
        }

        FieldMapper fieldMapper = null;
        smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
        String[] previousTypes = null;
        if (smartNameFieldMappers != null) {
            if (smartNameFieldMappers.hasMapper()) {
                fieldMapper = smartNameFieldMappers.mapper();
                fieldName = fieldMapper.names().indexName();
            }
            // if we have a doc mapper, its explicit type, mark it
            if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
                previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
            }
        }

        if (lookupId != null) {
            // if there are no mappings, then nothing has been indexing yet against this shard, so we can return
            // no match (but not cached!), since the Terms Lookup relies on the fact that there are mappings...
            if (fieldMapper == null) {
                return Queries.MATCH_NO_FILTER;
            }

            // external lookup, use it
            TermsLookup termsLookup = new TermsLookup(fieldMapper, lookupIndex, lookupType, lookupId, lookupRouting, lookupPath, parseContext);

            Filter filter = termsFilterCache.termsFilter(termsLookup, lookupCache, cacheKey);
            if (filter == null) {
                return null;
            }

            // cache the whole filter by default, or if explicitly told to
            if (cache == null || cache) {
                filter = parseContext.cacheFilter(filter, cacheKey);
            }
            return filter;
        }

        if (terms.isEmpty()) {
            return Queries.MATCH_NO_FILTER;
        }

        try {
            Filter filter;
            if (EXECUTION_VALUE_PLAIN.equals(execution)) {
                if (fieldMapper != null) {
                    filter = fieldMapper.termsFilter(terms, parseContext);
                } else {
                    BytesRef[] filterValues = new BytesRef[terms.size()];
                    for (int i = 0; i < filterValues.length; i++) {
                        filterValues[i] = BytesRefs.toBytesRef(terms.get(i));
                    }
                    filter = new TermsFilter(fieldName, filterValues);
                }
                // cache the whole filter by default, or if explicitly told to
                if (cache == null || cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_FIELDDATA.equals(execution)) {
                // if there are no mappings, then nothing has been indexing yet against this shard, so we can return
                // no match (but not cached!), since the FieldDataTermsFilter relies on a mapping...
                if (fieldMapper == null) {
                    return Queries.MATCH_NO_FILTER;
                }

                filter = fieldMapper.fieldDataTermsFilter(terms, parseContext);
                if (cache != null && cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_BOOL.equals(execution)) {
                XBooleanFilter boolFiler = new XBooleanFilter();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        boolFiler.add(parseContext.cacheFilter(fieldMapper.termFilter(term, parseContext), null), BooleanClause.Occur.SHOULD);
                    }
                } else {
                    for (Object term : terms) {
                        boolFiler.add(parseContext.cacheFilter(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))), null), BooleanClause.Occur.SHOULD);
                    }
                }
                filter = boolFiler;
                // only cache if explicitly told to, since we cache inner filters
                if (cache != null && cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_BOOL_NOCACHE.equals(execution)) {
                XBooleanFilter boolFiler = new XBooleanFilter();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        boolFiler.add(fieldMapper.termFilter(term, parseContext), BooleanClause.Occur.SHOULD);
                    }
                } else {
                    for (Object term : terms) {
                        boolFiler.add(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))), BooleanClause.Occur.SHOULD);
                    }
                }
                filter = boolFiler;
                // cache the whole filter by default, or if explicitly told to
                if (cache == null || cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_AND.equals(execution)) {
                List<Filter> filters = Lists.newArrayList();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        filters.add(parseContext.cacheFilter(fieldMapper.termFilter(term, parseContext), null));
                    }
                } else {
                    for (Object term : terms) {
                        filters.add(parseContext.cacheFilter(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))), null));
                    }
                }
                filter = new AndFilter(filters);
                // only cache if explicitly told to, since we cache inner filters
                if (cache != null && cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_AND_NOCACHE.equals(execution)) {
                List<Filter> filters = Lists.newArrayList();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        filters.add(fieldMapper.termFilter(term, parseContext));
                    }
                } else {
                    for (Object term : terms) {
                        filters.add(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))));
                    }
                }
                filter = new AndFilter(filters);
                // cache the whole filter by default, or if explicitly told to
                if (cache == null || cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_OR.equals(execution)) {
                List<Filter> filters = Lists.newArrayList();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        filters.add(parseContext.cacheFilter(fieldMapper.termFilter(term, parseContext), null));
                    }
                } else {
                    for (Object term : terms) {
                        filters.add(parseContext.cacheFilter(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))), null));
                    }
                }
                filter = new OrFilter(filters);
                // only cache if explicitly told to, since we cache inner filters
                if (cache != null && cache) {
                    filter = parseContext.cacheFilter(filter, cacheKey);
                }
            } else if (EXECUTION_VALUE_OR_NOCACHE.equals(execution)) {
                List<Filter> filters = Lists.newArrayList();
                if (fieldMapper != null) {
                    for (Object term : terms) {
                        filters.add(fieldMapper.termFilter(term, parseContext));
                    }
                } else {
                    for (Object term : terms) {
                        filters.add(new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(term))));
                    }
View Full Code Here


        MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
        if (smartNameFieldMappers == null || !smartNameFieldMappers.hasMapper()) {
            throw new QueryParsingException(parseContext.index(), "Failed to find geo_shape field [" + fieldName + "]");
        }

        FieldMapper fieldMapper = smartNameFieldMappers.mapper();
        // TODO: This isn't the nicest way to check this
        if (!(fieldMapper instanceof GeoShapeFieldMapper)) {
            throw new QueryParsingException(parseContext.index(), "Field [" + fieldName + "] is not a geo_shape");
        }
View Full Code Here

        }
        if (fi.getIndexOptions() != null) {
            m.put("options", fi.getIndexOptions().name());
        }
        m.put("attributes", fi.attributes());
        FieldMapper fieldMapper = mapperService.smartNameFieldMapper(fi.name);
        if (fieldMapper != null) {
            Map<String, Object> mapper = new HashMap();
            mapper.put("fullName", fieldMapper.names().fullName());
            mapper.put("indexName", fieldMapper.names().indexName());
            mapper.put("indexNameClean", fieldMapper.names().indexNameClean());

            mapper.put("boost", fieldMapper.boost());

            if (fieldMapper.indexAnalyzer() != null) {
                mapper.put("indexAnalyzer", fieldMapper.indexAnalyzer().toString());
            }
            if (fieldMapper.searchAnalyzer() != null) {
                mapper.put("searchAnalyzer", fieldMapper.searchAnalyzer().toString());
            }
            if (fieldMapper.searchQuoteAnalyzer() != null) {
                mapper.put("searchQuoteAnalyzer", fieldMapper.searchQuoteAnalyzer().toString());
            }

            FieldDataType dataType = fieldMapper.fieldDataType();
            if (dataType != null) {
                mapper.put("fieldDataType", dataType.getType());
            }

            FieldType type = fieldMapper.fieldType();
            if (type != null) {
                mapper.put("indexed", type.indexed());
                mapper.put("stored", type.stored());
                mapper.put("tokenized", type.tokenized());
                mapper.put("omitNorms", type.omitNorms());
                mapper.put("storeTermVectors", type.storeTermVectors());
                mapper.put("storeTermVectorOffsets", type.storeTermVectorOffsets());
                mapper.put("storeTermVectorPayloads", type.storeTermVectorPayloads());
                mapper.put("storeTermVectorPositions", type.storeTermVectorPositions());
                if (type.numericType() != null) {
                    mapper.put("numericType", type.numericType().name());
                    mapper.put("numericPrecisionStep", type.numericPrecisionStep());
                }
                if (type.docValueType() != null) {
                    mapper.put("docValueType", type.docValueType().name());
                }
            }

            SimilarityProvider similarityProvider = fieldMapper.similarity();
            if (similarityProvider != null) {
                mapper.put("similarityPovider", similarityProvider.name());
                mapper.put("similarity", similarityProvider.get().getClass().getName() );
            }

            PostingsFormatProvider postingsFormatProvider = fieldMapper.postingsFormatProvider();
            if (postingsFormatProvider != null) {
                mapper.put("postingsFormatProvider", postingsFormatProvider.name());
                mapper.put("postingsFormat", postingsFormatProvider.get().getName());
            }
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.mapper.FieldMapper$Names

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.