Data Types
editData Types
editThis functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
Most of Elasticsearch data types are available in Elasticsearch SQL, as indicated below:
Elasticsearch type | SQL type | SQL precision |
---|---|---|
Core types |
||
|
0 |
|
|
1 |
|
|
3 |
|
|
5 |
|
|
10 |
|
|
19 |
|
|
15 |
|
|
7 |
|
|
16 |
|
|
19 |
|
|
based on |
|
|
2,147,483,647 |
|
|
2,147,483,647 |
|
|
24 |
|
Complex types |
||
|
0 |
|
|
0 |
|
Unsupported types |
||
types not mentioned above |
|
0 |
Obviously, not all types in Elasticsearch have an equivalent in SQL and vice-versa hence why, Elasticsearch SQL uses the data type particularities of the former over the latter as ultimately Elasticsearch is the backing store.
SQL and multi-fields
editA core concept in Elasticsearch is that of an analyzed
field, that is a full-text value that is interpreted in order
to be effectively indexed. These fields are of type text
and are not used for sorting or aggregations as their actual value depends on the analyzer
used hence why Elasticsearch also offers the keyword
type for storing the exact
value.
In most case, and the default actually, is to use both types when for strings which Elasticsearch supports through multi fields, that is the ability to index the same string in multiple ways; for example index it both as text
for search but also as keyword
for sorting and aggregations.
As SQL requires exact values, when encountering a text
field Elasticsearch SQL will search for an exact multi-field that it can use for comparisons, sorting and aggregations.
To do that, it will search for the first keyword
that it can find that is not normalized and use that as the original field exact value.
Consider the following string
mapping:
{ "first_name" : { "type" : "text", "fields" : { "raw" : { "type" : "keyword" } } } }
The following SQL query:
SELECT first_name FROM index WHERE first_name = 'John'
is identical to:
SELECT first_name FROM index WHERE first_name.raw = 'John'
as Elasticsearch SQL automatically picks up the raw
multi-field from raw
for exact matching.