|
@@ -9,6 +9,7 @@
|
|
|
* <<sql-rest-filtering>>
|
|
|
* <<sql-rest-columnar>>
|
|
|
* <<sql-rest-params>>
|
|
|
+* <<sql-runtime-fields>>
|
|
|
* <<sql-rest-fields>>
|
|
|
|
|
|
[[sql-rest-overview]]
|
|
@@ -522,6 +523,44 @@ POST /_sql?format=txt
|
|
|
[IMPORTANT]
|
|
|
The recommended way of passing values to a query is with question mark placeholders, to avoid any attempts of hacking or SQL injection.
|
|
|
|
|
|
+[[sql-runtime-fields]]
|
|
|
+=== Use runtime fields
|
|
|
+
|
|
|
+Use the `runtime_mappings` parameter to extract and create <<runtime,runtime
|
|
|
+fields>>, or columns, from existing ones during a search.
|
|
|
+
|
|
|
+The following search creates a `release_day_of_week` runtime field from
|
|
|
+`release_date` and returns it in the response.
|
|
|
+
|
|
|
+[source,console]
|
|
|
+----
|
|
|
+POST _sql?format=txt
|
|
|
+{
|
|
|
+ "runtime_mappings": {
|
|
|
+ "release_day_of_week": {
|
|
|
+ "type": "keyword",
|
|
|
+ "script": """
|
|
|
+ emit(doc['release_date'].value.dayOfWeekEnum.toString())
|
|
|
+ """
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "query": """
|
|
|
+ SELECT * FROM library WHERE page_count > 300 AND author = 'Frank Herbert'
|
|
|
+ """
|
|
|
+}
|
|
|
+----
|
|
|
+// TEST[setup:library]
|
|
|
+
|
|
|
+The API returns:
|
|
|
+
|
|
|
+[source,txt]
|
|
|
+----
|
|
|
+ author | name | page_count | release_date |release_day_of_week
|
|
|
+---------------+---------------+---------------+------------------------+-------------------
|
|
|
+Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z|TUESDAY
|
|
|
+----
|
|
|
+// TESTRESPONSE[non_json]
|
|
|
+
|
|
|
[[sql-rest-fields]]
|
|
|
=== Supported REST parameters
|
|
|
|
|
@@ -530,7 +569,7 @@ the request time-outs or localization information (such as timezone).
|
|
|
|
|
|
The table below lists the supported parameters:
|
|
|
|
|
|
-[cols="^m,^m,^5"]
|
|
|
+[cols="<m,<m,<5"]
|
|
|
|
|
|
|===
|
|
|
|
|
@@ -579,6 +618,11 @@ More information available https://docs.oracle.com/javase/8/docs/api/java/time/Z
|
|
|
|none
|
|
|
|Optional list of parameters to replace question mark (`?`) placeholders inside the query.
|
|
|
|
|
|
+|runtime_mappings
|
|
|
+|none
|
|
|
+|Defines one or more <<runtime-search-request,runtime fields>> in the search
|
|
|
+request. These fields take precedence over mapped fields with the same name.
|
|
|
+
|
|
|
|===
|
|
|
|
|
|
Do note that most parameters (outside the timeout and `columnar` ones) make sense only during the initial query - any follow-up pagination request only requires the `cursor` parameter as explained in the <<sql-pagination, pagination>> chapter.
|