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>|<field-to-search>: <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
| 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:
Tip See also: Examples for some sample queries that
use the operators and delimiters to search the sample
| yes | ||||||||
score | object | The score assigned to matching search results. You can modify the score using the following options:
For information on using | 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
default
index and run the example queries on your cluster.
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.
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