@@ -18,4 +18,83 @@ Atlas Search
1818 :depth: 2
1919 :class: singlecol
2020
21- See :atlas:`Atlas Search </atlas-search/>` in the MongoDB Atlas documentation.
21+ Overview
22+ --------
23+
24+ In this guide, you can learn how to use the **Atlas Search** feature on a collection.
25+ Atlas Search enables you to perform full-text searches on collections hosted on MongoDB
26+ Atlas. Atlas Search indexes specify the behavior of the search and which fields to index.
27+
28+ Run an Atlas Search Query
29+ -------------------------
30+
31+ This section shows how to create an aggregation pipeline to run an
32+ Atlas Search on a collection. You can use ``Aggregates.search`` builder to
33+ create a ``$search`` pipeline stage and specify your search. Then, call
34+ the ``aggregate()`` method and pass your pipeline as a parameter.
35+
36+ .. tip::
37+
38+ To learn more about aggregation operations and builders, see the :ref:`java-aggregation`
39+ guide.
40+
41+ Before running an Atlas Search query, you must create an Atlas Search index
42+ on your collection. To learn how to programmatically create an Atlas Search
43+ index, see the :ref:`java-search-indexes` section in the Indexes guide.
44+
45+ Sample Data
46+ ~~~~~~~~~~~
47+
48+ The example in this section uses the ``movies`` collection in the ``sample_mflix``
49+ database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
50+ create a free MongoDB Atlas cluster and load the sample datasets, see the
51+ :atlas:`Get Started with Atlas </getting-started>` guide.
52+
53+ Atlas Search Example
54+ ~~~~~~~~~~~~~~~~~~~~
55+
56+ This example performs an Atlas Search query by calling the
57+ ``aggregate()`` method and passing the following pipeline stages:
58+
59+ - ``Aggregates.search``: Specifies a search query for documents in which
60+ the ``title`` field contains the word ``"Alabama"``
61+ - ``Aggregates.project``: Projects the ``title`` field of each matching document
62+
63+ .. io-code-block::
64+ :copyable:
65+
66+ .. input:: /includes/AtlasSearch.java
67+ :start-after: begin-atlas-search
68+ :end-before: end-atlas-search
69+ :language: java
70+ :dedent:
71+
72+ .. output::
73+ :language: console
74+ :visible: false
75+
76+ {"_id": {"$oid": "..."}, "title": "Alabama Moon"}
77+ {"_id": {"$oid": "..."}, "title": "Crazy in Alabama"}
78+ {"_id": {"$oid": "..."}, "title": "Sweet Home Alabama"}
79+
80+ .. tip:: Java Driver Atlas Search Examples
81+
82+ To view more examples that use the {+driver-short+} to perform Atlas
83+ Search queries, see :atlas:`Atlas Search Tutorials </atlas-search/tutorials/>`
84+ in the Atlas documentation.
85+
86+ Additional Information
87+ ----------------------
88+
89+ To learn more about Atlas Search, see :atlas:`Atlas Search </atlas-search/>`
90+ in the Atlas documentation.
91+
92+ API Documentation
93+ ~~~~~~~~~~~~~~~~~
94+
95+ To learn more about the methods and pipeline stages mentioned in this guide, see
96+ the following API documentation:
97+
98+ - `MongoCollection.aggregate() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#aggregate(java.util.List)>`__
99+ - `Aggregates.search <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#search(com.mongodb.client.model.search.SearchCollector)>`__
100+ - `Aggregates.project <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#project(org.bson.conversions.Bson)>`__
0 commit comments