Search in sources :

Example 1 with FieldNamesFieldMapper

use of org.opensearch.index.mapper.FieldNamesFieldMapper in project OpenSearch by opensearch-project.

the class RangeQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    if (from == null && to == null) {
        /**
         * Open bounds on both side, we can rewrite to an exists query
         * if the {@link FieldNamesFieldMapper} is enabled.
         */
        final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context.getMapperService().fieldType(FieldNamesFieldMapper.NAME);
        if (fieldNamesFieldType == null) {
            return new MatchNoDocsQuery("No mappings yet");
        }
        // Exists query would fail if the fieldNames field is disabled.
        if (fieldNamesFieldType.isEnabled()) {
            return ExistsQueryBuilder.newFilter(context, fieldName, false);
        }
    }
    MappedFieldType mapper = context.fieldMapper(this.fieldName);
    if (mapper == null) {
        throw new IllegalStateException("Rewrite first");
    }
    DateMathParser forcedDateParser = getForceDateParser();
    return mapper.rangeQuery(from, to, includeLower, includeUpper, relation, timeZone, forcedDateParser, context);
}
Also used : FieldNamesFieldMapper(org.opensearch.index.mapper.FieldNamesFieldMapper) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) DateMathParser(org.opensearch.common.time.DateMathParser)

Aggregations

MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 DateMathParser (org.opensearch.common.time.DateMathParser)1 FieldNamesFieldMapper (org.opensearch.index.mapper.FieldNamesFieldMapper)1 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)1