Search in sources :

Example 1 with ParentIdFieldMapper

use of org.opensearch.join.mapper.ParentIdFieldMapper in project OpenSearch by opensearch-project.

the class ParentIdQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    if (context.allowExpensiveQueries() == false) {
        throw new OpenSearchException("[joining] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false.");
    }
    ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.getMapperService());
    if (joinFieldMapper == null) {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            final String indexName = context.getIndexSettings().getIndex().getName();
            throw new QueryShardException(context, "[" + NAME + "] no join field found for index [" + indexName + "]");
        }
    }
    final ParentIdFieldMapper childMapper = joinFieldMapper.getParentIdFieldMapper(type, false);
    if (childMapper == null) {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(context, "[" + NAME + "] no relation found for child [" + type + "]");
        }
    }
    return new BooleanQuery.Builder().add(childMapper.fieldType().termQuery(id, context), BooleanClause.Occur.MUST).add(joinFieldMapper.fieldType().termQuery(type, context), BooleanClause.Occur.FILTER).build();
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) ParentIdFieldMapper(org.opensearch.join.mapper.ParentIdFieldMapper) ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) QueryShardException(org.opensearch.index.query.QueryShardException) OpenSearchException(org.opensearch.OpenSearchException)

Example 2 with ParentIdFieldMapper

use of org.opensearch.join.mapper.ParentIdFieldMapper in project OpenSearch by opensearch-project.

the class ChildrenAggregationBuilder method resolveConfig.

@Override
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
    ValuesSourceConfig config;
    ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
    if (parentJoinFieldMapper == null) {
        // Unmapped field case
        config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext);
        return config;
    }
    ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
    if (parentIdFieldMapper == null) {
        // Unmapped field case
        config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext);
        return config;
    }
    parentFilter = parentIdFieldMapper.getParentFilter();
    childFilter = parentIdFieldMapper.getChildFilter(childType);
    MappedFieldType fieldType = parentIdFieldMapper.fieldType();
    config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext);
    return config;
}
Also used : ParentIdFieldMapper(org.opensearch.join.mapper.ParentIdFieldMapper) ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) ValuesSourceConfig(org.opensearch.search.aggregations.support.ValuesSourceConfig) MappedFieldType(org.opensearch.index.mapper.MappedFieldType)

Example 3 with ParentIdFieldMapper

use of org.opensearch.join.mapper.ParentIdFieldMapper in project OpenSearch by opensearch-project.

the class ParentAggregationBuilder method resolveConfig.

@Override
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
    ValuesSourceConfig config;
    ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
    ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
    if (parentIdFieldMapper != null) {
        parentFilter = parentIdFieldMapper.getParentFilter();
        childFilter = parentIdFieldMapper.getChildFilter(childType);
        MappedFieldType fieldType = parentIdFieldMapper.fieldType();
        config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext);
    } else {
        // unmapped case
        config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext);
    }
    return config;
}
Also used : ParentIdFieldMapper(org.opensearch.join.mapper.ParentIdFieldMapper) ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) ValuesSourceConfig(org.opensearch.search.aggregations.support.ValuesSourceConfig) MappedFieldType(org.opensearch.index.mapper.MappedFieldType)

Example 4 with ParentIdFieldMapper

use of org.opensearch.join.mapper.ParentIdFieldMapper in project OpenSearch by opensearch-project.

the class HasParentQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    if (context.allowExpensiveQueries() == false) {
        throw new OpenSearchException("[joining] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false.");
    }
    ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.getMapperService());
    if (joinFieldMapper == null) {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(context, "[" + NAME + "] no join field has been configured");
        }
    }
    ParentIdFieldMapper parentIdFieldMapper = joinFieldMapper.getParentIdFieldMapper(type, true);
    if (parentIdFieldMapper != null) {
        Query parentFilter = parentIdFieldMapper.getParentFilter();
        Query innerQuery = Queries.filtered(query.toQuery(context), parentFilter);
        Query childFilter = parentIdFieldMapper.getChildrenFilter();
        MappedFieldType fieldType = parentIdFieldMapper.fieldType();
        final SortedSetOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
        return new HasChildQueryBuilder.LateParsingQuery(childFilter, innerQuery, HasChildQueryBuilder.DEFAULT_MIN_CHILDREN, HasChildQueryBuilder.DEFAULT_MAX_CHILDREN, fieldType.name(), score ? ScoreMode.Max : ScoreMode.None, fieldData, context.getSearchSimilarity());
    } else {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(context, "[" + NAME + "] join field [" + joinFieldMapper.name() + "] doesn't hold [" + type + "] as a parent");
        }
    }
}
Also used : ParentIdFieldMapper(org.opensearch.join.mapper.ParentIdFieldMapper) ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) QueryShardException(org.opensearch.index.query.QueryShardException) SortedSetOrdinalsIndexFieldData(org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData) OpenSearchException(org.opensearch.OpenSearchException)

Example 5 with ParentIdFieldMapper

use of org.opensearch.join.mapper.ParentIdFieldMapper in project OpenSearch by opensearch-project.

the class HasChildQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    if (context.allowExpensiveQueries() == false) {
        throw new OpenSearchException("[joining] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false.");
    }
    ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.getMapperService());
    if (joinFieldMapper == null) {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(context, "[" + NAME + "] no join field has been configured");
        }
    }
    ParentIdFieldMapper parentIdFieldMapper = joinFieldMapper.getParentIdFieldMapper(type, false);
    if (parentIdFieldMapper != null) {
        Query parentFilter = parentIdFieldMapper.getParentFilter();
        Query childFilter = parentIdFieldMapper.getChildFilter(type);
        Query innerQuery = Queries.filtered(query.toQuery(context), childFilter);
        MappedFieldType fieldType = parentIdFieldMapper.fieldType();
        final SortedSetOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
        return new LateParsingQuery(parentFilter, innerQuery, minChildren(), maxChildren(), fieldType.name(), scoreMode, fieldData, context.getSearchSimilarity());
    } else {
        if (ignoreUnmapped) {
            return new MatchNoDocsQuery();
        } else {
            throw new QueryShardException(context, "[" + NAME + "] join field [" + joinFieldMapper.name() + "] doesn't hold [" + type + "] as a child");
        }
    }
}
Also used : ParentIdFieldMapper(org.opensearch.join.mapper.ParentIdFieldMapper) ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) QueryShardException(org.opensearch.index.query.QueryShardException) SortedSetOrdinalsIndexFieldData(org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData) OpenSearchException(org.opensearch.OpenSearchException)

Aggregations

ParentIdFieldMapper (org.opensearch.join.mapper.ParentIdFieldMapper)5 ParentJoinFieldMapper (org.opensearch.join.mapper.ParentJoinFieldMapper)5 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)4 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 OpenSearchException (org.opensearch.OpenSearchException)3 QueryShardException (org.opensearch.index.query.QueryShardException)3 Query (org.apache.lucene.search.Query)2 SortedSetOrdinalsIndexFieldData (org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData)2 ValuesSourceConfig (org.opensearch.search.aggregations.support.ValuesSourceConfig)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)1