Search in sources :

Example 1 with FetchSourcePhase

use of org.opensearch.search.fetch.subphase.FetchSourcePhase in project OpenSearch by opensearch-project.

the class SearchModule method registerFetchSubPhases.

private void registerFetchSubPhases(List<SearchPlugin> plugins) {
    registerFetchSubPhase(new ExplainPhase());
    registerFetchSubPhase(new FetchDocValuesPhase());
    registerFetchSubPhase(new ScriptFieldsPhase());
    registerFetchSubPhase(new FetchSourcePhase());
    registerFetchSubPhase(new FetchFieldsPhase());
    registerFetchSubPhase(new FetchVersionPhase());
    registerFetchSubPhase(new SeqNoPrimaryTermPhase());
    registerFetchSubPhase(new MatchedQueriesPhase());
    registerFetchSubPhase(new HighlightPhase(highlighters));
    registerFetchSubPhase(new FetchScorePhase());
    FetchPhaseConstructionContext context = new FetchPhaseConstructionContext(highlighters);
    registerFromPlugin(plugins, p -> p.getFetchSubPhases(context), this::registerFetchSubPhase);
}
Also used : ScriptFieldsPhase(org.opensearch.search.fetch.subphase.ScriptFieldsPhase) ExplainPhase(org.opensearch.search.fetch.subphase.ExplainPhase) MatchedQueriesPhase(org.opensearch.search.fetch.subphase.MatchedQueriesPhase) FetchSourcePhase(org.opensearch.search.fetch.subphase.FetchSourcePhase) FetchScorePhase(org.opensearch.search.fetch.subphase.FetchScorePhase) SeqNoPrimaryTermPhase(org.opensearch.search.fetch.subphase.SeqNoPrimaryTermPhase) FetchPhaseConstructionContext(org.opensearch.plugins.SearchPlugin.FetchPhaseConstructionContext) FetchDocValuesPhase(org.opensearch.search.fetch.subphase.FetchDocValuesPhase) FetchVersionPhase(org.opensearch.search.fetch.subphase.FetchVersionPhase) FetchFieldsPhase(org.opensearch.search.fetch.subphase.FetchFieldsPhase) HighlightPhase(org.opensearch.search.fetch.subphase.highlight.HighlightPhase)

Example 2 with FetchSourcePhase

use of org.opensearch.search.fetch.subphase.FetchSourcePhase in project OpenSearch by opensearch-project.

the class AggregatorTestCase method createSearchContext.

