Refine search
/** * Create a query for matching a bounding box using doc values. * This query is usually slow as it does not use an index structure and needs * to verify documents one-by-one in order to know whether they match. It is * best used wrapped in an {@link IndexOrDocValuesQuery} alongside a * {@link LatLonPoint#newBoxQuery}. */ public static Query newSlowBoxQuery(String field, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) { // exact double values of lat=90.0D and lon=180.0D must be treated special as they are not represented in the encoding // and should not drag in extra bogus junk! TODO: should encodeCeil just throw ArithmeticException to be less trappy here? if (minLatitude == 90.0) { // range cannot match as 90.0 can never exist return new MatchNoDocsQuery("LatLonDocValuesField.newBoxQuery with minLatitude=90.0"); } if (minLongitude == 180.0) { if (maxLongitude == 180.0) { // range cannot match as 180.0 can never exist return new MatchNoDocsQuery("LatLonDocValuesField.newBoxQuery with minLongitude=maxLongitude=180.0"); } else if (maxLongitude < minLongitude) { // encodeCeil() with dateline wrapping! minLongitude = -180.0; } } return new LatLonDocValuesBoxQuery(field, minLatitude, maxLatitude, minLongitude, maxLongitude); }
@Override public int hashCode() { return classHash(); } }
@Override public boolean equals(Object o) { return sameClassAs(o); }
if (fieldType != null) { Analyzer actualAnalyzer = getAnalyzer(fieldType, type == MultiMatchQueryBuilder.Type.PHRASE); name = fieldType.name(); if (!groups.containsKey(actualAnalyzer)) { groups.put(actualAnalyzer, new ArrayList<>()); groups.get(actualAnalyzer).add(new FieldAndFieldType(fieldType, boost)); } else { queries.add(new MatchNoDocsQuery("unknown field " + name)); String representativeField = group.get(0).fieldType.name(); Query q = parseGroup(type.matchQueryType(), representativeField, 1f, value, minimumShouldMatch); if (q != null) {
@Override protected Query doToQuery(QueryShardContext shardContext) throws IOException { MappedFieldType fieldType = shardContext.fieldMapper(fieldName); if (fieldType == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(shardContext, "failed to find geo_point field [" + fieldName + "]"); } } if (!(fieldType instanceof GeoPointFieldType)) { throw new QueryShardException(shardContext, "field [" + fieldName + "] is not a geo_point field"); } QueryValidationException exception = checkLatLon(); if (exception != null) { throw new QueryShardException(shardContext, "couldn't validate latitude/ longitude values", exception); } if (GeoValidationMethod.isCoerce(validationMethod)) { GeoUtils.normalizePoint(center, true, true); } Query query = LatLonPoint.newDistanceQuery(fieldType.name(), center.lat(), center.lon(), this.distance); if (fieldType.hasDocValues()) { Query dvQuery = LatLonDocValuesField.newSlowDistanceQuery(fieldType.name(), center.lat(), center.lon(), this.distance); query = new IndexOrDocValuesQuery(query, dvQuery); } return query; }
if (fieldType == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "failed to find geo_shape field [" + fieldName + "]"); } else if (fieldType.typeName().equals(BaseGeoShapeFieldMapper.CONTENT_TYPE) == false) { throw new QueryShardException(context, "Field [" + fieldName + "] is not of type [geo_shape] but of type [" + fieldType.typeName() + "]"); BooleanQuery.Builder bool = new BooleanQuery.Builder(); Query exists = ExistsQueryBuilder.newFilter(context, fieldName); Query intersects = prefixTreeStrategy.makeQuery(getArgs(shapeToQuery, ShapeRelation.INTERSECTS)); bool.add(exists, BooleanClause.Occur.MUST); bool.add(intersects, BooleanClause.Occur.MUST_NOT); query = new ConstantScoreQuery(bool.build()); } else {
@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 (context.getIndexSettings().isSingleType() == false) { // BWC for indices with multiple types return doToQueryBWC(context); } ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.getMapperService()); if (joinFieldMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { final String indexName = context.getIndexSettings().getIndex().getName(); throw new QueryShardException(context, "[" + NAME + "] no join field found for index [" + indexName + "]"); } } final ParentIdFieldMapper childMapper = joinFieldMapper.getParentIdFieldMapper(type, false); if (childMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "[" + NAME + "] no relation found for child [" + type + "]"); } } return new BooleanQuery.Builder() .add(childMapper.fieldType().termQuery(id, context), BooleanClause.Occur.MUST) // Need to take child type into account, otherwise a child doc of different type with the same id could match .add(joinFieldMapper.fieldType().termQuery(type, context), BooleanClause.Occur.FILTER) .build(); }
(FieldNamesFieldMapper.FieldNamesFieldType) context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { return new MatchNoDocsQuery("No mappings yet"); if (mapper != null) { DateMathParser forcedDateParser = getForceDateParser(); query = mapper.rangeQuery( from, to, includeLower, includeUpper, relation, timeZone, forcedDateParser, context);
} else if (type.hasDocValues() == false) { throw new IllegalArgumentException("cannot load numeric doc values on " + field); } else { if (targetShard != shardId) { return new MatchNoDocsQuery("this shard is not part of the slice"); if (id != targetSlice) { return new MatchNoDocsQuery("this shard is not part of the slice");
@Override protected Query doToQuery(QueryShardContext context) throws IOException { MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType == null) { return new MatchNoDocsQuery("unknown field [" + fieldName + "]"); } MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod( rewrite, null, LoggingDeprecationHandler.INSTANCE); return fieldType.wildcardQuery(value, method, context); }
@Override public Query rewrite(IndexReader reader) throws IOException { if (getBoost() != 1f) { return super.rewrite(reader); } // Rewrite to an empty BooleanQuery so no Scorer or Weight is required return new BooleanQuery.Builder().build(); }
if (fieldType == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "failed to find geo_point field [" + fieldName + "]"); return LatLonPoint.newPolygonQuery(fieldType.name(), new Polygon(lats, lons));
if (fieldType == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "failed to find geo_point field [" + fieldName + "]"); Query query = LatLonPoint.newBoxQuery(fieldType.name(), luceneBottomRight.getLat(), luceneTopLeft.getLat(), luceneTopLeft.getLon(), luceneBottomRight.getLon()); if (fieldType.hasDocValues()) { Query dvQuery = LatLonDocValuesField.newSlowBoxQuery(fieldType.name(), luceneBottomRight.getLat(), luceneTopLeft.getLat(), luceneTopLeft.getLon(), luceneBottomRight.getLon());
if (fieldType == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "failed to find geo_shape field [" + fieldName + "]"); } else if (fieldType.typeName().equals(GeoShapeFieldMapper.CONTENT_TYPE) == false) { throw new QueryShardException(context, "Field [" + fieldName + "] is not of type [geo_shape] but of type [" + fieldType.typeName() + "]"); BooleanQuery.Builder bool = new BooleanQuery.Builder(); Query exists = ExistsQueryBuilder.newFilter(context, fieldName); Query intersects = strategy.makeQuery(getArgs(shapeToQuery, ShapeRelation.INTERSECTS)); bool.add(exists, BooleanClause.Occur.MUST); bool.add(intersects, BooleanClause.Occur.MUST_NOT); query = new ConstantScoreQuery(bool.build()); } else {
@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 (context.getIndexSettings().isSingleType() == false) { // BWC for indices with multiple types return doToQueryBWC(context); } ParentJoinFieldMapper joinFieldMapper = ParentJoinFieldMapper.getMapper(context.getMapperService()); if (joinFieldMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { final String indexName = context.getIndexSettings().getIndex().getName(); throw new QueryShardException(context, "[" + NAME + "] no join field found for index [" + indexName + "]"); } } final ParentIdFieldMapper childMapper = joinFieldMapper.getParentIdFieldMapper(type, false); if (childMapper == null) { if (ignoreUnmapped) { return new MatchNoDocsQuery(); } else { throw new QueryShardException(context, "[" + NAME + "] no relation found for child [" + type + "]"); } } return new BooleanQuery.Builder() .add(childMapper.fieldType().termQuery(id, context), BooleanClause.Occur.MUST) // Need to take child type into account, otherwise a child doc of different type with the same id could match .add(joinFieldMapper.fieldType().termQuery(type, context), BooleanClause.Occur.FILTER) .build(); }
(FieldNamesFieldMapper.FieldNamesFieldType) context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { return new MatchNoDocsQuery("No mappings yet"); if (mapper != null) { DateMathParser forcedDateParser = getForceDateParser(); query = mapper.rangeQuery( from, to, includeLower, includeUpper, relation, timeZone, forcedDateParser, context);
} else if (type.hasDocValues() == false) { throw new IllegalArgumentException("cannot load numeric doc values on " + field); } else { if (targetShard != shardId) { return new MatchNoDocsQuery("this shard is not part of the slice"); if (id != targetSlice) { return new MatchNoDocsQuery("this shard is not part of the slice");
@Override protected Query doToQuery(QueryShardContext context) throws IOException { MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType == null) { return new MatchNoDocsQuery("unknown field [" + fieldName + "]"); } MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod( rewrite, null, LoggingDeprecationHandler.INSTANCE); return fieldType.wildcardQuery(value, method, context); }