Skip to content

Commit c465971

Browse files
committed
SQL: document the use of a filter on _routing (#52355)
* Fix "Description"s for various sections in the functions pages. * Added a TIP for searching using a routing key. * Other small polishings (cherry picked from commit 9fad0b1)
1 parent 72f44e8 commit c465971

19 files changed

+153
-354
lines changed

docs/reference/sql/endpoints/jdbc.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ connection. For example:
208208
include-tagged::{jdbc-tests}/SimpleExampleTestCase.java[simple_example]
209209
--------------------------------------------------
210210

211-
NOTE:: {es-sql} doesn't provide a connection pooling mechanism, thus the connections
211+
[NOTE]
212+
{es-sql} doesn't provide a connection pooling mechanism, thus the connections
212213
the JDBC driver creates are not pooled. In order to achieve pooled connections,
213214
a third-party connection pooling mechanism is required. Configuring and setting up the
214215
third-party provider is outside the scope of this documentation.

docs/reference/sql/endpoints/rest.asciidoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,26 @@ Douglas Adams |The Hitchhiker's Guide to the Galaxy|180 |1979-10-12T
370370
// TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
371371
// TESTRESPONSE[non_json]
372372

373+
[TIP]
374+
=================
375+
A useful and less obvious usage for standard query DSL filtering is to search documents by a specific <<search-routing, routing key>>.
376+
Because {es-sql} does not support a `routing` parameter, one can specify a <<mapping-routing-field, `terms` filter for the `_routing` field>> instead:
377+
378+
[source,console]
379+
--------------------------------------------------
380+
POST /_sql?format=txt
381+
{
382+
"query": "SELECT * FROM library",
383+
"filter": {
384+
"terms": {
385+
"_routing": ["abc"]
386+
}
387+
}
388+
}
389+
--------------------------------------------------
390+
// TEST[setup:library]
391+
=================
392+
373393
[[sql-rest-columnar]]
374394
=== Columnar results
375395

docs/reference/sql/functions/aggs.asciidoc

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ AVG(numeric_field) <1>
2525

2626
*Output*: `double` numeric value
2727

28-
.Description:
29-
30-
Returns the https://en.wikipedia.org/wiki/Arithmetic_mean[Average] (arithmetic mean) of input values.
28+
*Description*: Returns the https://en.wikipedia.org/wiki/Arithmetic_mean[Average] (arithmetic mean) of input values.
3129

3230
["source","sql",subs="attributes,macros"]
3331
--------------------------------------------------
@@ -49,9 +47,7 @@ COUNT(expression) <1>
4947

5048
*Output*: numeric value
5149

52-
.Description:
53-
54-
Returns the total number (count) of input values.
50+
*Description*: Returns the total number (count) of input values.
5551

5652
In case of `COUNT(*)` or `COUNT(<literal>)`, _all_ values are considered (including `null` or missing ones).
5753

@@ -79,9 +75,7 @@ COUNT(ALL field_name) <1>
7975

8076
*Output*: numeric value
8177

82-
.Description:
83-
84-
Returns the total number (count) of all _non-null_ input values. `COUNT(<field_name>)` and `COUNT(ALL <field_name>)` are equivalent.
78+
*Description*: Returns the total number (count) of all _non-null_ input values. `COUNT(<field_name>)` and `COUNT(ALL <field_name>)` are equivalent.
8579

8680
["source","sql",subs="attributes,macros"]
8781
--------------------------------------------------
@@ -104,9 +98,7 @@ COUNT(DISTINCT field_name) <1>
10498

10599
*Output*: numeric value
106100

107-
.Description:
108-
109-
Returns the total number of _distinct non-null_ values in input values.
101+
*Description*: Returns the total number of _distinct non-null_ values in input values.
110102

111103
["source","sql",subs="attributes,macros"]
112104
--------------------------------------------------
@@ -131,9 +123,7 @@ FIRST(
131123

132124
*Output*: same type as the input
133125

134-
.Description:
135-
136-
Returns the first **non-NULL** value (if such exists) of the `field_name` input column sorted by
126+
*Description*: Returns the first **non-NULL** value (if such exists) of the `field_name` input column sorted by
137127
the `ordering_field_name` column. If `ordering_field_name` is not provided, only the `field_name`
138128
column is used for the sorting. E.g.:
139129

@@ -228,10 +218,8 @@ LAST(
228218

229219
*Output*: same type as the input
230220

231-
.Description:
232-
233-
It's the inverse of <<sql-functions-aggs-first>>. Returns the last **non-NULL** value (if such exists) of the
234-
`field_name`input column sorted descending by the `ordering_field_name` column. If `ordering_field_name` is not
221+
*Description*: It's the inverse of <<sql-functions-aggs-first>>. Returns the last **non-NULL** value (if such exists) of the
222+
`field_name` input column sorted descending by the `ordering_field_name` column. If `ordering_field_name` is not
235223
provided, only the `field_name` column is used for the sorting. E.g.:
236224

237225
[cols="<,<"]
@@ -322,9 +310,7 @@ MAX(field_name) <1>
322310

323311
*Output*: same type as the input
324312

325-
.Description:
326-
327-
Returns the maximum value across input values in the field `field_name`.
313+
*Description*: Returns the maximum value across input values in the field `field_name`.
328314

329315
["source","sql",subs="attributes,macros"]
330316
--------------------------------------------------
@@ -350,9 +336,7 @@ MIN(field_name) <1>
350336

351337
*Output*: same type as the input
352338

353-
.Description:
354-
355-
Returns the minimum value across input values in the field `field_name`.
339+
*Description*: Returns the minimum value across input values in the field `field_name`.
356340

357341
["source","sql",subs="attributes,macros"]
358342
--------------------------------------------------
@@ -378,9 +362,7 @@ SUM(field_name) <1>
378362

379363
*Output*: `bigint` for integer input, `double` for floating points
380364

381-
.Description:
382-
383-
Returns the sum of input values in the field `field_name`.
365+
*Description*: Returns the sum of input values in the field `field_name`.
384366

385367
["source","sql",subs="attributes,macros"]
386368
--------------------------------------------------
@@ -406,7 +388,7 @@ KURTOSIS(field_name) <1>
406388

407389
*Output*: `double` numeric value
408390

409-
.Description:
391+
*Description*:
410392

411393
https://en.wikipedia.org/wiki/Kurtosis[Quantify] the shape of the distribution of input values in the field `field_name`.
412394

@@ -430,7 +412,7 @@ MAD(field_name) <1>
430412

431413
*Output*: `double` numeric value
432414

433-
.Description:
415+
*Description*:
434416

435417
https://en.wikipedia.org/wiki/Median_absolute_deviation[Measure] the variability of the input values in the field `field_name`.
436418

@@ -457,7 +439,7 @@ PERCENTILE(
457439

458440
*Output*: `double` numeric value
459441

460-
.Description:
442+
*Description*:
461443

462444
Returns the nth https://en.wikipedia.org/wiki/Percentile[percentile] (represented by `numeric_exp` parameter)
463445
of input values in the field `field_name`.
@@ -485,7 +467,7 @@ PERCENTILE_RANK(
485467

486468
*Output*: `double` numeric value
487469

488-
.Description:
470+
*Description*:
489471

490472
Returns the nth https://en.wikipedia.org/wiki/Percentile_rank[percentile rank] (represented by `numeric_exp` parameter)
491473
of input values in the field `field_name`.
@@ -510,7 +492,7 @@ SKEWNESS(field_name) <1>
510492

511493
*Output*: `double` numeric value
512494

513-
.Description:
495+
*Description*:
514496

515497
https://en.wikipedia.org/wiki/Skewness[Quantify] the asymmetric distribution of input values in the field `field_name`.
516498

@@ -534,7 +516,7 @@ STDDEV_POP(field_name) <1>
534516

535517
*Output*: `double` numeric value
536518

537-
.Description:
519+
*Description*:
538520

539521
Returns the https://en.wikipedia.org/wiki/Standard_deviations[population standard deviation] of input values in the field `field_name`.
540522

@@ -558,7 +540,7 @@ SUM_OF_SQUARES(field_name) <1>
558540

559541
*Output*: `double` numeric value
560542

561-
.Description:
543+
*Description*:
562544

563545
Returns the https://en.wikipedia.org/wiki/Total_sum_of_squares[sum of squares] of input values in the field `field_name`.
564546

@@ -582,7 +564,7 @@ VAR_POP(field_name) <1>
582564

583565
*Output*: `double` numeric value
584566

585-
.Description:
567+
*Description*:
586568

587569
Returns the https://en.wikipedia.org/wiki/Variance[population variance] of input values in the field `field_name`.
588570

docs/reference/sql/functions/conditional.asciidoc

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ an _ELSE *default_result_* clause. Every *condition* should be a boolean express
2626
the *default_result* if all _WHEN *condition_* clauses evaluate to `false`. If the optional _ELSE *default_result_*
2727
clause is missing and all _WHEN *condition_* clauses evaluate to `false` then `null` is returned.
2828

29-
.Description
30-
31-
The CASE expression is a generic conditional expression which simulates if/else statements of other programming languages
29+
*Description*: The CASE expression is a generic conditional expression which simulates if/else statements of other programming languages
3230
If the condition’s result is true, the value of the result expression that follows the condition will be the returned
3331
the subsequent when clauses will be skipped and not processed.
3432

@@ -148,9 +146,7 @@ COALESCE can take an arbitrary number of arguments.
148146

149147
*Output*: one of the expressions or `null`
150148

151-
.Description
152-
153-
Returns the first of its arguments that is not null.
149+
*Description*: Returns the first of its arguments that is not null.
154150
If all arguments are null, then it returns `null`.
155151

156152

@@ -192,9 +188,7 @@ all of them must be of the same data type.
192188

193189
*Output*: one of the expressions or `null`
194190

195-
.Description
196-
197-
Returns the argument that has the largest value which is not null.
191+
*Description*: Returns the argument that has the largest value which is not null.
198192
If all arguments are null, then it returns `null`.
199193

200194

@@ -229,9 +223,7 @@ IFNULL(
229223

230224
*Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
231225

232-
.Description
233-
234-
Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
226+
*Description*: Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
235227
Returns the first of its arguments that is not null.
236228
If all arguments are null, then it returns `null`.
237229

@@ -269,9 +261,7 @@ IIF(expression, <1>
269261
*Output*: 2nd expression if 1st expression (condition) evaluates to `true`. If it evaluates to `false`
270262
return 3rd expression. If 3rd expression is not provided return `null`.
271263

272-
.Description
273-
274-
Conditional function that implements the standard _IF <condition> THEN <result1> ELSE <result2>_
264+
*Description*: Conditional function that implements the standard _IF <condition> THEN <result1> ELSE <result2>_
275265
logic of programming languages. If the 3rd expression is not provided and the condition evaluates to `false`,
276266
`null` is returned.
277267

@@ -316,9 +306,7 @@ ISNULL(
316306

317307
*Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
318308

319-
.Description
320-
321-
Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
309+
*Description*: Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
322310
Returns the first of its arguments that is not null.
323311
If all arguments are null, then it returns `null`.
324312

@@ -362,9 +350,7 @@ all of them must be of the same data type.
362350

363351
*Output*: one of the expressions or `null`
364352

365-
.Description
366-
367-
Returns the argument that has the smallest value which is not null.
353+
*Description*: Returns the argument that has the smallest value which is not null.
368354
If all arguments are null, then it returns `null`.
369355

370356

@@ -400,9 +386,7 @@ NULLIF(
400386

401387
*Output*: `null` if the 2 expressions are equal, otherwise the 1st expression.
402388

403-
.Description
404-
405-
Returns `null` when the two input expressions are equal and
389+
*Description*: Returns `null` when the two input expressions are equal and
406390
if not, it returns the 1st expression.
407391

408392

@@ -437,9 +421,7 @@ NVL(
437421

438422
*Output*: 2nd expression if 1st expression is null, otherwise 1st expression.
439423

440-
.Description
441-
442-
Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
424+
*Description*: Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
443425
Returns the first of its arguments that is not null.
444426
If all arguments are null, then it returns `null`.
445427

0 commit comments

Comments
 (0)