Search in sources :

Example 6 with ParentFieldMapper

use of org.elasticsearch.index.mapper.ParentFieldMapper in project elasticsearch by elastic.

the class ParentToChildrenAggregatorTests method mapperServiceMock.

@Override
protected MapperService mapperServiceMock() {
    MapperService mapperService = mock(MapperService.class);
    DocumentMapper childDocMapper = mock(DocumentMapper.class);
    DocumentMapper parentDocMapper = mock(DocumentMapper.class);
    ParentFieldMapper parentFieldMapper = createParentFieldMapper();
    when(childDocMapper.parentFieldMapper()).thenReturn(parentFieldMapper);
    when(parentDocMapper.parentFieldMapper()).thenReturn(parentFieldMapper);
    when(mapperService.documentMapper(CHILD_TYPE)).thenReturn(childDocMapper);
    when(mapperService.documentMapper(PARENT_TYPE)).thenReturn(parentDocMapper);
    when(mapperService.docMappers(false)).thenReturn(Arrays.asList(new DocumentMapper[] { childDocMapper, parentDocMapper }));
    when(parentDocMapper.typeFilter()).thenReturn(new TypeFieldMapper.TypesQuery(new BytesRef(PARENT_TYPE)));
    when(childDocMapper.typeFilter()).thenReturn(new TypeFieldMapper.TypesQuery(new BytesRef(CHILD_TYPE)));
    return mapperService;
}
Also used : TypeFieldMapper(org.elasticsearch.index.mapper.TypeFieldMapper) ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) MapperService(org.elasticsearch.index.mapper.MapperService) BytesRef(org.apache.lucene.util.BytesRef)

Example 7 with ParentFieldMapper

use of org.elasticsearch.index.mapper.ParentFieldMapper in project elasticsearch by elastic.

the class ParentFieldSubFetchPhaseTests method testGetParentIdNoParentField.

public void testGetParentIdNoParentField() throws Exception {
    ParentFieldMapper fieldMapper = createParentFieldMapper();
    Directory directory = newDirectory();
    IndexWriter indexWriter = new IndexWriter(directory, newIndexWriterConfig());
    Document document = new Document();
    document.add(new SortedDocValuesField("different_field", new BytesRef("1")));
    indexWriter.addDocument(document);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    String id = ParentFieldSubFetchPhase.getParentId(fieldMapper, indexReader.leaves().get(0).reader(), 0);
    assertNull(id);
    indexReader.close();
    directory.close();
}
Also used : ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) IndexWriter(org.apache.lucene.index.IndexWriter) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) IndexReader(org.apache.lucene.index.IndexReader) Document(org.apache.lucene.document.Document) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory)

Example 8 with ParentFieldMapper

use of org.elasticsearch.index.mapper.ParentFieldMapper in project elasticsearch by elastic.

the class ChildrenAggregationBuilder method resolveConfig.

@Override
protected ValuesSourceConfig<ParentChild> resolveConfig(SearchContext context) {
    ValuesSourceConfig<ParentChild> config = new ValuesSourceConfig<>(ValuesSourceType.BYTES);
    DocumentMapper childDocMapper = context.mapperService().documentMapper(childType);
    if (childDocMapper != null) {
        ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
        if (!parentFieldMapper.active()) {
            throw new IllegalArgumentException("[children] no [_parent] field not configured that points to a parent type");
        }
        parentType = parentFieldMapper.type();
        DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);
        if (parentDocMapper != null) {
            parentFilter = parentDocMapper.typeFilter();
            childFilter = childDocMapper.typeFilter();
            ParentChildIndexFieldData parentChildIndexFieldData = context.fieldData().getForField(parentFieldMapper.fieldType());
            config.fieldContext(new FieldContext(parentFieldMapper.fieldType().name(), parentChildIndexFieldData, parentFieldMapper.fieldType()));
        } else {
            config.unmapped(true);
        }
    } else {
        config.unmapped(true);
    }
    return config;
}
Also used : ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ValuesSourceConfig(org.elasticsearch.search.aggregations.support.ValuesSourceConfig) FieldContext(org.elasticsearch.search.aggregations.support.FieldContext) ParentChildIndexFieldData(org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData) ParentChild(org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild)

Aggregations

ParentFieldMapper (org.elasticsearch.index.mapper.ParentFieldMapper)8 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)5 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 BytesRef (org.apache.lucene.util.BytesRef)3 ParentChildIndexFieldData (org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData)3 Document (org.apache.lucene.document.Document)2 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)2 IndexReader (org.apache.lucene.index.IndexReader)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 Query (org.apache.lucene.search.Query)2 Directory (org.apache.lucene.store.Directory)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 HashSet (java.util.HashSet)1 Term (org.apache.lucene.index.Term)1 DocValuesTermsQuery (org.apache.lucene.search.DocValuesTermsQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 MapperService (org.elasticsearch.index.mapper.MapperService)1 TypeFieldMapper (org.elasticsearch.index.mapper.TypeFieldMapper)1 SearchHitField (org.elasticsearch.search.SearchHitField)1