@Override protected Analyzer getWrappedAnalyzer(String fieldName) { MappedFieldType fieldType = fullName(fieldName); if (fieldType != null) { Analyzer analyzer = extractAnalyzer.apply(fieldType); if (analyzer != null) { return analyzer; } } return defaultAnalyzer; } }
@Override public boolean containsKey(Object key) { // assume its a string... String fieldName = key.toString(); ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName); if (scriptValues == null) { MappedFieldType fieldType = mapperService.fullName(fieldName); if (fieldType == null) { return false; } } return true; }
@Override public MappedFieldType smartNameFieldType(String name) { return mapperService().fullName(name); }
public MappedFieldType fieldMapper(String name) { return failIfFieldMappingNotFound(name, mapperService.fullName(name)); }
@Override public PostingsFormat getPostingsFormatForField(String field) { final MappedFieldType fieldType = mapperService.fullName(field); if (fieldType == null) { logger.warn("no index mapper found for field: [{}] returning default postings format", field); } else if (fieldType instanceof CompletionFieldMapper.CompletionFieldType) { return CompletionFieldMapper.CompletionFieldType.postingsFormat(); } return super.getPostingsFormatForField(field); }
private Query createTypeFilter(String[] types) { if (types != null && types.length >= 1) { MappedFieldType ft = mapperService().fullName(TypeFieldMapper.NAME); if (ft != null) { // ft might be null if no documents have been indexed yet return ft.termsQuery(Arrays.asList(types), queryShardContext); } } return null; }
@Override public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(parserContext.mapperService().fullName(NAME)); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); if (fieldName.equals("required")) { builder.required(TypeParsers.nodeBooleanValue(name, "required", fieldNode, parserContext)); iterator.remove(); } } return builder; }
@Override public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(parserContext.mapperService().fullName(NAME)); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); if (fieldName.equals("enabled")) { builder.enabled(TypeParsers.nodeBooleanValue(name, "enabled", fieldNode, parserContext)); iterator.remove(); } } return builder; }
@Override public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { return new Builder(parserContext.mapperService().fullName(NAME)); }
public void postProcess(MapperService mapperService) { if (mapperService.getIndexSettings().isSingleType()) { final Collection<String> types = mapperService.types(); assert types.size() <= 1 : types; if (types.isEmpty() == false) { type = types.iterator().next(); } } for (Map.Entry<String, List<Object>> entry : fields().entrySet()) { MappedFieldType fieldType = mapperService.fullName(entry.getKey()); if (fieldType == null) { throw new IllegalStateException("Field [" + entry.getKey() + "] exists in the index but not in mappings"); } List<Object> fieldValues = entry.getValue(); for (int i = 0; i < fieldValues.size(); i++) { fieldValues.set(i, fieldType.valueForDisplay(fieldValues.get(i))); } } }
@Override public Similarity get(String name) { MappedFieldType fieldType = mapperService.fullName(name); return (fieldType != null && fieldType.similarity() != null) ? fieldType.similarity().get() : defaultSimilarity; } }
private Query existsQuery(String fieldName) { final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { return new MatchNoDocsQuery("No mappings yet"); } if (fieldNamesFieldType.isEnabled() == false) { // The field_names_field is disabled so we switch to a wildcard query that matches all terms return new WildcardQuery(new Term(fieldName, "*")); } return ExistsQueryBuilder.newFilter(context, fieldName); }
@Override public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { DEPRECATION_LOGGER.deprecated("Fielddata access on the _uid field is deprecated, use _id instead"); MappedFieldType idFieldType = mapperService.fullName(IdFieldMapper.NAME); IndexFieldData<?> idFieldData = idFieldType.fielddataBuilder(fullyQualifiedIndexName) .build(indexSettings, idFieldType, cache, breakerService, mapperService); final String type = mapperService.types().iterator().next(); return new UidIndexFieldData(indexSettings.getIndex(), type, idFieldData); } };
@Override protected ScoreFunction doToFunction(QueryShardContext context) { MappedFieldType fieldType = context.getMapperService().fullName(field); IndexNumericFieldData fieldData = null; if (fieldType == null) { if(missing == null) { throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined."); } } else { fieldData = context.getForField(fieldType); } return new FieldValueFactorFunction(field, factor, modifier, missing, fieldData); }
@Override public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { if (parserContext.indexVersionCreated().onOrAfter(Version.V_5_0_0_alpha3)) { throw new MapperParsingException(NAME + " is not configurable"); } return new Builder(parserContext.mapperService().fullName(NAME)); }
/** Returns true if a query on the given field might match nested documents. */ boolean mightMatchNestedDocs(String field) { if (field.startsWith("_")) { // meta field. Every meta field behaves differently, eg. nested // documents have the same _uid as their parent, put their path in // the _type field but do not have _field_names. So we just ignore // meta fields and return true, which is always safe, it just means // we might add a nested filter when it is nor required. return true; } if (mapperService.fullName(field) == null) { // field does not exist return false; } for (String parent = parentObject(field); parent != null; parent = parentObject(parent)) { ObjectMapper mapper = mapperService.getObjectMapper(parent); if (mapper != null && mapper.nested().isNested()) { return true; } } return false; }
private static Analyzer getAnalyzerAtField(IndexShard indexShard, String field, @Nullable Map<String, String> perFieldAnalyzer) { MapperService mapperService = indexShard.mapperService(); Analyzer analyzer; if (perFieldAnalyzer != null && perFieldAnalyzer.containsKey(field)) { analyzer = mapperService.getIndexAnalyzers().get(perFieldAnalyzer.get(field).toString()); } else { MappedFieldType fieldType = mapperService.fullName(field); if (fieldType instanceof KeywordFieldMapper.KeywordFieldType) { KeywordFieldMapper.KeywordFieldType keywordFieldType = (KeywordFieldMapper.KeywordFieldType) fieldType; analyzer = keywordFieldType.normalizer() == null ? keywordFieldType.indexAnalyzer() : keywordFieldType.normalizer(); } else { analyzer = fieldType.indexAnalyzer(); } } if (analyzer == null) { analyzer = mapperService.getIndexAnalyzers().getDefaultIndexAnalyzer(); } return analyzer; }
private static Query newFieldExistsQuery(QueryShardContext context, String field) { MappedFieldType fieldType = context.getMapperService().fullName(field); if (fieldType == null) { // The field does not exist as a leaf but could be an object so // check for an object mapper if (context.getObjectMapper(field) != null) { return newObjectFieldExistsQuery(context, field); } return Queries.newMatchNoDocsQuery("No field \"" + field + "\" exists in mappings."); } Query filter = fieldType.existsQuery(context); return new ConstantScoreQuery(filter); }
private static Query newObjectFieldExistsQuery(QueryShardContext context, String objField) { BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder(); Collection<String> fields = context.simpleMatchToIndexNames(objField + ".*"); for (String field : fields) { Query existsQuery = context.getMapperService().fullName(field).existsQuery(context); booleanQuery.add(existsQuery, Occur.SHOULD); } return new ConstantScoreQuery(booleanQuery.build()); }
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException { QueryShardContext shardContext = queryRewriteContext.convertToShardContext(); // If the context is null we are not on the shard and cannot // rewrite so just pretend there is an intersection so that the rewrite is a noop if (shardContext == null || shardContext.getIndexReader() == null) { return MappedFieldType.Relation.INTERSECTS; } final MapperService mapperService = shardContext.getMapperService(); final MappedFieldType fieldType = mapperService.fullName(fieldName); if (fieldType == null) { // no field means we have no values return MappedFieldType.Relation.DISJOINT; } else { DateMathParser dateMathParser = getForceDateParser(); return fieldType.isFieldWithinQuery(shardContext.getIndexReader(), from, to, includeLower, includeUpper, timeZone, dateMathParser, queryRewriteContext); } }