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 タイプとしてインデックスできます。
Define the Index for the stringFacet Type
stringFacetタイプのインデックスを定義するには、Atlas UI で希望する構成方法を選択し、データベースとコレクションを選択します。
Configure Properties for the stringFacet Type
MongoDB Search stringFacet タイプには次のパラメーターがあります。
UI フィールド名 | JSON Option | タイプ | 必要性 | 説明 |
|---|---|---|---|---|
Data Type |
| string | 必須 | Human-readable label that identifies this field type. Value must be |
Try an Example for the stringFacet Type
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.
stringFacet 型の例
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:
MongoDB Search
facet(MongoDB Search 演算子)を使用したクエリのメタデータ結果。
詳細
facet コレクターの詳細とクエリの例については、「例」を参照してください。
ファセット定義を使用してインデックスを作成し、facet コレクターを使用してそのインデックスをクエリする方法については、「 MongoDB Search でファセットの使用方法 」チュートリアルをご覧ください。
stringFacetを使用してページネーションされた結果でファセット検索を実行するインデックスとクエリの例については、「ページネーションされた結果でファセットを使用する」を参照してください。