ODBC Driver for Elasticsearch

Build 23.0.8839

クエリマッピング

このセクションでは、SQL 構文がどのようにElasticsearch クエリに変換されているかを説明します。さまざまなクエリの結果がどうなるかを説明するサンプルも示されています。

コンテキストのクエリ/フィルタリングおよびスコアリング

_score カラムがselect された場合、検索結果の品質をスコアリングするクエリコンテキストリクエストを発行し、スコアリングがリクエストされます。デフォルトで、結果は 計算された_score の降順で返されます。ORDER BY 句によって返される結果の順序を指定することができます。

_score カラムがselect されていない場合、コンテキストのフィルタが送られ、Elasticsearch はスコアを計算しません。これらのクエリ結果はORDER BY 句により明示的に指定されない場合、任意の順序で返されます。

テキストマッチングおよび検索

Elasticsearch のanalyzed フィールドは、アナライザーを通した後は転置インデックスに格納されます。アナライザーはカスタマイズ可能であり、転置インデックスへの格納前にさまざまなフィルタを実行することができます。 例えば、デフォルトElasticsearch アナライザーはすべての単語を小文字に直します。

このポイントをデモするために、Elasticsearch のanalyzed フィールドには'Bike' という値を作成しています。 解析後、この値は(デフォルトアナライザーを使って)逆引きインデックスに'bike' として格納されます。 一方、non-analyzed フィールドは検索値を解析せず、'Bike' として格納されます。

検索を実行する際には、いくつかのElasticsearch クエリタイプは、アナライザーを通じて検索値を実行します(これにより、検索は大文字・小文字の区別がなくなります)。いくつかのクエリタイプは、アナライザーを経由しません(大文字・小文字を区別します)。 また、デフォルトアナライザーは、複数の単語を持つフィールドを個別の単語に分割します。これらのフィールドに検索を実行する場合、 Elasticsearch は同じ単語を持つレコードを別の順番で返すことがあります。例えば、'blue sky' という値に対して検索が実行された場合でも'sky blue' のレコードが返されます。

この大文字・小文字の区別や順序の問題の回避には、CData ODBC Driver for Elasticsearch は、カラムをanalyzed 、もしくはnon-analyzed に分類し、指定された演算子(= のような)に基づく適切なElasticsearch クエリを発行して、値を検索します。

イコールおよび非イコール

句がイコール(=)もしくは非イコール(= もしくは<>)フィルタを含む場合、使われるカラムやデータによって異なるElasticsearch クエリが発行されます。analyzed カラムとnon-analyzed カラムは別の動きをし、最適な検索機能が提供されるように異なるElasticsearch クエリが発行されます。 また、文字列値が空白を含むかどうかにより、異なるクエリが発行されます。 以下は、いくつかのケースでのルールおよび動作の説明です。

analyzed カラム
analyzed カラムはアナライザーを通された後に格納されます。その結果として、指定された検索値は、検索前にElasticsearch サーバーのアナライザーを通されます。これにより検索は大文字・小文字の区別がなくなります(使われたアナライザーが大文字・小文字を処理する前提で)。

WHERE 句の例 Elasticsearch クエリタイプ
WHERE analyzed_column='value' Query String Query
WHERE analyzed_column='value with spaces' Match Phrase Query

Non-Analyzed Columns
non-analyzed カラムはアナライザーを通されずに格納されます。これにより、non-analyzed カラムは大文字・小文字の区別があり、これらのカラムの検索値は大文字・小文字を区別しなければなりません。検索値が1つの単語である場合、本製品 は3つの標準的な形式である、大文字、小文字、すべて大文字、で指定されたオリジナルケーシングでフィルタをチェックします。 検索値が複数の単語を含む場合、検索値はas-is で送られ、大文字・小文字の区別があります。

WHERE 句の例 Elasticsearch クエリタイプ
WHERE nonanalyzed_column='myValue' Query String Query: Four cases are checked - myValue OR MYVALUE OR myvalue OR Myvalue
WHERE nonanalyzed_column='value with spaces' Wildcard Query

IN and NOT IN

IN およびNOT IN 演算子はイコールおよび非イコール演算子と非常に似た機能を果たします。

WHERE 句の例 Behavior
WHERE column IN ('value') Treated as: column='value'
WHERE column NOT IN ('value') Treated as: column!='value'
WHERE column IN ('value1', 'value2') Treated as: column='value1' OR column='value2'
WHERE column NOT IN ('value1', 'value2') Treated as: column!='value1' AND column!='value2'

LIKE およびNOT LIKE

LIKE およびNOT LIKE 演算子はワイルドカード文字として使うことができます。% はゼロ、1、もしくは複数の文字を意味します。アンダースコア(_)は一つの文字を意味します(文字が存在している必要があります)。

WHERE 句の例 Behavior
WHERE column LIKE 'value' Treated as: column='value'
WHERE column NOT LIKE 'value' Treated as: column!='value'
WHERE analyzed_column LIKE 'v_lu%' Query String Query with wildcards
WHERE nonanalyzed_column LIKE 'v_lu%' Wildcard Query with wildcards

Aggregate Filtering

Aggregate data may consist of JSON objects or arrays (both primitive and object arrays).

JSON objects and arrays of objects will be treated as raw strings and all filtering will be performed by the 本製品. Therefore an equals operation must match the entire JSON aggregate to return a result, unless a CONTAINS or LIKE operation is used.

If JSON objects are flattened into individual columns (via FlattenObjects and FlattenArrays), the column for the specific JSON field will be treated as individual columns. Thus the data type will be that as contained in the Elasticsearch mapping and all filters will be pushed to the server (where applicable).

JSON primitive array aggregates will also be treated as raw strings by default and filters will be performed by the 本製品. To filter data based on whether a primitive array contains a single value, the INARRAY function can be used (e.g. INARRAY(column) = 'value'). When performing a search on array fields, Elasticsearch looks at each value individually within an array. Thus when the INARRAY function is specified in a WHERE clause, the filter will be pushed to the server which performs a search within an array.

Primitive arrays may consist of different data types, such as strings or ints. Therefore the INARRAY function supports comparison operators applicable to the data type within the Elasticsearch mapping for the field. For example, INARRAY(int_array) > 5, will return all rows of data in which the int_array contains a value greater than 5. Supported comparison operators include the use of the LIKE operator for string arrays.

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839