queryString
Definition
Syntax
queryString
has the following syntax:
1 { 2 "$search": { 3 "index": <index name>, // optional, defaults to "default" 4 "queryString": { 5 "defaultPath": "<default-field-to-search>", 6 "query": "(<field-to-search>: (<search-values>) AND|OR (<search-values>)) AND|OR (<search-values>)" 7 } 8 } 9 }
Options
queryString
uses the following terms to construct a query:
Field | Type | Description | Necessity | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
defaultPath | string | The indexed field to search by default. Atlas Search only searches the
field in defaultPath if you omit the field to search in the
query . | yes | ||||||||||||||||||||||||
query | string | One or more indexed fields and values to search. Fields and
values are colon-delimited. For example, to search the You can combine the fields and values using the following:
TipSee also:Examples for some sample queries that
use the operators and delimiters to search the sample
You can run wildcard and regular expression queries using the following:
NoteThe | yes | ||||||||||||||||||||||||
score | object | The score assigned to matching search results. You can modify the default score using the following options:
For information on using NoteWhen you query values in arrays, Atlas Search doesn't alter the score of the matching results based on the number of values inside the array that matched the query. The score would be the same as a single match regardless of the number of matches inside an array. | no |
Examples
The following examples use the movies
collection in the
sample_mflix
database. If you have the sample dataset on your cluster , you can create the
Atlas Search index named default
with dynamic mappings and run the example
queries on your cluster .
Boolean Operator Queries
Basic Examples
Advanced Examples
The following example uses the queryString
operator to query for
movie plots that contain the terms captain
, kirk
, and
chess
. This example shows how different grouping of the same search
terms using parentheses can result in different documents to be
included in the search results.
Example
The following queries search for a combination of the terms,
captain
, kirk
, and chess
in the plot
field.
Each query returns a different result depending
on how the search terms are grouped.
The queries also includes a $project
stage to:
Exclude all fields except
title
,plot
, andfullpath
Add a field named
score
Range Queries
Wildcard Queries
The following examples use the queryString
operator to query for
movie titles using fuzzy, wildcard, and regular expressions. The queries
include a $project
stage to exclude all fields except
title
.