use of org.opensearch.index.mapper.MappedFieldType in project OpenSearch by opensearch-project.
the class TermsSetQueryBuilder method createTermQueries.
/**
* Visible only for testing purposes.
*/
List<Query> createTermQueries(QueryShardContext context) {
final MappedFieldType fieldType = context.fieldMapper(fieldName);
final List<Query> queries = new ArrayList<>(values.size());
for (Object value : values) {
if (fieldType != null) {
queries.add(fieldType.termQuery(value, context));
} else {
queries.add(new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(value))));
}
}
return queries;
}
use of org.opensearch.index.mapper.MappedFieldType in project OpenSearch by opensearch-project.
the class WildcardQueryBuilder method doToQuery.
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
throw new IllegalStateException("Rewrite first");
}
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
return fieldType.wildcardQuery(value, method, caseInsensitive, context);
}
use of org.opensearch.index.mapper.MappedFieldType in project OpenSearch by opensearch-project.
the class DecayFunctionBuilder method parseVariable.
private AbstractDistanceScoreFunction parseVariable(String fieldName, XContentParser parser, QueryShardContext context, MultiValueMode mode) throws IOException {
// the field must exist, else we cannot read the value for the doc later
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
throw new ParsingException(parser.getTokenLocation(), "unknown field [{}]", fieldName);
}
// dates and time and geo need special handling
parser.nextToken();
// TODO these ain't gonna work with runtime fields
if (fieldType instanceof DateFieldMapper.DateFieldType) {
return parseDateVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof GeoPointFieldType) {
return parseGeoVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
return parseNumberVariable(parser, context, fieldType, mode);
} else {
throw new ParsingException(parser.getTokenLocation(), "field [{}] is of type [{}], but only numeric types are supported.", fieldName, fieldType);
}
}
use of org.opensearch.index.mapper.MappedFieldType in project OpenSearch by opensearch-project.
the class RegexpQueryBuilder method doToQuery.
@Override
protected Query doToQuery(QueryShardContext context) throws QueryShardException, IOException {
final int maxAllowedRegexLength = context.getIndexSettings().getMaxRegexLength();
if (value.length() > maxAllowedRegexLength) {
throw new IllegalArgumentException("The length of regex [" + value.length() + "] used in the Regexp Query request has exceeded " + "the allowed maximum of [" + maxAllowedRegexLength + "]. " + "This maximum can be set by changing the [" + IndexSettings.MAX_REGEX_LENGTH_SETTING.getKey() + "] index level setting.");
}
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
int matchFlagsValue = caseInsensitive ? RegExp.ASCII_CASE_INSENSITIVE : 0;
Query query = null;
// For BWC we mask irrelevant bits (RegExp changed ALL from 0xffff to 0xff)
int sanitisedSyntaxFlag = syntaxFlagsValue & RegExp.ALL;
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType != null) {
query = fieldType.regexpQuery(value, sanitisedSyntaxFlag, matchFlagsValue, maxDeterminizedStates, method, context);
}
if (query == null) {
if (method == null) {
method = MultiTermQuery.CONSTANT_SCORE_REWRITE;
}
query = new RegexpQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), sanitisedSyntaxFlag, matchFlagsValue, RegexpQuery.DEFAULT_PROVIDER, maxDeterminizedStates, method);
}
return query;
}
use of org.opensearch.index.mapper.MappedFieldType in project OpenSearch by opensearch-project.
the class IntervalQueryBuilder method doToQuery.
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
MappedFieldType fieldType = context.fieldMapper(field);
if (fieldType == null) {
// Be lenient with unmapped fields so that cross-index search will work nicely
return new MatchNoDocsQuery();
}
Set<String> maskedFields = new HashSet<>();
sourceProvider.extractFields(maskedFields);
for (String maskedField : maskedFields) {
MappedFieldType ft = context.fieldMapper(maskedField);
if (ft == null) {
// Be lenient with unmapped fields so that cross-index search will work nicely
return new MatchNoDocsQuery();
}
}
return new IntervalQuery(field, sourceProvider.getSource(context, fieldType));
}
Aggregations