private Query createTypeFilter(String[] types) { if (types != null && types.length >= 1) { MappedFieldType ft = mapperService().fullName(TypeFieldMapper.NAME); if (ft != null) { // ft might be null if no documents have been indexed yet return ft.termsQuery(Arrays.asList(types), queryShardContext); } } return null; }
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems, QueryShardContext context) { MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { // no mappings, nothing to exclude return; } // artificial docs get assigned a random id and should be disregarded List<BytesRef> uids = new ArrayList<>(); for (Item item : likeItems) { if (item.doc() != null) { continue; } uids.add(createUidAsBytes(item.type(), item.id())); } if (!uids.isEmpty()) { Query query = uidField.termsQuery(uids, context); boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { return new MatchNoDocsQuery("No mappings"); } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection<String> typesForQuery; if (types.length == 0) { typesForQuery = context.queryTypes(); } else if (types.length == 1 && MetaData.ALL.equals(types[0])) { typesForQuery = context.getMapperService().types(); } else { typesForQuery = new HashSet<>(); Collections.addAll(typesForQuery, types); } query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { if (termsLookup != null || supplier != null) { throw new UnsupportedOperationException("query must be rewritten first"); } if (values == null || values.isEmpty()) { return Queries.newMatchNoDocsQuery("No terms supplied for \"" + getName() + "\" query."); } int maxTermsCount = context.getIndexSettings().getMaxTermsCount(); if (values.size() > maxTermsCount){ DEPRECATION_LOGGER.deprecated( "Deprecated: the number of terms [" + values.size() + "] used in the Terms Query request has exceeded " + "the allowed maximum of [" + maxTermsCount + "]. " + "This maximum can be set by changing the [" + IndexSettings.MAX_TERMS_COUNT_SETTING.getKey() + "] index level setting."); } MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { return fieldType.termsQuery(values, context); } else { BytesRef[] filterValues = new BytesRef[values.size()]; for (int i = 0; i < filterValues.length; i++) { filterValues[i] = BytesRefs.toBytesRef(values.get(i)); } return new TermInSetQuery(fieldName, filterValues); } }
@Override public Query termsQuery(List values, QueryShardContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.getFullyQualifiedIndex().getName() + " vs. " + values); }
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems, QueryShardContext context) { MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { // no mappings, nothing to exclude return; } // artificial docs get assigned a random id and should be disregarded List<BytesRef> uids = new ArrayList<>(); for (Item item : likeItems) { if (item.doc() != null) { continue; } uids.add(createUidAsBytes(item.type(), item.id())); } if (!uids.isEmpty()) { Query query = uidField.termsQuery(uids, context); boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } }
private Query createTypeFilter(String[] types) { if (types != null && types.length >= 1) { MappedFieldType ft = mapperService().fullName(TypeFieldMapper.NAME); if (ft != null) { // ft might be null if no documents have been indexed yet return ft.termsQuery(Arrays.asList(types), queryShardContext); } } return null; }
private Query createTypeFilter(String[] types) { if (types != null && types.length >= 1) { MappedFieldType ft = mapperService().fullName(TypeFieldMapper.NAME); if (ft != null) { // ft might be null if no documents have been indexed yet return ft.termsQuery(Arrays.asList(types), queryShardContext); } } return null; }
private Query createTypeFilter(String[] types) { if (types != null && types.length >= 1) { MappedFieldType ft = mapperService().fullName(TypeFieldMapper.NAME); if (ft != null) { // ft might be null if no documents have been indexed yet return ft.termsQuery(Arrays.asList(types), queryShardContext); } } return null; }
/** * Create a new geohash filter for a given set of geohashes. In general this method * returns a boolean filter combining the geohashes OR-wise. * * @param context Context of the filter * @param fieldType field mapper for geopoints * @param geohash mandatory geohash * @param geohashes optional array of additional geohashes * @return a new GeoBoundinboxfilter */ public static Query create(QueryShardContext context, BaseGeoPointFieldMapper.LegacyGeoPointFieldType fieldType, String geohash, @Nullable List<CharSequence> geohashes) { MappedFieldType geoHashMapper = fieldType.geoHashFieldType(); if (geoHashMapper == null) { throw new IllegalArgumentException("geohash filter needs geohash_prefix to be enabled"); } if (geohashes == null || geohashes.size() == 0) { return geoHashMapper.termQuery(geohash, context); } else { geohashes.add(geohash); return geoHashMapper.termsQuery(geohashes, context); } }
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems, QueryShardContext context) { MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { // no mappings, nothing to exclude return; } // artificial docs get assigned a random id and should be disregarded List<BytesRef> uids = new ArrayList<>(); for (Item item : likeItems) { if (item.doc() != null) { continue; } uids.add(createUidAsBytes(item.type(), item.id())); } if (!uids.isEmpty()) { Query query = uidField.termsQuery(uids, context); boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } }
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems, QueryShardContext context) { MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { // no mappings, nothing to exclude return; } // artificial docs get assigned a random id and should be disregarded List<BytesRef> uids = new ArrayList<>(); for (Item item : likeItems) { if (item.doc() != null) { continue; } uids.add(createUidAsBytes(item.type(), item.id())); } if (!uids.isEmpty()) { Query query = uidField.termsQuery(uids, context); boolQuery.add(query, BooleanClause.Occur.MUST_NOT); } }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { return new MatchNoDocsQuery("No mappings"); } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection<String> typesForQuery; if (types.length == 0) { typesForQuery = context.queryTypes(); } else if (types.length == 1 && MetaData.ALL.equals(types[0])) { typesForQuery = context.getMapperService().types(); } else { typesForQuery = new HashSet<>(); Collections.addAll(typesForQuery, types); } query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { return new MatchNoDocsQuery("No mappings"); } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection<String> typesForQuery; if (types.length == 0) { typesForQuery = context.queryTypes(); } else if (types.length == 1 && MetaData.ALL.equals(types[0])) { typesForQuery = context.getMapperService().types(); } else { typesForQuery = new HashSet<>(); Collections.addAll(typesForQuery, types); } query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { return new MatchNoDocsQuery("No mappings"); } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection<String> typesForQuery; if (types.length == 0) { typesForQuery = context.queryTypes(); } else if (types.length == 1 && MetaData.ALL.equals(types[0])) { typesForQuery = context.getMapperService().types(); } else { typesForQuery = new HashSet<>(); Collections.addAll(typesForQuery, types); } query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; }
@Override public Query termsQuery(List values, @Nullable QueryParseContext context) { if (indexOptions() != IndexOptions.NONE || context == null) { return super.termsQuery(values, context); } return new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values)); }
@Override public Query termsQuery(List values, QueryParseContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.index().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery(); }
@Override public Query termsQuery(List values, QueryShardContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.index().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + values); }
@Override public Query termsQuery(List values, QueryShardContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.getFullyQualifiedIndex().getName() + " vs. " + values); }
@Override public Query termsQuery(List values, QueryShardContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.getFullyQualifiedIndex().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.getFullyQualifiedIndex().getName() + " vs. " + values); }