Search in sources :

Example 1 with ValuesSourceConfig

use of org.opensearch.search.aggregations.support.ValuesSourceConfig 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 2 with ValuesSourceConfig

use of org.opensearch.search.aggregations.support.ValuesSourceConfig 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 3 with ValuesSourceConfig

use of org.opensearch.search.aggregations.support.ValuesSourceConfig in project OpenSearch by opensearch-project.

the class DiversifiedAggregatorFactory method registerAggregators.

public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
    builder.register(DiversifiedAggregationBuilder.REGISTRY_KEY, org.opensearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN), (String name, int shardSize, AggregatorFactories factories, SearchContext context, Aggregator parent, Map<String, Object> metadata, ValuesSourceConfig valuesSourceConfig, int maxDocsPerValue, String executionHint) -> new DiversifiedNumericSamplerAggregator(name, shardSize, factories, context, parent, metadata, valuesSourceConfig, maxDocsPerValue), true);
    builder.register(DiversifiedAggregationBuilder.REGISTRY_KEY, CoreValuesSourceType.BYTES, (String name, int shardSize, AggregatorFactories factories, SearchContext context, Aggregator parent, Map<String, Object> metadata, ValuesSourceConfig valuesSourceConfig, int maxDocsPerValue, String executionHint) -> {
        ExecutionMode execution = null;
        if (executionHint != null) {
            execution = ExecutionMode.fromString(executionHint);
        }
        // In some cases using ordinals is just not supported: override it
        if (execution == null) {
            execution = ExecutionMode.GLOBAL_ORDINALS;
        }
        if ((execution.needsGlobalOrdinals()) && (valuesSourceConfig.hasGlobalOrdinals() == false)) {
            execution = ExecutionMode.MAP;
        }
        return execution.create(name, factories, shardSize, maxDocsPerValue, valuesSourceConfig, context, parent, metadata);
    }, true);
}
Also used : ValuesSourceConfig(org.opensearch.search.aggregations.support.ValuesSourceConfig) AggregatorFactories(org.opensearch.search.aggregations.AggregatorFactories) SearchContext(org.opensearch.search.internal.SearchContext) NonCollectingAggregator(org.opensearch.search.aggregations.NonCollectingAggregator) Aggregator(org.opensearch.search.aggregations.Aggregator) ExecutionMode(org.opensearch.search.aggregations.bucket.sampler.SamplerAggregator.ExecutionMode) Map(java.util.Map)

Aggregations

ValuesSourceConfig (org.opensearch.search.aggregations.support.ValuesSourceConfig)3 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)2 ParentIdFieldMapper (org.opensearch.join.mapper.ParentIdFieldMapper)2 ParentJoinFieldMapper (org.opensearch.join.mapper.ParentJoinFieldMapper)2 Map (java.util.Map)1 Aggregator (org.opensearch.search.aggregations.Aggregator)1 AggregatorFactories (org.opensearch.search.aggregations.AggregatorFactories)1 NonCollectingAggregator (org.opensearch.search.aggregations.NonCollectingAggregator)1 ExecutionMode (org.opensearch.search.aggregations.bucket.sampler.SamplerAggregator.ExecutionMode)1 SearchContext (org.opensearch.search.internal.SearchContext)1