---
title: "ウォークスルー:Ingestion APIを使った2つのロケーションでのインデックス文書の作成と更新"
slug: "walkthrough--creating-and-updating-index-documents-in-two-locales-using-the-ingestion-api"
abstract: "APIプッシュソースの作成方法と、Ingestion APIを使って複数のロケーションでインデックスドキュメントを作成・更新する方法を説明します。"
---
# ウォークスルー:Ingestion APIを使った2つのロケーションでのインデックス文書の作成と更新

管理者が[Sitecore SearchでAPIプッシュソースを設定し](https://doc.sitecore.com/search/en/users/search-user-guide/en/configure-api-push.html) た後、インジェスションAPIを使ってそのインデックスにドキュメントを追加し、後でドキュメントの更新や削除が可能です。

> !注このウォークスルーでは、属性値を渡してインデックス文書を作成する方法を説明します。ドキュメントエクストラクターを渡すことでインデックス文書を作成することもできます。

このウォークスルーでは、以下のシナリオで[Ingestion API](https://doc.sitecore.com/search/ja/developers/search-developer-guide/using-the-ingestion-api-to-add-content-to-an-index.html "Using the Ingestion API to add content to an index")の使い方を説明します。

-   文書は英語(en\_us)とフランス語(fr\_fr)のロケーションで作成したいものです。フランス語の文書は英語の文書の翻訳です。
    
    > !注インデックス文書を2つのローカルで作成できるのは、管理者がAPIプッシュソースを2つのローカルに設定しているからです。
    
-   各ドキュメントには*ID*、*タイトル*、*説明*、*image\_url*、*content\_type*属性が入っている必要があります。
    

このウォークスルーでは、以下の方法を説明します:

-   Ingestion APIを使って、2つのローカルでインデックスドキュメントを作成できます。
-   Ingestion APIを使って両方のローカルでインデックス文書を編集してください。

> !注**始める前に**管理者が以下のことを行っていることを確認してください:
> 
> -   Searchで、作成予定のインデックス文書に必要なすべての属性 [を追加します](https://doc.sitecore.com/search/en/users/search-user-guide/en/add-an-attribute.html) 。
>     
> -   **「ENABLE INCREMENTAL UPDATES」**[をオンにしてソースを作成・公開します。このソースのIDはIngestion APIコールで使用します。](https://doc.sitecore.com/search/en/users/search-user-guide/en/configure-an-advanced-web-crawler.html)
>     
> 
> この前提条件は、ソースがAPIプッシュソースの場合は適用されません。
> 
> -   ingestionスコープ付きのAPIキーを用意しましょう。このAPIキーは、Searchの**Developer Resources** > **API Access**セクションで確認できます。
> 
> この前提条件は、実装がサブドメインを使用している場合は適用されません。

## Ingestion APIを使って2つのロケールでインデックスドキュメントを作成してください

Ingestion APIで文書を作成するには、[Create DocumentエンドポイントのPOSTメソッド](https://doc.sitecore.com/search/ja/developers/search-developer-guide/using-the-ingestion-api-to-add-content-to-an-index/create-an-index-document/creating-a-document-by-passing-attribute-values.html "Creating a document by passing attribute values") を使用し、必要なパラメータをすべて渡してください。英語(米国)の書類とフランス(フランス)の書類の2回の電話をかけ、両方の書類で同じ書類IDを通すようにしてください。

> !注同じ内容でも異なる場所の文書には必ず同じIDを割り当ててください。これにより、ピン、ブースト、埋葬などのルールがすべての場所に適用されることが保証されます。

Ingestion APIを使って文書を作成するには:

1.  英語(米国)文書を追加するには、[Create DocumentエンドポイントにPOST呼び出し](https://doc.sitecore.com/search/ja/developers/search-developer-guide/using-the-ingestion-api-to-add-content-to-an-index/create-an-index-document/creating-a-document-by-passing-attribute-values.html "Creating a document by passing attribute values") を行い、ロケールをen\_usと指定してください。リクエストURLにプッシュソースのIDとドメインIDを追加してください。リクエスト本文にインデックス文書のIDと、インデックス文書に付けたい属性を追加します。
    
    以下はCURL POST呼び出しのサンプルです:
    
    curl --location 'https://discover.sitecorecloud.io/ingestion/v1/domains/110525450/sources/879132/entities/content/documents?locale=en\_us' \\
    --header 'Content-Type: application/json' \\
    --header 'Authorization: 01-dsd5-2703c7fb73cfcfd0778dhd439bd9a12444'\\
    --data '{
     "document": {
     "id": "push\_source\_test\_123",
     "fields": {
     "title": "English title",
     "description": "English description",
     "type": "blog",
     "image\_url": "www.myimage.com",
     }
     }
    }'
    
2.  フランス語(FR)文書を追加するには、[Create DocumentエンドポイントにPOST呼び出し](https://doc.sitecore.com/search/ja/developers/search-developer-guide/using-the-ingestion-api-to-add-content-to-an-index/create-an-index-document/creating-a-document-by-passing-attribute-values.html "Creating a document by passing attribute values") を行い、ロケートをfr\_frとして指定してください。パスにプッシュソースのソースID、ドメインID、ロケールを追加します。リクエスト本文にインデックス文書のIDと、インデックス文書に付けたい属性を追加します。
    
    以下はCURL POST呼び出しのサンプルです:
    
    curl --location 'https://discover.sitecorecloud.io/ingestion/v1/domains/110525450/sources/879132/entities/content/documents?locale=fr\_fr' \\
    --header 'Content-Type: application/json' \\
    --header 'Authorization: 01-dsd5-2703c7fb73cfcfd0778dhd439bd9a12444'\\
    --data '{
     "document": {
     "id": "push\_source\_test\_123",
     "fields": {
     "title": "French title",
     "description": "French description",
     "type": "blog",
     "image\_url": "www.myimage.com"
     }
     }
    }'
    

## Ingestion APIを使って両方のローカルでインデックス文書を編集してください

英語(米国)とフランス語(フランス語)のインデックス文書を編集して、*[image\_urlをwww.myimage.com](http://www.myimage.com)*から*[www.newimage.com](http://www.newimage.com)*に変更したいです。これを行うには、[部分更新ドキュメントエンドポイントでPATCHメソッド](https://doc.sitecore.com/search/ja/developers/search-developer-guide/using-the-ingestion-api-to-add-content-to-an-index/partially-updating-a-document.html "Partially updating a document")を使い、両方のロケールをクエリパラメータとして渡します。これは一回の通話で可能です。

以下はCURL PATCH呼び出しのサンプルです:

curl --location 'https://discover.sitecorecloud.io/ingestion/v1/domains/110525450/sources/879132/entities/content/documents/push\_source\_test\_123?locale=en\_us&locale=fr\_fr' \\
--header 'Content-Type: application/json' \\
--header 'Authorization: 01-dsd5-2703c7fb73cfcfd0778dhd439bd9a12444'\\
--data '{
 "document": {
 "id": "push\_source\_test\_123",
 "fields": {
 "image\_url": "www.newimage.com"
 }
 }
}'