List of usage examples for org.apache.lucene.search DocValuesTermsQuery DocValuesTermsQuery
public DocValuesTermsQuery(String field, String... terms)
From source file:org.elasticsearch.index.query.ParentIdQueryBuilder.java
License:Apache License
@Override protected Query doToQuery(QueryShardContext context) throws IOException { DocumentMapper childDocMapper = context.getMapperService().documentMapper(type); if (childDocMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else {// w w w. j av a 2s. com throw new QueryShardException(context, "[" + NAME + "] no mapping found for type [" + type + "]"); } } ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); if (parentFieldMapper.active() == false) { throw new QueryShardException(context, "[" + NAME + "] _parent field has no parent type configured"); } String fieldName = ParentFieldMapper.joinField(parentFieldMapper.type()); BooleanQuery.Builder query = new BooleanQuery.Builder(); query.add(new DocValuesTermsQuery(fieldName, id), BooleanClause.Occur.MUST); // Need to take child type into account, otherwise a child doc of different type with the same id could match query.add(new TermQuery(new Term(TypeFieldMapper.NAME, type)), BooleanClause.Occur.FILTER); return query.build(); }
From source file:org.elasticsearch.index.query.ParentIdQueryBuilderTests.java
License:Apache License
@Override protected void doAssertLuceneQuery(ParentIdQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, Matchers.instanceOf(BooleanQuery.class)); BooleanQuery booleanQuery = (BooleanQuery) query; assertThat(booleanQuery.clauses().size(), Matchers.equalTo(2)); DocValuesTermsQuery idQuery = (DocValuesTermsQuery) booleanQuery.clauses().get(0).getQuery(); // there are no getters to get the field and terms on DocValuesTermsQuery, so lets validate by creating a // new query based on the builder: assertThat(idQuery,/* ww w . j av a 2 s. c o m*/ Matchers.equalTo(new DocValuesTermsQuery("_parent#" + PARENT_TYPE, queryBuilder.getId()))); TermQuery typeQuery = (TermQuery) booleanQuery.clauses().get(1).getQuery(); assertThat(typeQuery.getTerm().field(), Matchers.equalTo(TypeFieldMapper.NAME)); assertThat(typeQuery.getTerm().text(), Matchers.equalTo(queryBuilder.getType())); }
From source file:org.elasticsearch.join.query.LegacyParentIdQueryBuilderTests.java
License:Apache License
@Override protected void doAssertLuceneQuery(ParentIdQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { assertThat(query, Matchers.instanceOf(BooleanQuery.class)); BooleanQuery booleanQuery = (BooleanQuery) query; assertThat(booleanQuery.clauses().size(), Matchers.equalTo(2)); DocValuesTermsQuery idQuery = (DocValuesTermsQuery) booleanQuery.clauses().get(0).getQuery(); // there are no getters to get the field and terms on DocValuesTermsQuery, so lets validate by creating a // new query based on the builder: assertThat(idQuery,/*from ww w . ja v a2s.c o m*/ Matchers.equalTo(new DocValuesTermsQuery("_parent#" + PARENT_TYPE, queryBuilder.getId()))); TermQuery typeQuery = (TermQuery) booleanQuery.clauses().get(1).getQuery(); assertThat(typeQuery.getTerm().field(), Matchers.equalTo(TypeFieldMapper.NAME)); assertThat(typeQuery.getTerm().text(), Matchers.equalTo(queryBuilder.getType())); }
From source file:org.elasticsearch.join.query.ParentIdQueryBuilder.java
License:Apache License
/** * Creates parent_id query from a {@link ParentFieldMapper} * Only used for BWC with multi-types indices *//*from w w w . j a va 2 s . c o m*/ private Query doToQueryBWC(QueryShardContext context) throws IOException { DocumentMapper childDocMapper = context.getMapperService().documentMapper(type); if (childDocMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "[" + NAME + "] no mapping found for type [" + type + "]"); } } ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); if (parentFieldMapper.active() == false) { throw new QueryShardException(context, "[" + NAME + "] _parent field has no parent type configured"); } String fieldName = ParentFieldMapper.joinField(parentFieldMapper.type()); return new BooleanQuery.Builder().add(new DocValuesTermsQuery(fieldName, id), BooleanClause.Occur.MUST) // Need to take child type into account, otherwise a child doc of different type with the same id could match .add(new TermQuery(new Term(TypeFieldMapper.NAME, type)), BooleanClause.Occur.FILTER).build(); }