Search in sources :

Example 1 with SortedSetOrdinalsIndexFieldData

use of org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData in project OpenSearch by opensearch-project.

the class IndexFieldDataServiceTests method testGetForFieldDefaults.

public void testGetForFieldDefaults() {
    final IndexService indexService = createIndex("test");
    final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    final IndexFieldDataService ifdService = new IndexFieldDataService(indexService.getIndexSettings(), indicesService.getIndicesFieldDataCache(), indicesService.getCircuitBreakerService(), indexService.mapperService());
    final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
    final MappedFieldType stringMapper = new KeywordFieldMapper.Builder("string").build(ctx).fieldType();
    ifdService.clear();
    IndexFieldData<?> fd = ifdService.getForField(stringMapper, "test", () -> {
        throw new UnsupportedOperationException();
    });
    assertTrue(fd instanceof SortedSetOrdinalsIndexFieldData);
    for (MappedFieldType mapper : Arrays.asList(new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.BYTE, false, true).build(ctx).fieldType(), new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.SHORT, false, true).build(ctx).fieldType(), new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.INTEGER, false, true).build(ctx).fieldType(), new NumberFieldMapper.Builder("long", NumberFieldMapper.NumberType.LONG, false, true).build(ctx).fieldType())) {
        ifdService.clear();
        fd = ifdService.getForField(mapper, "test", () -> {
            throw new UnsupportedOperationException();
        });
        assertTrue(fd instanceof SortedNumericIndexFieldData);
    }
    final MappedFieldType floatMapper = new NumberFieldMapper.Builder("float", NumberFieldMapper.NumberType.FLOAT, false, true).build(ctx).fieldType();
    ifdService.clear();
    fd = ifdService.getForField(floatMapper, "test", () -> {
        throw new UnsupportedOperationException();
    });
    assertTrue(fd instanceof SortedNumericIndexFieldData);
    final MappedFieldType doubleMapper = new NumberFieldMapper.Builder("double", NumberFieldMapper.NumberType.DOUBLE, false, true).build(ctx).fieldType();
    ifdService.clear();
    fd = ifdService.getForField(doubleMapper, "test", () -> {
        throw new UnsupportedOperationException();
    });
    assertTrue(fd instanceof SortedNumericIndexFieldData);
}
Also used : NumberFieldMapper(org.opensearch.index.mapper.NumberFieldMapper) IndexService(org.opensearch.index.IndexService) IndicesService(org.opensearch.indices.IndicesService) SortedSetOrdinalsIndexFieldData(org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData) ContentPath(org.opensearch.index.mapper.ContentPath) SortedNumericIndexFieldData(org.opensearch.index.fielddata.plain.SortedNumericIndexFieldData) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) BuilderContext(org.opensearch.index.mapper.Mapper.BuilderContext)

Example 2 with SortedSetOrdinalsIndexFieldData

use of org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData in project OpenSearch by opensearch-project.

the class FieldDataCacheTests method testLoadGlobal_neverCacheIfFieldIsMissing.

public void testLoadGlobal_neverCacheIfFieldIsMissing() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    iwc.setMergePolicy(NoMergePolicy.INSTANCE);
    IndexWriter iw = new IndexWriter(dir, iwc);
    long numDocs = scaledRandomIntBetween(32, 128);
    for (int i = 1; i <= numDocs; i++) {
        Document doc = new Document();
        doc.add(new SortedSetDocValuesField("field1", new BytesRef(String.valueOf(i))));
        doc.add(new StringField("field2", String.valueOf(i), Field.Store.NO));
        iw.addDocument(doc);
        if (i % 24 == 0) {
            iw.commit();
        }
    }
    iw.close();
    DirectoryReader ir = OpenSearchDirectoryReader.wrap(DirectoryReader.open(dir), new ShardId("_index", "_na_", 0));
    DummyAccountingFieldDataCache fieldDataCache = new DummyAccountingFieldDataCache();
    // Testing SortedSetOrdinalsIndexFieldData:
    SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData = createSortedDV("field1", fieldDataCache);
    sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
    assertThat(fieldDataCache.cachedGlobally, equalTo(1));
    sortedSetOrdinalsIndexFieldData.loadGlobal(new FieldMaskingReader("field1", ir));
    assertThat(fieldDataCache.cachedGlobally, equalTo(1));
    // Testing PagedBytesIndexFieldData
    PagedBytesIndexFieldData pagedBytesIndexFieldData = createPagedBytes("field2", fieldDataCache);
    pagedBytesIndexFieldData.loadGlobal(ir);
    assertThat(fieldDataCache.cachedGlobally, equalTo(2));
    pagedBytesIndexFieldData.loadGlobal(new FieldMaskingReader("field2", ir));
    assertThat(fieldDataCache.cachedGlobally, equalTo(2));
    ir.close();
    dir.close();
}
Also used : PagedBytesIndexFieldData(org.opensearch.index.fielddata.plain.PagedBytesIndexFieldData) OpenSearchDirectoryReader(org.opensearch.common.lucene.index.OpenSearchDirectoryReader) DirectoryReader(org.apache.lucene.index.DirectoryReader) SortedSetOrdinalsIndexFieldData(org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData) FieldMaskingReader(org.opensearch.test.FieldMaskingReader) Document(org.apache.lucene.document.Document) ShardId(org.opensearch.index.shard.ShardId) IndexWriter(org.apache.lucene.index.IndexWriter) StringField(org.apache.lucene.document.StringField) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 3 with SortedSetOrdinalsIndexFieldData

use of org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData 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)

Example 4 with SortedSetOrdinalsIndexFieldData

use of org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData in project OpenSearch by opensearch-project.

the class HasChildQueryBuilder 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, false);
    if (parentIdFieldMapper != null) {
        Query parentFilter = parentIdFieldMapper.getParentFilter();
        Query childFilter = parentIdFieldMapper.getChildFilter(type);
        Query innerQuery = Queries.filtered(query.toQuery(context), childFilter);
        MappedFieldType fieldType = parentIdFieldMapper.fieldType();
        final SortedSetOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
        return new LateParsingQuery(parentFilter, innerQuery, minChildren(), maxChildren(), fieldType.name(), scoreMode, 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 child");
        }
    }
}
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

SortedSetOrdinalsIndexFieldData (org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData)4 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)3 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)2 Query (org.apache.lucene.search.Query)2 OpenSearchException (org.opensearch.OpenSearchException)2 QueryShardException (org.opensearch.index.query.QueryShardException)2 ParentIdFieldMapper (org.opensearch.join.mapper.ParentIdFieldMapper)2 ParentJoinFieldMapper (org.opensearch.join.mapper.ParentJoinFieldMapper)2 Document (org.apache.lucene.document.Document)1 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)1 StringField (org.apache.lucene.document.StringField)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 Directory (org.apache.lucene.store.Directory)1 BytesRef (org.apache.lucene.util.BytesRef)1 OpenSearchDirectoryReader (org.opensearch.common.lucene.index.OpenSearchDirectoryReader)1 IndexService (org.opensearch.index.IndexService)1 PagedBytesIndexFieldData (org.opensearch.index.fielddata.plain.PagedBytesIndexFieldData)1 SortedNumericIndexFieldData (org.opensearch.index.fielddata.plain.SortedNumericIndexFieldData)1