protected static void parseNested( String name, Map<String, Object> node, ObjectMapper.Builder builder) { boolean nested = false; boolean nestedIncludeInParent = false; boolean nestedIncludeInRoot = false; Object fieldNode = node.get("type"); if (fieldNode != null) { String type = fieldNode.toString(); if (type.equals(CONTENT_TYPE)) { builder.nested = Nested.NO; } else if (type.equals(NESTED_CONTENT_TYPE)) { nested = true; } else { throw new MapperParsingException( "Trying to parse an object but has a different type [" + type + "] for [" + name + "]"); } } fieldNode = node.get("include_in_parent"); if (fieldNode != null) { nestedIncludeInParent = nodeBooleanValue(fieldNode); } fieldNode = node.get("include_in_root"); if (fieldNode != null) { nestedIncludeInRoot = nodeBooleanValue(fieldNode); } if (nested) { builder.nested = Nested.newNested(nestedIncludeInParent, nestedIncludeInRoot); } }
protected static void parseProperties( ObjectMapper.Builder objBuilder, Map<String, Object> propsNode, ParserContext parserContext) { for (Map.Entry<String, Object> entry : propsNode.entrySet()) { String propName = entry.getKey(); // Should accept empty arrays, as a work around for when the user can't provide an empty // Map. (PHP for example) boolean isEmptyList = entry.getValue() instanceof List && ((List<?>) entry.getValue()).isEmpty(); if (entry.getValue() instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> propNode = (Map<String, Object>) entry.getValue(); String type; Object typeNode = propNode.get("type"); if (typeNode != null) { type = typeNode.toString(); } else { // lets see if we can derive this... if (propNode.get("properties") != null) { type = ObjectMapper.CONTENT_TYPE; } else if (propNode.size() == 1 && propNode.get("enabled") != null) { // if there is a single property with the enabled flag on it, make it an object // (usually, setting enabled to false to not index any type, including core values, // which // non enabled object type supports). type = ObjectMapper.CONTENT_TYPE; } else { throw new MapperParsingException("No type specified for property [" + propName + "]"); } } Mapper.TypeParser typeParser = parserContext.typeParser(type); if (typeParser == null) { throw new MapperParsingException( "No handler for type [" + type + "] declared on field [" + propName + "]"); } objBuilder.add(typeParser.parse(propName, propNode, parserContext)); } else if (!isEmptyList) { throw new MapperParsingException( "Expected map for property [fields] on field [" + propName + "] but got a " + propName.getClass()); } } }
@Override public void run() { OntologyHelper helper = helpers.get(threadKey); if (helper != null) { // Check if the last call time was longer ago than the maximum if (System.currentTimeMillis() - DELETE_CHECK_DELAY_MS > helper.getLastCallTime()) { // Assume helper is out of use - dispose of it to allow memory to be freed helper.dispose(); helpers.remove(threadKey); } } }
private Analyzer getAnalyzerAtField( String field, @Nullable Map<String, String> perFieldAnalyzer) { MapperService mapperService = indexShard.mapperService(); Analyzer analyzer; if (perFieldAnalyzer != null && perFieldAnalyzer.containsKey(field)) { analyzer = mapperService.analysisService().analyzer(perFieldAnalyzer.get(field).toString()); } else { analyzer = mapperService.smartNameFieldMapper(field).indexAnalyzer(); } if (analyzer == null) { analyzer = mapperService.analysisService().defaultIndexAnalyzer(); } return analyzer; }
private void parseProperties( ObjectMapper.Builder objBuilder, Map<String, Object> propsNode, ParserContext parserContext) { for (Map.Entry<String, Object> entry : propsNode.entrySet()) { String propName = entry.getKey(); Map<String, Object> propNode = (Map<String, Object>) entry.getValue(); String type; Object typeNode = propNode.get("type"); if (typeNode != null) { type = typeNode.toString(); } else { // lets see if we can derive this... if (propNode.get("properties") != null) { type = ObjectMapper.CONTENT_TYPE; } else if (propNode.get("fields") != null) { type = MultiFieldMapper.CONTENT_TYPE; } else if (propNode.size() == 1 && propNode.get("enabled") != null) { // if there is a single property with the enabled flag on it, make it an object // (usually, setting enabled to false to not index any type, including core values, // which // non enabled object type supports). type = ObjectMapper.CONTENT_TYPE; } else { throw new MapperParsingException("No type specified for property [" + propName + "]"); } } Mapper.TypeParser typeParser = parserContext.typeParser(type); if (typeParser == null) { throw new MapperParsingException( "No handler for type [" + type + "] declared on field [" + propName + "]"); } objBuilder.add(typeParser.parse(propName, propNode, parserContext)); } }
public static OntologyHelper getHelper(OntologySettings settings, ThreadPool threadPool) throws OntologyHelperException { String helperKey = buildHelperKey(settings); OntologyHelper helper = helpers.get(helperKey); if (helper == null) { helper = new ElasticOntologyHelperFactory(settings).buildOntologyHelper(); OntologyCheckRunnable checker = new OntologyCheckRunnable(helperKey); threadPool.scheduleWithFixedDelay(checker, TimeValue.timeValueMillis(DELETE_CHECK_DELAY_MS)); helpers.put(helperKey, helper); helper.updateLastCallTime(); } return helper; }
private Mapper.Builder<?, ?> findMapperBuilder( Map<String, Object> propNode, String propName, ParserContext parserContext) { String type; Object typeNode = propNode.get("type"); if (typeNode != null) { type = typeNode.toString(); } else { type = "string"; } Mapper.TypeParser typeParser = parserContext.typeParser(type); Mapper.Builder<?, ?> mapperBuilder = typeParser.parse(propName, (Map<String, Object>) propNode, parserContext); return mapperBuilder; }
@Override public OntologyMapper build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); Map<String, FieldMapper<String>> fieldMappers = Maps.newHashMap(); context.path().add(name); if (propertyBuilders != null) { for (String property : propertyBuilders.keySet()) { StringFieldMapper sfm = propertyBuilders.get(property).build(context); fieldMappers.put(sfm.names().indexName(), sfm); } } // Initialise field mappers for the pre-defined fields for (FieldMappings mapping : ontologySettings.getFieldMappings()) { if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) { StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName()) .store(true) .index(true) .tokenized(!mapping.isUriField()) .build(context); fieldMappers.put(mapper.names().indexName(), mapper); } } context.path().remove(); // remove name context.path().pathType(origPathType); return new OntologyMapper( buildNames(context), fieldType, docValues, indexAnalyzer, searchAnalyzer, postingsProvider, docValuesProvider, similarity, fieldDataSettings, context.indexSettings(), new MultiFields.Builder().build(this, context), ontologySettings, fieldMappers, threadPool); }
@Override public Terms terms(String field) { return fields.get(field); }