カスタムスキーマ定義
ビュースキーマは、Elasticsearch タイプおよびクエリに対しconnector が推測するリレーショナル構造を固定します。カスタムスキーマがどう動作するかの例として、次のマッピングを使用します(テーブル名は'insured' です)。
{
"insured": {
"properties": {
"name": { "type":"string" },
"address": {
"street": { "type":"string" },
"city": { "type":"string" },
"state": { "type":"string" }
},
"insured_ages": { "type": "integer" },
"vehicles": {
"type": "nested",
"properties": {
"year": { "type":"integer" },
"make": { "type":"string" },
"model": { "type":"string" },
"body_style" { "type": "string" }
}
}
}
}
}
また、上の例において、次のサンプルデータを考えてください:
{
"_source": {
"name": "John Smith",
"address": {
"street": "Main Street",
"city": "Chapel Hill",
"state": "NC"
},
"insured_ages": [ 17, 43, 45 ],
"vehicles": [
{
"year": 2015,
"make": "Dodge",
"model": "RAM 1500",
"body_style": "TK"
},
{
"year": 2015,
"make": "Suzuki",
"model": "V-Strom 650 XT",
"body_style": "MC"
},
{
"year": 2012,
"make": "Honda",
"model": "Accord",
"body_style": "4D"
}
]
}
}
カスタムスキーマの定義
GenerateSchemaFiles が設定されている場合の固定されたスキーマは、Location プロパティによって指定されたフォルダに配置されます。例えば、GenerateSchemaFiles を"OnUse" に設定して、SELECT クエリを実行します:
SELECT * FROM insured
生成されたスキーマでカラムの動作を変更できます。次のスキーマは、other:xPathプロパティを使って、特定のカラムへのデータがどこに取得されるべきかを定義します。このモデルを使って、階層構造のアービトラリーレベルをフラット化することができます。
es_index およびes_type 属性は、取得するElasticsearch インデックスおよびタイプを指定します。es_index およびes_type 属性は、同じタイプ内で複数のスキーマを使うフレキシビリティを与えます。es_type が指定されていない場合、ファイル名がパースされるコレクションを決定します。
以下は、カラム動作マークアップの例です。完全なスキーマはカスタムスキーマ例 を参照してください。
<rsb:script xmlns:rsb="http://www.rssbus.com/ns/rsbscript/2">
<rsb:info title="StaticInsured" description="Elasticsearch に insure されたデータセットのCustom Schema。">
<!-- Column definitions -->
<attr name="_id" xs:type="string" other:xPath="_id" other:sourceField="_id" other:analyzed="true" />
<attr name="_score" xs:type="double" other:xPath="_score" other:sourceField="_score" other:analyzed="true" />
<attr name="name" xs:type="string" other:xPath="_source/name" other:sourceField="name" other:analyzed="true" />
<attr name="address.street" xs:type="string" other:xPath="_source/address/street" other:sourceField="address.street" other:analyzed="true" />
<attr name="address.city" xs:type="string" other:xPath="_source/address/city" other:sourceField="address.city" other:analyzed="true" />
<attr name="address.state" xs:type="string" other:xPath="_source/address/state" other:sourceField="address.state" other:analyzed="true" />
<attr name="insured_ages" xs:type="string" other:xPath="_source/insured_ages" other:valueFormat="aggregate" other:sourceField="insured_ages" other:analyzed="false" />
<attr name="insured_ages.0" xs:type="integer" other:xPath="_source/insured_ages[0]" other:sourceField="insured_ages" other:analyzed="false" />
<attr name="vehicles" xs:type="string" other:xPath="_source/vehicles" other:valueFormat="aggregate" other:sourceField="vehicles" other:analyzed="true" />
<attr name="vehicles.0.year" xs:type="integer" other:xPath="_source/vehicles[0]/year" other:sourceField="vehicles.year" other:analyzed="true" />
<attr name="vehicles.0.make" xs:type="string" other:xPath="_source/vehicles[0]/make" other:sourceField="vehicles.make" other:analyzed="true" />
<attr name="vehicles.0.model" xs:type="string" other:xPath="_source/vehicles[0]/model" other:sourceField="vehicles.model" other:analyzed="true" />
<attr name="vehicles.0.body_style" xs:type="string" other:xPath="_source/vehicles[0]/body_style" other:sourceField="vehicles.body_style" other:analyzed="true" />
<input name="rows@next" desc="データのページングに使われる内部属性。" />
</rsb:info>
<rsb:set attr="es_index" value="auto"/>
<rsb:set attr="es_type" value="insured"/>
</rsb:script>