Class RerankQuery

java.lang.Object
com.mongodb.client.model.RerankQuery
All Implemented Interfaces:
org.bson.conversions.Bson

@Beta(SERVER) public final class RerankQuery extends Object implements org.bson.conversions.Bson
Represents a query for the $rerank aggregation pipeline stage.

The $rerank stage is available only in MongoDB Atlas.

Use rerankQuery(String) for a simple text query, or rerankQuery(Bson) to specify the full query document directly (e.g., for future modalities like imageURL or videoURL).

Since:
5.8
Since server release
8.3
  • Field Summary

    Fields inherited from interface org.bson.conversions.Bson

    DEFAULT_CODEC_REGISTRY
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a rerank query with the specified text.
    rerankQuery(org.bson.conversions.Bson query)
    Creates a rerank query from a full query document.
    <TDocument>
    org.bson.BsonDocument
    toBsonDocument(Class<TDocument> documentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.bson.conversions.Bson

    toBsonDocument
  • Method Details

    • rerankQuery

      public static RerankQuery rerankQuery(String text)
      Creates a rerank query with the specified text.

      This is a convenience for rerankQuery(new Document("text", text)).

      Parameters:
      text - the query text to rerank against.
      Returns:
      a new RerankQuery
    • rerankQuery

      public static RerankQuery rerankQuery(org.bson.conversions.Bson query)
      Creates a rerank query from a full query document.

      Use this overload for future query modalities (e.g., imageURL, videoURL) or to pass additional fields alongside text.

      Parameters:
      query - the query document.
      Returns:
      a new RerankQuery
    • toBsonDocument

      public <TDocument> org.bson.BsonDocument toBsonDocument(Class<TDocument> documentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
      Specified by:
      toBsonDocument in interface org.bson.conversions.Bson
    • toString

      public String toString()
      Overrides:
      toString in class Object