Search in sources :

Example 1 with ParentJoinFieldMapper

use of org.opensearch.join.mapper.ParentJoinFieldMapper 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 ParentJoinFieldMapper

use of org.opensearch.join.mapper.ParentJoinFieldMapper 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 ParentJoinFieldMapper

use of org.opensearch.join.mapper.ParentJoinFieldMapper 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 ParentJoinFieldMapper

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

the class ParentToChildrenAggregatorTests method mapperServiceMock.

@Override
protected MapperService mapperServiceMock() {
    ParentJoinFieldMapper joinFieldMapper = createJoinFieldMapper();
    MapperService mapperService = mock(MapperService.class);
    MetaJoinFieldMapper.MetaJoinFieldType metaJoinFieldType = mock(MetaJoinFieldMapper.MetaJoinFieldType.class);
    when(metaJoinFieldType.getJoinField()).thenReturn("join_field");
    when(mapperService.fieldType("_parent_join")).thenReturn(metaJoinFieldType);
    MappingLookup fieldMappers = new MappingLookup(Collections.singleton(joinFieldMapper), Collections.emptyList(), Collections.emptyList(), 0, null);
    DocumentMapper mockMapper = mock(DocumentMapper.class);
    when(mockMapper.mappers()).thenReturn(fieldMappers);
    when(mapperService.documentMapper()).thenReturn(mockMapper);
    return mapperService;
}
Also used : ParentJoinFieldMapper(org.opensearch.join.mapper.ParentJoinFieldMapper) MappingLookup(org.opensearch.index.mapper.MappingLookup) MetaJoinFieldMapper(org.opensearch.join.mapper.MetaJoinFieldMapper) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) MapperService(org.opensearch.index.mapper.MapperService)

Example 5 with ParentJoinFieldMapper

use of org.opensearch.join.mapper.ParentJoinFieldMapper 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)

Aggregations

ParentJoinFieldMapper (org.opensearch.join.mapper.ParentJoinFieldMapper)8 ParentIdFieldMapper (org.opensearch.join.mapper.ParentIdFieldMapper)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 DocumentMapper (org.opensearch.index.mapper.DocumentMapper)2 MapperService (org.opensearch.index.mapper.MapperService)2 MappingLookup (org.opensearch.index.mapper.MappingLookup)2 MetaJoinFieldMapper (org.opensearch.join.mapper.MetaJoinFieldMapper)2 ValuesSourceConfig (org.opensearch.search.aggregations.support.ValuesSourceConfig)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 QueryShardContext (org.opensearch.index.query.QueryShardContext)1