Java Code Examples for org.elasticsearch.index.mapper.core.StringFieldMapper#Builder

The following examples show how to use org.elasticsearch.index.mapper.core.StringFieldMapper#Builder . 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: QueryParseContext.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private MappedFieldType failIfFieldMappingNotFound(String name, MappedFieldType fieldMapping) {
    if (fieldMapping != null || allowUnmappedFields) {
        return fieldMapping;
    } else if (mapUnmappedFieldAsString){
        StringFieldMapper.Builder builder = MapperBuilders.stringField(name);
        // it would be better to pass the real index settings, but they are not easily accessible from here...
        Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexQueryParser.getIndexCreatedVersion()).build();
        return builder.build(new Mapper.BuilderContext(settings, new ContentPath(1))).fieldType();
    } else {
        Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion();
        if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) {
            throw new QueryParsingException(this, "Strict field resolution and no field mapping can be found for the field with name ["
                    + name + "]");
        } else {
            return fieldMapping;
        }
    }
}
 
Example 2
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 3
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>)entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder)builder);
	}
	return propertyMap;
}
 
Example 4
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);
	parseField(builder, name, node, parserContext);

	for (Iterator<Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder = builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 5
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 6
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name);
	parseField(builder, name, node, parserContext);

	for (Iterator<Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder = builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 7
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>)entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder)builder);
	}
	return propertyMap;
}
 
Example 8
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name the field name
 * @param node the JSON node holding the mapping definitions.
 * @param parserContext the parser context
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 9
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 10
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 11
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name);
	parseField(builder, name, node, parserContext);

	for (Iterator<Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder = builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 12
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Map<String, StringFieldMapper.Builder> parseProperties(Map<String, Object> propertiesNode, ParserContext parserContext) {
	Map<String, StringFieldMapper.Builder> propertyMap = new HashMap<>();
	for (Iterator<Map.Entry<String, Object>> iterator = propertiesNode.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		String name = entry.getKey();

		@SuppressWarnings("unchecked")
		Mapper.Builder builder = new StringFieldMapper.TypeParser().parse(entry.getKey(), (Map<String, Object>) entry.getValue(), parserContext);
		propertyMap.put(name, (StringFieldMapper.Builder) builder);
	}
	return propertyMap;
}
 
Example 13
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the mapping definition for the ontology type.
 *
 * @param name          the field name
 * @param node          the JSON node holding the mapping definitions.
 * @param parserContext the parser context object.
 * @return a Builder for an OntologyMapper.
 */
@SuppressWarnings("unchecked")
@Override
public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
		throws MapperParsingException {
	OntologySettings ontologySettings = null;

	Builder builder = new Builder(name, threadPool);

	for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) {
		Entry<String, Object> entry = iterator.next();
		if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
			ontologySettings = new OntologySettingsBuilder()
					.settingsNode((Map<String, Object>) entry.getValue())
					.build();
			iterator.remove();
		} else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
			Map<String, StringFieldMapper.Builder> builders = parseProperties((Map<String, Object>) entry.getValue(), parserContext);
			builder.propertyBuilders(builders);
			iterator.remove();
		}
	}

	if (ontologySettings == null) {
		throw new MapperParsingException("No ontology settings supplied");
	} else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
			&& StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
		throw new MapperParsingException("No ontology URI or OLS details supplied");
	} else {
		builder = builder.ontologySettings(ontologySettings);
	}

	return builder;
}
 
Example 14
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 15
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 16
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 17
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 18
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 19
Source File: OntologyMapper.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
public Builder propertyBuilders(Map<String, StringFieldMapper.Builder> props) {
	this.propertyBuilders = props;
	return this;
}
 
Example 20
Source File: MapperBuilders.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static StringFieldMapper.Builder stringField(String name) {
    return new StringFieldMapper.Builder(name);
}