AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

ファセット検索の string フィールドのインデックス作成方法

You can use the MongoDB Search stringFacet type to index string fields for faceting, which allows you to run a facet operator query on that field. MongoDB Search doesn't apply the analyzer when indexing string fields for faceting.

MongoDB Search は、stringFacet 型としてインデックス付けされたフィールドに対するファセット演算子クエリのみをサポートします。同じフィールドで通常の検索も実行するには、フィールドをタイプ string としてインデックス必要があります。

埋め込まれたドキュメント内の文字列フィールドをファセットには、親フィールドをドキュメント型としてインデックス必要があります。埋め込まれたドキュメント内の stringフィールドをファセットと、 MongoDB Search は一致する親ドキュメントの数のみのファセット数を返します。

MongoDB Search stringは、ファセットの 値を動的にインデックスません。ファセットの string 値をインデックスには、静的マッピングを使用する必要があります。Atlas UIのビジュアル エディターまたはJSONエディターを使用して、string フィールドをnumber タイプとしてインデックスできます。

stringFacetタイプのインデックスを定義するには、Atlas UI で希望する構成方法を選択し、データベースとコレクションを選択します。

MongoDB Search stringFacet タイプには次のパラメーターがあります。

UI フィールド名
JSON Option
タイプ
必要性
説明
Data Type

type

string

必須

Human-readable label that identifies this field type. Value must be stringFacet. MongoDB Search truncates BSON string values indexed as the stringFacet type to around 8000 UTF-16 code units.

The following index definition example uses the sample_mflix.movies collection. If you have the sample data already loaded on your cluster, you can use the Visual Editor or JSON Editor in the Atlas UI to configure the index. After you select your preferred configuration method, select the database and collection, and refine your index to add field mappings.

The following index definition for the sample_mflix.movies collection in the sample dataset indexes the genres field as stringFacet for faceting.

The following index definition for the sample_mflix.movies collection in the sample dataset indexes the genres field as stringFacet and string types to return the following types of results for your queries:

facet コレクターの詳細とクエリの例については、「例」を参照してください。

ファセット定義を使用してインデックスを作成し、facet コレクターを使用してそのインデックスをクエリする方法については、「 MongoDB Search でファセットの使用方法 」チュートリアルをご覧ください。

stringFacetを使用してページネーションされた結果でファセット検索を実行するインデックスとクエリの例については、「ページネーションされた結果でファセットを使用する」を参照してください。