Search in sources :

Example 1 with SearchLookup

use of org.elasticsearch.search.lookup.SearchLookup in project elasticsearch by elastic.

the class AggregatorTestCase method createAggregator.

protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder, IndexSearcher indexSearcher, MappedFieldType... fieldTypes) throws IOException {
    IndexSettings indexSettings = createIndexSettings();
    SearchContext searchContext = createSearchContext(indexSearcher, indexSettings);
    CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
    when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
    // TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
    MapperService mapperService = mapperServiceMock();
    when(mapperService.hasNested()).thenReturn(false);
    when(searchContext.mapperService()).thenReturn(mapperService);
    IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
    }), circuitBreakerService, mapperService);
    when(searchContext.fieldData()).thenReturn(ifds);
    SearchLookup searchLookup = new SearchLookup(mapperService, ifds, new String[] { "type" });
    when(searchContext.lookup()).thenReturn(searchLookup);
    QueryShardContext queryShardContext = queryShardContextMock(fieldTypes, indexSettings, circuitBreakerService);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
    @SuppressWarnings("unchecked") A aggregator = (A) aggregationBuilder.build(searchContext, null).create(null, true);
    return aggregator;
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) MapperService(org.elasticsearch.index.mapper.MapperService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Example 2 with SearchLookup

use of org.elasticsearch.search.lookup.SearchLookup in project elasticsearch by elastic.

the class ExpressionTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");
    service = new ExpressionScriptEngineService(Settings.EMPTY);
    lookup = new SearchLookup(index.mapperService(), index.fieldData(), null);
}
Also used : IndexService(org.elasticsearch.index.IndexService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Example 3 with SearchLookup

use of org.elasticsearch.search.lookup.SearchLookup in project elasticsearch by elastic.

the class NeedsScoreTests method testNeedsScores.

public void testNeedsScores() {
    IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");
    PainlessScriptEngineService service = new PainlessScriptEngineService(Settings.EMPTY);
    SearchLookup lookup = new SearchLookup(index.mapperService(), index.fieldData(), null);
    Object compiled = service.compile(null, "1.2", Collections.emptyMap());
    SearchScript ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled), lookup, Collections.<String, Object>emptyMap());
    assertFalse(ss.needsScores());
    compiled = service.compile(null, "doc['d'].value", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled), lookup, Collections.<String, Object>emptyMap());
    assertFalse(ss.needsScores());
    compiled = service.compile(null, "1/_score", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled), lookup, Collections.<String, Object>emptyMap());
    assertTrue(ss.needsScores());
    compiled = service.compile(null, "doc['d'].value * _score", Collections.emptyMap());
    ss = service.search(new CompiledScript(ScriptType.INLINE, "randomName", "painless", compiled), lookup, Collections.<String, Object>emptyMap());
    assertTrue(ss.needsScores());
    service.close();
}
Also used : CompiledScript(org.elasticsearch.script.CompiledScript) SearchScript(org.elasticsearch.script.SearchScript) IndexService(org.elasticsearch.index.IndexService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Aggregations

SearchLookup (org.elasticsearch.search.lookup.SearchLookup)3 IndexService (org.elasticsearch.index.IndexService)2 MockBigArrays (org.elasticsearch.common.util.MockBigArrays)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 IndexFieldDataService (org.elasticsearch.index.fielddata.IndexFieldDataService)1 MapperService (org.elasticsearch.index.mapper.MapperService)1 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)1 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)1 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)1 IndicesFieldDataCache (org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache)1 CompiledScript (org.elasticsearch.script.CompiledScript)1 SearchScript (org.elasticsearch.script.SearchScript)1 SearchContext (org.elasticsearch.search.internal.SearchContext)1