DELETE nested_numbers
POST /nested_numbers/_doc
{"numbers": [{"n": 1}, {"n": 2}]}
POST /_xpack/sql?format=json
{
"query": "select * from nested_numbers"
}
will fail with an sql_illegal_argument_exception stating "reason": "Arrays (returned by [numbers.n]) are not supported". But I'm not sure there's a good reason for this restriction (note that the format above is json, not txt).
If I take the result of the sql request, pass it to /translate and then _search I get the expected results.
GET nested_numbers/_search
# The GET body below is the response from
#
# POST /_xpack/sql/translate
# {
# "query": "select * from nested_numbers"
# }
{
"size": 1000,
"_source": false,
"stored_fields": "_none_",
"docvalue_fields": [
"numbers.n"
],
"sort": [
{
"_doc": {
"order": "asc"
}
}
]
}
The only good reason I can think of for this restriction is that it makes JDBC connectivity awkward, but the JDBC driver for PostgreSQL works ok with JSON. Would it be possible to allow SQL queries to return arrays and nested types?
Finally, the error message associated with this condition is type-dependent. The following errors with # "reason": "Cannot extract value [numbers.n] from source".
DELETE nested_strings
POST /nested_strings/_doc
{"numbers": [{"n": "one"}, {"n": "two"}]}
POST /_xpack/sql?format=json
{
"query": "select * from nested_strings"
}
I've realised that as this restriction doesn't apply when using nested docs, this isn't actually an issue for me. However, some docs describing these error messages would be very helpful.
Hi @paulcarey,
Glad to see you took ES-SQL for a spin.
The reason for not supporting arrays is, in principle, related to SQL way of dealing with values: rows and columns where each element in the matrix is a single value. When you have an array of values for a certain row and column, which one do you want to return? The first, third, fifth etc? Also, this being JSON (as the native format in which _source is stored in Elasticsearch - and JSON is by definition unordered) how do you define "first", "third" etc.
Also, SQL doesn't have the notion of arrays of values.
Thanks for the response, but stating that SQL doesn't have the notion of arrays of values isn't really correct.
Obviously 'SQL' can be a bit ambiguous, depending on versions of specs etc., but here's an example of using Arrays of Structs with JDBC and PostgreSQL.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.