-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-37545 Atlas Search Page #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
ee47667
61417a0
a281005
1e1cf71
91e0cb8
3f5dafb
9fb0ae1
23a66b3
42ca676
1f19022
b70545d
832bc70
4c4d580
fde6b8c
8d345d8
fd1b40c
da20d88
bfc9606
3373359
f804519
29532a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,118 @@ | ||||||||||||||||||||||
.. _pymongo-atlas-search: | ||||||||||||||||||||||
|
||||||||||||||||||||||
============ | ||||||||||||||||||||||
Atlas Search | ||||||||||||||||||||||
============ | ||||||||||||||||||||||
|
||||||||||||||||||||||
.. contents:: On this page | ||||||||||||||||||||||
:local: | ||||||||||||||||||||||
:backlinks: none | ||||||||||||||||||||||
:depth: 2 | ||||||||||||||||||||||
:class: singlecol | ||||||||||||||||||||||
|
||||||||||||||||||||||
.. facet:: | ||||||||||||||||||||||
:name: genre | ||||||||||||||||||||||
:values: reference | ||||||||||||||||||||||
|
||||||||||||||||||||||
.. meta:: | ||||||||||||||||||||||
:keywords: search, atlas, read | ||||||||||||||||||||||
|
||||||||||||||||||||||
Overview | ||||||||||||||||||||||
-------- | ||||||||||||||||||||||
|
||||||||||||||||||||||
In this guide, you can learn how to query an Atlas Search index and use advanced search functionality for your applications. To query the seach index, use a ``$search`` aggregation pipeline stage with {+driver-short+}. | ||||||||||||||||||||||
|
||||||||||||||||||||||
To learn more about the ``$search`` pipeline stage, see :manual:`$search | ||||||||||||||||||||||
</reference/operator/aggregation/search/>`. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
.. note:: Only Available on Atlas for MongoDB v4.2 and Later | ||||||||||||||||||||||
|
||||||||||||||||||||||
The ``$search`` aggregation-pipeline operator is available only for collections hosted | ||||||||||||||||||||||
on :atlas:`MongoDB Atlas </>` clusters running MongoDB v4.2 or later that are | ||||||||||||||||||||||
covered by an :atlas:`Atlas search index </reference/atlas-search/index-definitions/>`. | ||||||||||||||||||||||
To learn more about the required setup and the functionality of this operator, | ||||||||||||||||||||||
see the :ref:`Atlas Search <fts-top-ref>` documentation. | ||||||||||||||||||||||
|
||||||||||||||||||||||
Sample Data | ||||||||||||||||||||||
~~~~~~~~~~~ | ||||||||||||||||||||||
|
||||||||||||||||||||||
The examples in this guide use the ``sample_mflix.movies`` collection | ||||||||||||||||||||||
from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to create a | ||||||||||||||||||||||
free MongoDB Atlas cluster and load the sample datasets, see | ||||||||||||||||||||||
:ref:`<pymongo-get-started>`. | ||||||||||||||||||||||
|
||||||||||||||||||||||
Create an Atlas Search Index | ||||||||||||||||||||||
---------------------------- | ||||||||||||||||||||||
|
||||||||||||||||||||||
Before you can perform a search on an Atlas collection, you must first create an **Atlas | ||||||||||||||||||||||
Search index** on the collection. An Atlas Search index is a data structure that | ||||||||||||||||||||||
categorizes data in a searchable format. To learn how to create an Atlas Search Index | ||||||||||||||||||||||
see the :ref:`pymongo-atlas-search-index` documentation. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "documentation" here made me think I was getting link to a different set of docs rather than a page in the pymongo docs. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Search Your Data | ||||||||||||||||||||||
---------------- | ||||||||||||||||||||||
|
||||||||||||||||||||||
To use the ``$search`` aggregation pipeline stage, you must select an Atlas Search query operator that specifies the type of query you run. You can also optionally select a collector that groups results by values or ranges. To see a table of all the operators and collectors available in Atlas Search, see :atlas:`Use Operators and Collectors in Atlas Search Queries </atlas-search/operators-and-collectors>`. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: I think "specify" might work better than "select" here since select seems like you are doing it through some kind of select stage or selection process within atlas search
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
The following example uses the ``phrase`` operator, which performs search for documents containing an ordered sequence of terms. To learn more about the ``phrase`` operator, see :atlas:`Phrase </atlas-search/phrase>` in the Atlas guide. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
The example performs a basic search of the ``title`` field for the query string ``new york``. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
The query also includes a: | ||||||||||||||||||||||
|
||||||||||||||||||||||
- :pipeline:`$limit` stage to limit the output to 10 results. | ||||||||||||||||||||||
- :pipeline:`$project` stage to exclude all fields except | ||||||||||||||||||||||
``title`` and add a field named ``score``. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style guide: Introduce lists with a full sentence
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
.. io-code-block:: | ||||||||||||||||||||||
:copyable: true | ||||||||||||||||||||||
|
||||||||||||||||||||||
.. input:: | ||||||||||||||||||||||
:language: python | ||||||||||||||||||||||
|
||||||||||||||||||||||
client = pymongo.MongoClient("<connection-string>") | ||||||||||||||||||||||
result = client["sample_mflix"]["movies"].aggregate([ | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
"$search": { | ||||||||||||||||||||||
"index": "pymongoindex", | ||||||||||||||||||||||
"phrase": { | ||||||||||||||||||||||
"path": "title", | ||||||||||||||||||||||
"query": "new york" | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
{ "$limit": 10 }, | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
"$project": { | ||||||||||||||||||||||
"_id": 0, | ||||||||||||||||||||||
"title": 1, | ||||||||||||||||||||||
"score": { "$meta": "searchScore" } | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
]) | ||||||||||||||||||||||
|
||||||||||||||||||||||
for i in result: | ||||||||||||||||||||||
print(i) | ||||||||||||||||||||||
|
||||||||||||||||||||||
.. output:: | ||||||||||||||||||||||
:language: none | ||||||||||||||||||||||
:visible: false | ||||||||||||||||||||||
|
||||||||||||||||||||||
{ title: 'New York, New York', score: 6.786321640014648 } | ||||||||||||||||||||||
{ title: 'New York', score: 6.258549213409424 } | ||||||||||||||||||||||
{ title: 'New York Stories', score: 5.3813982009887695 } | ||||||||||||||||||||||
{ title: 'New York Minute', score: 5.3813982009887695 } | ||||||||||||||||||||||
{ title: 'Synecdoche, New York', score: 5.3813982009887695 } | ||||||||||||||||||||||
{ title: 'New York Doll', score: 5.3813982009887695 } | ||||||||||||||||||||||
{ title: 'Little New York', score: 5.3813982009887695 } | ||||||||||||||||||||||
{ title: 'Escape from New York', score: 4.719893455505371 } | ||||||||||||||||||||||
{ title: 'Naked in New York', score: 4.719893455505371 } | ||||||||||||||||||||||
{ title: 'Autumn in New York', score: 4.719893455505371 } | ||||||||||||||||||||||
|
||||||||||||||||||||||
Next Steps | ||||||||||||||||||||||
---------- | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We typically use "Next Steps" in tutorial-style pages. Since this is a reference page, I would suggest converting this to an "Additional Information" section (and converting the following paragraph into a bulleted list of resources) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not convert into a bulleted list, but I did change it to an addl. info section. Looking at the other pymongo pages, some of the addl. info sections are in prose and I think in this case, prose works better because the information isn't linking out to functions in the api docs or less prose-based information |
||||||||||||||||||||||
|
||||||||||||||||||||||
Now that you've run a query using Atlas Search, review the Atlas Search :atlas:`documentation | ||||||||||||||||||||||
</atlas-search>` to learn more about the different :atlas:`operators | ||||||||||||||||||||||
</atlas-search/operators-and-collectors>` and other queries you can run. More query examples using | ||||||||||||||||||||||
MongoDB Query Language (MQL) are available througout the Atlas :atlas:`documentation | ||||||||||||||||||||||
</atlas-search>`. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't refer to it as MQL in external docs anymore. It's now called the "MongoDB Query API", but I think we can get away without mentioning either one here
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: Restructure this to specify the driver earlier