Package com.mongodb.client.model.search
Interface SearchOperator
- All Superinterfaces:
Bson
- All Known Subinterfaces:
AutocompleteSearchOperator
,CompoundSearchOperator
,DateNearSearchOperator
,DateRangeSearchOperator
,EqualsSearchOperator
,ExistsSearchOperator
,FilterCompoundSearchOperator
,GeoNearSearchOperator
,InSearchOperator
,MoreLikeThisSearchOperator
,MustCompoundSearchOperator
,MustNotCompoundSearchOperator
,NumberNearSearchOperator
,NumberRangeSearchOperator
,PhraseSearchOperator
,QueryStringSearchOperator
,RegexSearchOperator
,ShouldCompoundSearchOperator
,TextSearchOperator
,WildcardSearchOperator
The core part of the
$search
pipeline stage of an aggregation pipeline.- Since:
- 4.7
- MongoDB Atlas documentation
- Search operators
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY
-
Method Summary
Modifier and TypeMethodDescriptionstatic AutocompleteSearchOperator
autocomplete
(FieldSearchPath path, Iterable<String> queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.static AutocompleteSearchOperator
autocomplete
(FieldSearchPath path, String query, String... queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.static CompoundSearchOperatorBase
compound()
Returns a base for aSearchOperator
that may combine multipleSearchOperator
s.static DateRangeSearchOperatorBase
dateRange
(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.static DateRangeSearchOperatorBase
dateRange
(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.static EqualsSearchOperator
equals
(FieldSearchPath path, boolean value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equals
(FieldSearchPath path, Number value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equals
(FieldSearchPath path, String value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equals
(FieldSearchPath path, Instant value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equals
(FieldSearchPath path, UUID value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equals
(FieldSearchPath path, ObjectId value) Returns aSearchOperator
that searches for documents where a field matches the specified value.static EqualsSearchOperator
equalsNull
(FieldSearchPath path) Returns aSearchOperator
that searches for documents where a field matches null.static ExistsSearchOperator
exists
(FieldSearchPath path) Returns aSearchOperator
that tests if thepath
exists in a document.static InSearchOperator
in
(FieldSearchPath path, boolean value, boolean... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic <T> InSearchOperator
in
(FieldSearchPath path, Iterable<? extends T> values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperator
in
(FieldSearchPath path, Number value, Number... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperator
in
(FieldSearchPath path, String value, String... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperator
in
(FieldSearchPath path, Instant value, Instant... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperator
in
(FieldSearchPath path, UUID value, UUID... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperator
in
(FieldSearchPath path, ObjectId value, ObjectId... values) Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified valuesstatic MoreLikeThisSearchOperator
moreLikeThis
(Iterable<BsonDocument> likes) Returns aSearchOperator
that returns documents similar to input documents.static MoreLikeThisSearchOperator
moreLikeThis
(BsonDocument like) Returns aSearchOperator
that returns documents similar to input document.static GeoNearSearchOperator
near
(Point origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static GeoNearSearchOperator
near
(Point origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static NumberNearSearchOperator
near
(Number origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static NumberNearSearchOperator
near
(Number origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static DateNearSearchOperator
near
(Instant origin, Duration pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static DateNearSearchOperator
near
(Instant origin, Duration pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.numberRange
(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.numberRange
(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.static SearchOperator
Creates aSearchOperator
from aBson
in situations when there is no builder method that better satisfies your needs.static PhraseSearchOperator
phrase
(SearchPath path, String query) Returns aSearchOperator
that performs a search for documents containing an ordered sequence of terms.static PhraseSearchOperator
phrase
(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperator
that performs a search for documents containing an ordered sequence of terms.static QueryStringSearchOperator
queryString
(FieldSearchPath defaultPath, String query) Returns aSearchOperator
that supports querying a combination of indexed fields and values.static RegexSearchOperator
regex
(SearchPath path, String query) Returns aSearchOperator
that performs a search using a regular expression.static RegexSearchOperator
regex
(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperator
that performs a search using a regular expression.score
(SearchScore modifier) Creates a newSearchOperator
with the scoring modifier specified.static TextSearchOperator
text
(SearchPath path, String query) Returns aSearchOperator
that performs a full-text search.static TextSearchOperator
text
(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperator
that performs a full-text search.static WildcardSearchOperator
wildcard
(SearchPath path, String query) Returns aSearchOperator
that performs a search using a special characters in the search string that can match any character.static WildcardSearchOperator
wildcard
(Iterable<String> queries, Iterable<? extends SearchPath> paths) Returns aSearchOperator
that performs a search using a special characters in the search string that can match any character.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
score
Creates a newSearchOperator
with the scoring modifier specified.- Parameters:
modifier
- The scoring modifier.- Returns:
- A new
SearchOperator
.
-
compound
Returns a base for aSearchOperator
that may combine multipleSearchOperator
s. CombiningSearchOperator
s affects calculation of the relevance score.- Returns:
- A base for a
CompoundSearchOperator
. - MongoDB Atlas documentation
- compound operator
-
exists
Returns aSearchOperator
that tests if thepath
exists in a document.- Parameters:
path
- The path to test.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- exists operator
-
text
Returns aSearchOperator
that performs a full-text search.- Parameters:
path
- The field to be searched.query
- The string to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- text operator
-
text
Returns aSearchOperator
that performs a full-text search.- Parameters:
paths
- The non-empty fields to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- text operator
-
autocomplete
static AutocompleteSearchOperator autocomplete(FieldSearchPath path, String query, String... queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.- Parameters:
path
- The field to be searched.query
- The string to search for.queries
- More strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- autocomplete operator
-
autocomplete
Returns aSearchOperator
that may be used to implement search-as-you-type functionality.- Parameters:
path
- The field to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- autocomplete operator
-
numberRange
Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.- Parameters:
path
- The field to be searched.paths
- More fields to be searched.- Returns:
- A base for a
NumberRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
numberRange
Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.- Parameters:
paths
- The non-empty fields to be searched.- Returns:
- A base for a
NumberRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
dateRange
Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.- Parameters:
path
- The field to be searched.paths
- More fields to be searched.- Returns:
- A base for a
DateRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
dateRange
Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.- Parameters:
paths
- The non-empty fields to be searched.- Returns:
- A base for a
DateRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
near
static NumberNearSearchOperator near(Number origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static NumberNearSearchOperator near(Number origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static DateNearSearchOperator near(Instant origin, Duration pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half. Data is extracted viaDuration.toMillis()
.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - See Also:
- MongoDB Atlas documentation
- near operator
-
near
static DateNearSearchOperator near(Instant origin, Duration pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half. Data is extracted viaDuration.toMillis()
.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - See Also:
- MongoDB Atlas documentation
- near operator
-
near
static GeoNearSearchOperator near(Point origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance in meters from theorigin
at which the relevance score drops in half.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static GeoNearSearchOperator near(Point origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance in meters from theorigin
at which the relevance score drops in half.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The boolean value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The objectId value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The number value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The instant date value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The uuid value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path
- The indexed field to be searched.value
- The string value to search for.values
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperator
that searches for documents where the value or array of values at a given path contains any of the specified values- Type Parameters:
T
- the type of elements invalues
.- Parameters:
path
- The indexed field to be searched.values
- The non-empty values to search for. Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- in operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The boolean value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The object id value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The number value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The instant date value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The string value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperator
that searches for documents where a field matches the specified value.- Parameters:
path
- The indexed field to be searched.value
- The uuid value to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
equalsNull
Returns aSearchOperator
that searches for documents where a field matches null.- Parameters:
path
- The indexed field to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- equals operator
-
moreLikeThis
Returns aSearchOperator
that returns documents similar to input document.- Parameters:
like
- The BSON document that is used to extract representative terms to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- moreLikeThis operator
-
moreLikeThis
Returns aSearchOperator
that returns documents similar to input documents.- Parameters:
likes
- The BSON documents that are used to extract representative terms to query for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- moreLikeThis operator
-
queryString
Returns aSearchOperator
that supports querying a combination of indexed fields and values.- Parameters:
defaultPath
- The field to be searched by default.query
- One or more indexed fields and values to search.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- queryString operator
-
phrase
Returns aSearchOperator
that performs a search for documents containing an ordered sequence of terms.- Parameters:
path
- The field to be searched.query
- The string to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- phrase operator
-
phrase
Returns aSearchOperator
that performs a search for documents containing an ordered sequence of terms.- Parameters:
paths
- The non-empty fields to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- phrase operator
-
wildcard
Returns aSearchOperator
that performs a search using a special characters in the search string that can match any character.- Parameters:
path
- The indexed field to be searched.query
- The string to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- wildcard operator
-
wildcard
static WildcardSearchOperator wildcard(Iterable<String> queries, Iterable<? extends SearchPath> paths) Returns aSearchOperator
that performs a search using a special characters in the search string that can match any character.- Parameters:
queries
- The non-empty strings to search for.paths
- The non-empty index fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- wildcard operator
-
regex
Returns aSearchOperator
that performs a search using a regular expression.- Parameters:
path
- The field to be searched.query
- The string to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- regex operator
-
regex
Returns aSearchOperator
that performs a search using a regular expression.- Parameters:
paths
- The non-empty fields to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- regex operator
-
of
Creates aSearchOperator
from aBson
in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.Example
The following code creates two functionally equivalentSearchOperator
s, though they may not be equal.SearchOperator operator1 = SearchOperator.exists( SearchPath.fieldPath("fieldName")); SearchOperator operator2 = SearchOperator.of(new Document("exists", new Document("path", SearchPath.fieldPath("fieldName").toValue())));
- Parameters:
operator
- ABson
representing the requiredSearchOperator
.- Returns:
- The requested
SearchOperator
.
-