doc-exports/docs/css/umn/css_01_0061.html
Wuwan, Qi 050b395397 CSS UMN 23.2.1 20230926
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com>
Co-authored-by: Wuwan, Qi <wuwanqi1@noreply.gitea.eco.tsi-dev.otc-service.com>
Co-committed-by: Wuwan, Qi <wuwanqi1@noreply.gitea.eco.tsi-dev.otc-service.com>
2024-01-10 14:23:15 +00:00

327 lines
31 KiB
HTML

<a name="css_01_0061"></a><a name="css_01_0061"></a>
<h1 class="topictitle1">Using the Open Distro SQL Plugin</h1>
<div id="body1562124251004"><p id="css_01_0061__en-us_topic_0000001268594557_p412122212308">For Elasticsearch 6.5.4 and later versions, Open Distro for Elasticsearch SQL lets you write queries in SQL rather than in the Elasticsearch query domain-specific language (DSL).</p>
<p id="css_01_0061__en-us_topic_0000001268594557_p14906121217302">If you are already familiar with SQL and do not want to learn query DSL, this feature is a great option.</p>
<div class="section" id="css_01_0061__en-us_topic_0000001268594557_section59231342303"><h4 class="sectiontitle">Basic Operations</h4><ul id="css_01_0061__en-us_topic_0000001268594557_ul165831326120"><li id="css_01_0061__en-us_topic_0000001268594557_li05831021116">Kibana (recommended)<ul id="css_01_0061__en-us_topic_0000001268594557_ul67081305120"><li id="css_01_0061__en-us_topic_0000001268594557_li14709103011119">Log in to Kibana and send requests using request parameters or request body to <strong id="css_01_0061__b13214411195512">_opendistro/_sqlURI</strong> in the <strong id="css_01_0061__b17268815105516">Dev Tools</strong> page.<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen887920471045">GET _opendistro/_sql?sql=select * from my-index limit 50</pre>
<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen158809477411">POST _opendistro/_sql
{
"query": "SELECT * FROM my-index LIMIT 50"
}</pre>
</li><li id="css_01_0061__en-us_topic_0000001268594557_li19313824444">By default, the result is returned in the JSON structure. If you want the result to be returned in the CSV format, run the following command:<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen120515501255">POST _opendistro/_sql?format=csv
{
"query": "SELECT * FROM my-index LIMIT 50"
}</pre>
<p id="css_01_0061__en-us_topic_0000001268594557_p14212203148">When data is returned in the CSV format, each row corresponds to a document and each column corresponds to a field.</p>
</li></ul>
</li><li id="css_01_0061__en-us_topic_0000001268594557_li343015161417">cURL commands<p id="css_01_0061__en-us_topic_0000001268594557_p10352171713713"><a name="css_01_0061__en-us_topic_0000001268594557_li343015161417"></a><a name="en-us_topic_0000001268594557_li343015161417"></a>You can also run cURL commands in ECS to execute SQL statements.</p>
<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen048591921014">curl -XPOST https://localhost:9200/_opendistro/_sql -u username:password -k -d '{"query": "SELECT * FROM kibana_sample_data_flights LIMIT 10"}' -H 'Content-Type: application/json'</pre>
</li></ul>
<p id="css_01_0061__en-us_topic_0000001268594557_p43991212177"></p>
</div>
<div class="section" id="css_01_0061__en-us_topic_0000001268594557_section17251759164012"><h4 class="sectiontitle">Supported Operations</h4><p id="css_01_0061__en-us_topic_0000001268594557_p162295419416">Open Distro for Elasticsearch supports the following SQL operations: statements, conditions, aggregations, include and exclude fields, common functions, joins, and show.</p>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul465451824513"><li id="css_01_0061__en-us_topic_0000001268594557_li1765481815457">Statements
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table136696188464" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Statements</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row18670121812462"><th align="left" class="cellrowborder" valign="top" width="12.58%" id="mcps1.3.4.3.1.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p201811141478">Statement</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="87.42%" id="mcps1.3.4.3.1.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p71821541475">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row1667091864614"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p418244144714">Select</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p31827484717">SELECT * FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row126709180463"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p1618213484716">Delete</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p41821145479">DELETE FROM my-index WHERE _id=1</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row16701185462"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p6182340475">Where</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p618220416477">SELECT * FROM my-index WHERE ['field']='value'</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1367010187461"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p618213418474">Order by</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1918215484720">SELECT * FROM my-index ORDER BY _id asc</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1767141804619"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p151820410478">Group by</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p918244104712">SELECT * FROM my-index GROUP BY range(age, 20,30,39)</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row9671818144613"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p17182443475">Limit</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p61821494717">SELECT * FROM my-index LIMIT 50 (default is 200)</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1867115188466"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p51827419472">Union</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1818224194715">SELECT * FROM my-index1 UNION SELECT * FROM my-index2</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row196711618144617"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.3.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p51824494716">Minus</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.3.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1618212474720">SELECT * FROM my-index1 MINUS SELECT * FROM my-index2</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="css_01_0061__en-us_topic_0000001268594557_note1761712244817"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="css_01_0061__en-us_topic_0000001268594557_p86171624483">As with any complex query, large UNION and MINUS statements can strain or even crash your cluster.</p>
</div></div>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul1772193644811"><li id="css_01_0061__en-us_topic_0000001268594557_li5722136154818">Conditions
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table1788703814504" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Conditions</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row1888418383503"><th align="left" class="cellrowborder" valign="top" width="12.58%" id="mcps1.3.4.4.1.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p1188413815017">Condition</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="87.42%" id="mcps1.3.4.4.1.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p68842038185014">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row9884123845010"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p198841382502">Like</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p8884638195015">SELECT * FROM my-index WHERE name LIKE 'j%'</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row20884123818507"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p3884163814505">And</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p788463810505">SELECT * FROM my-index WHERE name LIKE 'j%' AND age &gt; 21</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row168841338185010"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p16884103818509">Or</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p8884838175015">SELECT * FROM my-index WHERE name LIKE 'j%' OR age &gt; 21</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row8885138195017"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p16885638155011">Count distinct</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p78851538115013">SELECT count(distinct age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row5885838195014"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p88851138145011">In</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p9885123805012">SELECT * FROM my-index WHERE name IN ('alejandro', 'carolina')</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row38858384509"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p988512381506">Not</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p888510387505">SELECT * FROM my-index WHERE name NOT IN ('jane')</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row88852382506"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p138855386507">Between</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1988583845011">SELECT * FROM my-index WHERE age BETWEEN 20 AND 30</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row188543810506"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p7885173875016">Aliases</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p988523815501">SELECT avg(age) AS Average_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1388719382509"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p18887153820500">Date</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p128870384504">SELECT * FROM my-index WHERE birthday='1990-11-15'</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row148871638175019"><td class="cellrowborder" valign="top" width="12.58%" headers="mcps1.3.4.4.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p888773815011">Null</p>
</td>
<td class="cellrowborder" valign="top" width="87.42%" headers="mcps1.3.4.4.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p20887203819506">SELECT * FROM my-index WHERE name IS NULL</p>
</td>
</tr>
</tbody>
</table>
</div>
</li><li id="css_01_0061__en-us_topic_0000001268594557_li16104202917515">Aggregations
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table14777194527" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Aggregations</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row117783965212"><th align="left" class="cellrowborder" valign="top" width="12.04%" id="mcps1.3.4.4.2.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p1822862318528">Aggregation</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="87.96000000000001%" id="mcps1.3.4.4.2.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p11228723105220">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row677812985214"><td class="cellrowborder" valign="top" width="12.04%" headers="mcps1.3.4.4.2.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p11228423145212">avg()</p>
</td>
<td class="cellrowborder" valign="top" width="87.96000000000001%" headers="mcps1.3.4.4.2.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p4228122315210">SELECT avg(age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1577812914522"><td class="cellrowborder" valign="top" width="12.04%" headers="mcps1.3.4.4.2.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p6228192385212">count()</p>
</td>
<td class="cellrowborder" valign="top" width="87.96000000000001%" headers="mcps1.3.4.4.2.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p5228323165217">SELECT count(age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row19778893529"><td class="cellrowborder" valign="top" width="12.04%" headers="mcps1.3.4.4.2.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p722852325220">max()</p>
</td>
<td class="cellrowborder" valign="top" width="87.96000000000001%" headers="mcps1.3.4.4.2.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1122802318526">SELECT max(age) AS Highest_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row0778139175216"><td class="cellrowborder" valign="top" width="12.04%" headers="mcps1.3.4.4.2.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p22281623175215">min()</p>
</td>
<td class="cellrowborder" valign="top" width="87.96000000000001%" headers="mcps1.3.4.4.2.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p222862345220">SELECT min(age) AS Lowest_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row11778159125210"><td class="cellrowborder" valign="top" width="12.04%" headers="mcps1.3.4.4.2.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p11228923185219">sum()</p>
</td>
<td class="cellrowborder" valign="top" width="87.96000000000001%" headers="mcps1.3.4.4.2.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p15228323125218">SELECT sum(age) AS Age_Sum FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul636917462528"><li id="css_01_0061__en-us_topic_0000001268594557_li19369204610528">Include and exclude fields
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table54279212535" frame="border" border="1" rules="all"><caption><b>Table 4 </b>Include and exclude fields</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row2428132125318"><th align="left" class="cellrowborder" valign="top" width="11.5%" id="mcps1.3.4.5.1.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p1945132611535">Pattern</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="88.5%" id="mcps1.3.4.5.1.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p29451226205312">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row742816295318"><td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.3.4.5.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p18945726115312">include()</p>
</td>
<td class="cellrowborder" valign="top" width="88.5%" headers="mcps1.3.4.5.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p29451265533">SELECT include('a*'), exclude('age') FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row24288215316"><td class="cellrowborder" valign="top" width="11.5%" headers="mcps1.3.4.5.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p11945726105314">exclude()</p>
</td>
<td class="cellrowborder" valign="top" width="88.5%" headers="mcps1.3.4.5.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p18945142685318">SELECT exclude('*name') FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul12780174635316"><li id="css_01_0061__en-us_topic_0000001268594557_li078034617535">Functions
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table1388491105413" frame="border" border="1" rules="all"><caption><b>Table 5 </b>Functions</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row28841411135411"><th align="left" class="cellrowborder" valign="top" width="11.41%" id="mcps1.3.4.6.1.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p77251736135419">Function</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="88.59%" id="mcps1.3.4.6.1.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p872593605420">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row5885811125411"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p372663615414">floor</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p572653645411">SELECT floor(number) AS Rounded_Down FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row1088571116543"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p2726436155413">trim</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1272619363547">SELECT trim(name) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row18885111115546"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p187261936165417">log</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p13726236135416">SELECT log(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row38852011195416"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p13726163675416">log10</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p197263366547">SELECT log10(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row19885181195414"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p11726193618544">substring</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p57262367545">SELECT substring(name, 2,5) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row58851811115410"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p172633665411">round</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p87261836155412">SELECT round(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row14885511155413"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p472653618540">sqrt</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p19726336145413">SELECT sqrt(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row14885101175420"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p14726236105419">concat_ws</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1972611368548">SELECT concat_ws(' ', age, height) AS combined FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row16885191105414"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p18726936165410">/</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p372618366547">SELECT number / 100 FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row14885011105410"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p1272713616543">%</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p19727153655417">SELECT number % 100 FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row11885511135416"><td class="cellrowborder" valign="top" width="11.41%" headers="mcps1.3.4.6.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p972713685413">date_format</p>
</td>
<td class="cellrowborder" valign="top" width="88.59%" headers="mcps1.3.4.6.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p3727436145418">SELECT date_format(date, 'Y') FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="css_01_0061__en-us_topic_0000001268594557_note16422449165417"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="css_01_0061__en-us_topic_0000001268594557_p134231049165417">You must enable fielddata in the document mapping for most string functions to work properly.</p>
</div></div>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul1695269155520"><li id="css_01_0061__en-us_topic_0000001268594557_li19952139195510">Joins
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table2631133710555" frame="border" border="1" rules="all"><caption><b>Table 6 </b>Joins</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row36321937105512"><th align="left" class="cellrowborder" valign="top" width="11.59%" id="mcps1.3.4.7.1.1.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p171605492551">Join</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="88.41%" id="mcps1.3.4.7.1.1.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p1416024945513">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row13632937105516"><td class="cellrowborder" valign="top" width="11.59%" headers="mcps1.3.4.7.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p616054985515">Inner join</p>
</td>
<td class="cellrowborder" valign="top" width="88.41%" headers="mcps1.3.4.7.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p1281322512377">SELECT s.firstname, s.lastname, s.gender, sc.name FROM student s JOIN school sc ON sc.name = s.school_name WHERE s.age &gt; 20</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row18632153725514"><td class="cellrowborder" valign="top" width="11.59%" headers="mcps1.3.4.7.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p19160124955518">Left outer join</p>
</td>
<td class="cellrowborder" valign="top" width="88.41%" headers="mcps1.3.4.7.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p19882134153819">SELECT s.firstname, s.lastname, s.gender, sc.name FROM student s LEFT JOIN school sc ON sc.name = s.school_name</p>
</td>
</tr>
<tr id="css_01_0061__en-us_topic_0000001268594557_row6632203785510"><td class="cellrowborder" valign="top" width="11.59%" headers="mcps1.3.4.7.1.1.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p131615491559">Cross join</p>
</td>
<td class="cellrowborder" valign="top" width="88.41%" headers="mcps1.3.4.7.1.1.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p93604212399">SELECT s.firstname, s.lastname, s.gender, sc.name FROM student s CROSS JOIN school sc</p>
</td>
</tr>
</tbody>
</table>
</div>
<p id="css_01_0061__en-us_topic_0000001268594557_p1489516104565">For details about the restrictions, see <a href="#css_01_0061__en-us_topic_0000001268594557_section89917481618">Joins</a>.</p>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul481615419575"><li id="css_01_0061__en-us_topic_0000001268594557_li19816204125713">Show<p id="css_01_0061__en-us_topic_0000001268594557_p138722362573"><a name="css_01_0061__en-us_topic_0000001268594557_li19816204125713"></a><a name="en-us_topic_0000001268594557_li19816204125713"></a>Show commands display indexes and mappings that match an index pattern. You can use <strong id="css_01_0061__b946325422415">*</strong> or <strong id="css_01_0061__b5409856172418">%</strong> for wildcards.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__en-us_topic_0000001268594557_table1919121475815" frame="border" border="1" rules="all"><caption><b>Table 7 </b>Show</caption><thead align="left"><tr id="css_01_0061__en-us_topic_0000001268594557_row692041455817"><th align="left" class="cellrowborder" valign="top" width="12.22%" id="mcps1.3.4.8.1.2.2.3.1.1"><p id="css_01_0061__en-us_topic_0000001268594557_p19984153416582">Show</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="87.78%" id="mcps1.3.4.8.1.2.2.3.1.2"><p id="css_01_0061__en-us_topic_0000001268594557_p2098418342580">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__en-us_topic_0000001268594557_row16920131416588"><td class="cellrowborder" valign="top" width="12.22%" headers="mcps1.3.4.8.1.2.2.3.1.1 "><p id="css_01_0061__en-us_topic_0000001268594557_p10985133485814">Show tables like</p>
</td>
<td class="cellrowborder" valign="top" width="87.78%" headers="mcps1.3.4.8.1.2.2.3.1.2 "><p id="css_01_0061__en-us_topic_0000001268594557_p8985133410588">SHOW TABLES LIKE logs-*</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
</div>
<div class="section" id="css_01_0061__en-us_topic_0000001268594557_section89917481618"><a name="css_01_0061__en-us_topic_0000001268594557_section89917481618"></a><a name="en-us_topic_0000001268594557_section89917481618"></a><h4 class="sectiontitle">Joins</h4><p id="css_01_0061__en-us_topic_0000001268594557_p0551203710167">Open Distro for Elasticsearch SQL supports inner joins, left outer joins and cross joins. Joins have the following constraints:</p>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul9814142441718"><li id="css_01_0061__en-us_topic_0000001268594557_li8814142481718">You can only join two indexes.</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul28561231121711"><li id="css_01_0061__en-us_topic_0000001268594557_li128569311174">You must use an alias for an index (for example, people p).</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul8256838151713"><li id="css_01_0061__en-us_topic_0000001268594557_li225673851720">In an ON clause, you can only use the AND conditions.</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul1848794614174"><li id="css_01_0061__en-us_topic_0000001268594557_li14870468176">In a WHERE statement, do not combine trees that contain multiple indexes. For example, the following statement will work:<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen12492163191819">WHERE (a.type1 &gt; 3 OR a.type1 &lt; 0) AND (b.type2 &gt; 4 OR b.type2 &lt; -1)</pre>
<div class="p" id="css_01_0061__en-us_topic_0000001268594557_p2551183710167">The following statement will not work:<pre class="screen" id="css_01_0061__en-us_topic_0000001268594557_screen10526134218183">WHERE (a.type1 &gt; 3 OR b.type2 &lt; 0) AND (a.type1 &gt; 4 OR b.type2 &lt; -1)</pre>
</div>
</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul14929185615174"><li id="css_01_0061__en-us_topic_0000001268594557_li292955641714">You cannot use GROUP BY or ORDER BY to obtain results.</li></ul>
<ul id="css_01_0061__en-us_topic_0000001268594557_ul81119714183"><li id="css_01_0061__en-us_topic_0000001268594557_li81119791815">LIMIT with OFFSET (for example, LIMIT 25 OFFSET 25) is not supported.</li></ul>
</div>
<div class="section" id="css_01_0061__en-us_topic_0000001268594557_section153416302213"><h4 class="sectiontitle">JDBC Driver</h4><p id="css_01_0061__en-us_topic_0000001268594557_p7514165152217">The Java Database Connectivity (JDBC) driver allows you to integrate Open Distro for Elasticsearch with your business intelligence (BI) applications.</p>
<p id="css_01_0061__en-us_topic_0000001268594557_p5514105182211">For details about how to download and use JAR files, see <a href="https://github.com/opendistro-for-elasticsearch/sql-jdbc" target="_blank" rel="noopener noreferrer">GitHub Repositories</a>.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="css_01_0212.html">Managing Plugins</a></div>
</div>
</div>