Search in sources :

Example 41 with QueryShardContext

use of org.elasticsearch.index.query.QueryShardContext in project elasticsearch by elastic.

the class Murmur3FieldMapperTests method setup.

@Before
public void setup() {
    indexService = createIndex("test");
    mapperRegistry = new MapperRegistry(Collections.singletonMap(Murmur3FieldMapper.CONTENT_TYPE, new Murmur3FieldMapper.TypeParser()), Collections.emptyMap());
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Before(org.junit.Before)

Example 42 with QueryShardContext

use of org.elasticsearch.index.query.QueryShardContext in project elasticsearch by elastic.

the class FieldNamesFieldMapperTests method testSeesFieldsFromPlugins.

public void testSeesFieldsFromPlugins() throws IOException {
    IndexService indexService = createIndex("test");
    IndicesModule indicesModule = newTestIndicesModule(Collections.emptyMap(), Collections.singletonMap("_dummy", new DummyMetadataFieldMapper.TypeParser()));
    final MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    MapperService mapperService = new MapperService(indexService.getIndexSettings(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapperParser parser = new DocumentMapperParser(indexService.getIndexSettings(), mapperService, indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    ParsedDocument parsedDocument = mapper.parse("index", "type", "id", new BytesArray("{}"));
    IndexableField[] fields = parsedDocument.rootDoc().getFields(FieldNamesFieldMapper.NAME);
    boolean found = false;
    for (IndexableField f : fields) {
        if ("_dummy".equals(f.stringValue())) {
            found = true;
            break;
        }
    }
    assertTrue("Could not find the dummy field among " + Arrays.toString(fields), found);
}
Also used : IndicesModule(org.elasticsearch.indices.IndicesModule) BytesArray(org.elasticsearch.common.bytes.BytesArray) IndexService(org.elasticsearch.index.IndexService) IndexableField(org.apache.lucene.index.IndexableField) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext)

Example 43 with QueryShardContext

use of org.elasticsearch.index.query.QueryShardContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testLong.

public void testLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long");
    client().prepareIndex("index", "type", "1").setSource("long", 42).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 44 with QueryShardContext

use of org.elasticsearch.index.query.QueryShardContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testEmptyBoolean.

public void testEmptyBoolean() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bool", "type=boolean");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "bool", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "bool", null, true, null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(1, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 45 with QueryShardContext

use of org.elasticsearch.index.query.QueryShardContext in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testUnmappedBoolean.

public void testUnmappedBoolean() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "bool", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        assertNull(valuesSource);
        config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "bool", null, true, null, null);
        valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(1, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Aggregations

QueryShardContext (org.elasticsearch.index.query.QueryShardContext)49 IndexService (org.elasticsearch.index.IndexService)17 Query (org.apache.lucene.search.Query)13 Settings (org.elasticsearch.common.settings.Settings)12 IndexSettings (org.elasticsearch.index.IndexSettings)11 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)9 Searcher (org.elasticsearch.index.engine.Engine.Searcher)9 TermQuery (org.apache.lucene.search.TermQuery)8 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)8 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)7 BytesRef (org.apache.lucene.util.BytesRef)7 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)6 BoostQuery (org.apache.lucene.search.BoostQuery)6 Version (org.elasticsearch.Version)6 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Term (org.apache.lucene.index.Term)5 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)5