Skip to content

Commit 9fad0b1

Browse files
authored
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
1 parent c3c84c6 commit 9fad0b1

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
@@ -371,6 +371,26 @@ Douglas Adams |The Hitchhiker's Guide to the Galaxy|180 |1979-10-12T
371371
// TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
372372
// TESTRESPONSE[non_json]
373373

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

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

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

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

@@ -317,9 +307,7 @@ ISNULL(
317307

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

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

@@ -363,9 +351,7 @@ all of them must be of the same data type.
363351

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

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

371357

@@ -401,9 +387,7 @@ NULLIF(
401387

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

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

409393

@@ -438,9 +422,7 @@ NVL(
438422

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

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

0 commit comments

Comments
 (0)