---
title: "インジェスションAPI文書エクストラクタ参照"
slug: "ingestion-api-document-extractor-reference"
abstract: "Sitecore SearchインジェスションAPIのフィールドとエクストラクタパラメータをフォーマットし、属性抽出ロジックを渡す方法について。"
---
# インジェスションAPI文書エクストラクタ参照

[インジェスション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")を使って属性抽出ロジックを渡してインデックス文書を作成する際は、fieldとパラメータのextractorを正確にフォーマットすることが非常に重要です。これらのパラメータは型stringですが、Sitecore Searchは正確な抽出ルールを作成できるように特定のフォーマットであることを期待しています。

このトピックでは、Swaggerのリファレンスを補完する形でこれらの文字列を正しくフォーマットする方法を説明します。

> !注 [ドキュメントエクストラクタ](https://doc.sitecore.com/search/en/users/search-user-guide/en/configuring-document-extractors.html) とは何か、[XPath](https://doc.sitecore.com/search/en/users/search-user-guide/en/create-an-xpath-document-extractor.html)や[JavaScript](https://doc.sitecore.com/search/en/users/search-user-guide/en/create-a-javascript-document-extractor.html)のドキュメントエクストラクタの作成方法をよく理解することをお勧めします。
> 
> インジェスションAPIを使うため、これらのトピックに含まれる手順に従う必要はありませんが、説明されている概念や論理を理解することは役立ちます。

## 場パラメータ

[既存のドキュメント抽出器](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-an-index-document-by-using-an-existing-document-extractor.html "Creating an index document by using an existing document extractor")のルールを上書きし、属性に固定値を割り当てるためにfieldsを使います。属性名と属性値を渡す必要があります。

> !注[新しいエクストラクタをパスする](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-an-index-document-by-passing-a-new-document-extractor.html "Creating an index document by passing a new document extractor")際にfieldsパスする必要はありません。なぜなら、extractorパラメータ自体に属性の固定値を指定できるからです。例は*「XPath文書エクストラクタのパッシング*」や*「JavaScriptドキュメントエクストラクタのパッシング*」で示されています。

この形式を使って、fieldsパラメータを通じて属性の固定値を定義します:

{
 "items": {
 "<attribute1>": "<value of attribute 1>",
 "<attribute2>": "<value of attribute 2>"
 }
}

例えば、*型* と *名前* 属性の固定値を設定するには、CURL呼び出しで以下の行を渡すことができます。

\--form 'fields={
 "items": {
 "type": "pdf",
 "name": "Compliance Services Playbook"
 }
}'

## エクストラクタパラメータ

extractorパラメータを使って使いたい抽出ロジックを渡します。

### 属性ごとに複数のルールを持つXPathドキュメントエクストラクタを渡す

XPathドキュメントエクストラクタを定義するには、エクストラクタの種類(xpath)と属性の値を抽出するために使うルールを指定する必要があります。

この形式を使ってXPath抽出ロジックをextractorパラメータで渡します:

\--form 'extractor=
{
 "type": "xpath",
 "rules": {
 "<attribute1>": {
 "selectors": 
 {
 "expression": "<First XPath expression to get the value of attribute1>"
 },
 {
 "expression": "<Second XPath expression to get the value of attribute1>"
 },
 
 },
 "<attribute2>": {
 "selectors": 
 {
 "expression": "<XPath expression to get the value of <attribute1>>"
 }
 
 },
 "attribite3": {
 "value": "<Fixed value for attribute3>"
 }
 }
}

> !注複数のセレクターを通過した場合、Searchは通過した順番にそれらを適用します。最初のセレクタで属性値が得られなければ、Searchは2つ目を試し、これを繰り返して属性値が得られるか、試すセレクタがなくなるまで続けます

例えば、*タイトル*、*image\_url*、*タイプ* 属性の抽出値をXPathで定義するには、cURL呼び出しで以下のものを渡すことができます。

\--form 'extractor={
 "type": "xpath",
 "rules": {
 "title": {
 "selectors": 
 {"expression": "//meta@property=\\'dozen:page:id\\'/@content"},
 {"expression": "//title/text()"}
 
 },
 "image\_url": {
 "selectors": 
 {"expression": "//meta@property=\\'og:image\\'/@content"}
 
 },
 "type": {
 "value": "The Core"
 }
 }

その例では、属性値を取得するために以下のロジックを用います:

-   title (最初のセレクター): property='dozen:page:id'で識別されるカスタムメタタグから値を取得。
-   title (セカンドセレクター)HTML <title> タグから値を取れ。
-   image\_url: og:image metaタグから値を取得します。
-   type:すべての索引文書に固定値の *The Core* を割り当てます。

### JavaScriptドキュメントエクストラクタのパッシング

JavaScriptドキュメントエクストラクタを定義するには、エクストラクタの種類(js)と、オブジェクトの配列を返す[cheerio構文](https://cheerio.js.org/)JavaScript関数を指定する必要があります。

extractorパラメータを使って抽出ロジックを渡すJavaScriptこの形式を用いてください:

\--form 'extractor={
 "type": "js",
 "source": "function extract(request, response) {
 $ = response.body;
 <attribute1> = $('\\'<JavaScript code to get the value of attribite1>;
 <attribute2> = $('\\'<JavaScript code to get the value of attribite2>;

 // Return structured data
 return {
 '\\''<attribute1>\\'': <attribute1>,
 '\\''<attribute2>\\'': <attribute2>,
 '\\''<attribute3>\\'': "fixed value" // optional - set a fixed value for an attribute
 };
 }"
 }'

例えば、JavaScriptを使ってPDFファイルから *タイトル*、*説明*、*タイプ* 属性の値を抽出するには、cURL呼び出しで以下の値を渡すことができます:

\--form 'extractor="{\\
 \\"type\\": \\"js\\", \\
 \\"source\\": \\"function extract(request, response) { \\
 $ = response.body; \\
 title = $('\\'title\\'').text(); \\
 description = $('\\'body\\'').text()\\
 .replace(/(\\\\\\\\r\\\\\\\\n|\\\\\\\\n|\\\\\\\\r)/gm, '\\'' '\\'')\\
 .replace(/ +/g, '\\'' '\\'')\\
 .replace(/\\\\\\\\.+/g, '\\''.'\\'')\\
 .substring(0, 7000); \\
 return { \\
 '\\''title\\'': title, \\
 '\\''description\\'': description, \\
 '\\''type\\'': \\"PDF\\" \\
 }; \\
 }\\"\\
}"'

その例では、属性値を取得するために以下のロジックを用います:

-   titleHTML <title> タグをターゲットにする CSS セレクターを使いましょう。
-   description:スペースと行の改行を正規化し、過剰な句読点を削除し、テキストを最大7,000文字に切り詰めます。
-   type:すべての索引文書に固定値の *PDF* を割り当てます。