protected SearchContext createSearchContext(IndexSearcher indexSearcher, IndexSettings indexSettings, Query query, MultiBucketConsumer bucketConsumer, CircuitBreakerService circuitBreakerService, MappedFieldType... fieldTypes) throws IOException {
    QueryCache queryCache = new DisabledQueryCache(indexSettings);
    QueryCachingPolicy queryCachingPolicy = new QueryCachingPolicy() {

        @Override
        public void onUse(Query query) {
        }

        @Override
        public boolean shouldCache(Query query) {
            // never cache a query
            return false;
        }
    };
    ContextIndexSearcher contextIndexSearcher = new ContextIndexSearcher(indexSearcher.getIndexReader(), indexSearcher.getSimilarity(), queryCache, queryCachingPolicy, false);
    SearchContext searchContext = mock(SearchContext.class);
    when(searchContext.numberOfShards()).thenReturn(1);
    when(searchContext.searcher()).thenReturn(contextIndexSearcher);
    when(searchContext.fetchPhase()).thenReturn(new FetchPhase(Arrays.asList(new FetchSourcePhase(), new FetchDocValuesPhase())));
    when(searchContext.bitsetFilterCache()).thenReturn(new BitsetFilterCache(indexSettings, mock(Listener.class)));
    IndexShard indexShard = mock(IndexShard.class);
    when(indexShard.shardId()).thenReturn(new ShardId("test", "test", 0));
    when(searchContext.indexShard()).thenReturn(indexShard);
    when(searchContext.aggregations()).thenReturn(new SearchContextAggregations(AggregatorFactories.EMPTY, bucketConsumer));
    when(searchContext.query()).thenReturn(query);
    /*
         * Always use the circuit breaking big arrays instance so that the CircuitBreakerService
         * we're passed gets a chance to break.
         */
    BigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking();
    when(searchContext.bigArrays()).thenReturn(bigArrays);
    // TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
    MapperService mapperService = mapperServiceMock();
    when(mapperService.getIndexSettings()).thenReturn(indexSettings);
    when(mapperService.hasNested()).thenReturn(false);
    when(searchContext.mapperService()).thenReturn(mapperService);
    IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
    }), circuitBreakerService, mapperService);
    QueryShardContext queryShardContext = queryShardContextMock(contextIndexSearcher, mapperService, indexSettings, circuitBreakerService, bigArrays);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
    when(queryShardContext.getObjectMapper(anyString())).thenAnswer(invocation -> {
        String fieldName = (String) invocation.getArguments()[0];
        if (fieldName.startsWith(NESTEDFIELD_PREFIX)) {
            BuilderContext context = new BuilderContext(indexSettings.getSettings(), new ContentPath());
            return new ObjectMapper.Builder<>(fieldName).nested(Nested.newNested()).build(context);
        }
        return null;
    });
    Map<String, MappedFieldType> fieldNameToType = new HashMap<>();
    fieldNameToType.putAll(Arrays.stream(fieldTypes).filter(Objects::nonNull).collect(Collectors.toMap(MappedFieldType::name, Function.identity())));
    fieldNameToType.putAll(getFieldAliases(fieldTypes));
    registerFieldTypes(searchContext, mapperService, fieldNameToType);
    doAnswer(invocation -> {
        /* Store the release-ables so we can release them at the end of the test case. This is important because aggregations don't
             * close their sub-aggregations. This is fairly similar to what the production code does. */
        releasables.add((Releasable) invocation.getArguments()[0]);
        return null;
    }).when(searchContext).addReleasable(any());
    return searchContext;
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) QueryCache(org.apache.lucene.search.QueryCache) DisabledQueryCache(org.opensearch.index.cache.query.DisabledQueryCache) Listener(org.opensearch.index.cache.bitset.BitsetFilterCache.Listener) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) HashMap(java.util.HashMap) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Builder(org.opensearch.search.aggregations.AggregatorFactories.Builder) NestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.NestedAggregationBuilder) ContextIndexSearcher(org.opensearch.search.internal.ContextIndexSearcher) SearchContext(org.opensearch.search.internal.SearchContext) MockBigArrays(org.opensearch.common.util.MockBigArrays) Mockito.anyString(org.mockito.Mockito.anyString) ShardId(org.opensearch.index.shard.ShardId) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) QueryShardContext(org.opensearch.index.query.QueryShardContext) IndexShard(org.opensearch.index.shard.IndexShard) FetchSourcePhase(org.opensearch.search.fetch.subphase.FetchSourcePhase) FetchDocValuesPhase(org.opensearch.search.fetch.subphase.FetchDocValuesPhase) ContentPath(org.opensearch.index.mapper.ContentPath) IndicesFieldDataCache(org.opensearch.indices.fielddata.cache.IndicesFieldDataCache) MockBigArrays(org.opensearch.common.util.MockBigArrays) BigArrays(org.opensearch.common.util.BigArrays) IndexFieldDataService(org.opensearch.index.fielddata.IndexFieldDataService) FetchPhase(org.opensearch.search.fetch.FetchPhase) Objects(java.util.Objects) BuilderContext(org.opensearch.index.mapper.Mapper.BuilderContext) BitsetFilterCache(org.opensearch.index.cache.bitset.BitsetFilterCache) DisabledQueryCache(org.opensearch.index.cache.query.DisabledQueryCache) MapperService(org.opensearch.index.mapper.MapperService)

Aggregations

FetchDocValuesPhase (org.opensearch.search.fetch.subphase.FetchDocValuesPhase)2 FetchSourcePhase (org.opensearch.search.fetch.subphase.FetchSourcePhase)2 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 QueryCache (org.apache.lucene.search.QueryCache)1 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)1 Mockito.anyString (org.mockito.Mockito.anyString)1 BigArrays (org.opensearch.common.util.BigArrays)1 MockBigArrays (org.opensearch.common.util.MockBigArrays)1 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 BitsetFilterCache (org.opensearch.index.cache.bitset.BitsetFilterCache)1 Listener (org.opensearch.index.cache.bitset.BitsetFilterCache.Listener)1 DisabledQueryCache (org.opensearch.index.cache.query.DisabledQueryCache)1 IndexFieldDataService (org.opensearch.index.fielddata.IndexFieldDataService)1 ContentPath (org.opensearch.index.mapper.ContentPath)1 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)1 BuilderContext (org.opensearch.index.mapper.Mapper.BuilderContext)1