doc-exports/docs/css/umn/css_01_0061.html
Zheng, Xiu 5b5876528a CSS UMN 22.5.1 Version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Zheng, Xiu <zhengxiu@huawei.com>
Co-committed-by: Zheng, Xiu <zhengxiu@huawei.com>
2023-03-29 17:17:49 +00:00

321 lines
25 KiB
HTML

<a name="css_01_0061"></a><a name="css_01_0061"></a>
<h1 class="topictitle1">Elasticsearch SQL</h1>
<div id="body0000001334778845"><p id="css_01_0061__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__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__section12911051103415"><h4 class="sectiontitle">Basic Operations</h4><ul id="css_01_0061__ul165831326120"><li id="css_01_0061__li05831021116">Kibana (recommended)<ul id="css_01_0061__ul67081305120"><li id="css_01_0061__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__screen887920471045">GET _opendistro/_sql?sql=select * from my-index limit 50</pre>
<pre class="screen" id="css_01_0061__screen158809477411">POST _opendistro/_sql
{
"query": "SELECT * FROM my-index LIMIT 50"
}</pre>
</li><li id="css_01_0061__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__screen120515501255">POST _opendistro/_sql?format=csv
{
"query": "SELECT * FROM my-index LIMIT 50"
}</pre>
<p id="css_01_0061__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__li343015161417">cURL commands<p id="css_01_0061__p10352171713713"><a name="css_01_0061__li343015161417"></a><a name="li343015161417"></a>You can also run cURL commands in ECS to execute SQL statements.</p>
<pre class="screen" id="css_01_0061__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>
</div>
<div class="section" id="css_01_0061__section17251759164012"><h4 class="sectiontitle">Supported Operations</h4><p id="css_01_0061__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__ul465451824513"><li id="css_01_0061__li1765481815457">Statements
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__table136696188464" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Statements</caption><thead align="left"><tr id="css_01_0061__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__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__p71821541475">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p31827484717">SELECT * FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p41821145479">DELETE FROM my-index WHERE _id=1</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p618220416477">SELECT * FROM my-index WHERE ['field']='value'</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1918215484720">SELECT * FROM my-index ORDER BY _id asc</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p918244104712">SELECT * FROM my-index GROUP BY range(age, 20,30,39)</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p61821494717">SELECT * FROM my-index LIMIT 50 (default is 200)</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1818224194715">SELECT * FROM my-index1 UNION SELECT * FROM my-index2</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1618212474720">SELECT * FROM my-index1 MINUS SELECT * FROM my-index2</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="css_01_0061__note1761712244817"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="css_01_0061__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__ul1772193644811"><li id="css_01_0061__li5722136154818">Conditions
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__table1788703814504" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Conditions</caption><thead align="left"><tr id="css_01_0061__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__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__p68842038185014">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p8884638195015">SELECT * FROM my-index WHERE name LIKE 'j%'</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p788463810505">SELECT * FROM my-index WHERE name LIKE 'j%' AND age &gt; 21</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p8884838175015">SELECT * FROM my-index WHERE name LIKE 'j%' OR age &gt; 21</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p78851538115013">SELECT count(distinct age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p9885123805012">SELECT * FROM my-index WHERE name IN ('alejandro', 'carolina')</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p888510387505">SELECT * FROM my-index WHERE name NOT IN ('jane')</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1988583845011">SELECT * FROM my-index WHERE age BETWEEN 20 AND 30</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p988523815501">SELECT avg(age) AS Average_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p128870384504">SELECT * FROM my-index WHERE birthday='1990-11-15'</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p20887203819506">SELECT * FROM my-index WHERE name IS NULL</p>
</td>
</tr>
</tbody>
</table>
</div>
</li><li id="css_01_0061__li16104202917515">Aggregations
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__table14777194527" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Aggregations</caption><thead align="left"><tr id="css_01_0061__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__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__p11228723105220">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p4228122315210">SELECT avg(age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p5228323165217">SELECT count(age) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1122802318526">SELECT max(age) AS Highest_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p222862345220">SELECT min(age) AS Lowest_Age FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p15228323125218">SELECT sum(age) AS Age_Sum FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<ul id="css_01_0061__ul636917462528"><li id="css_01_0061__li19369204610528">Include and exclude fields
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__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__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__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__p29451226205312">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p29451265533">SELECT include('a*'), exclude('age') FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p18945142685318">SELECT exclude('*name') FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<ul id="css_01_0061__ul12780174635316"><li id="css_01_0061__li078034617535">Functions
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__table1388491105413" frame="border" border="1" rules="all"><caption><b>Table 5 </b>Functions</caption><thead align="left"><tr id="css_01_0061__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__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__p872593605420">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p572653645411">SELECT floor(number) AS Rounded_Down FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1272619363547">SELECT trim(name) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p13726236135416">SELECT log(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p197263366547">SELECT log10(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p57262367545">SELECT substring(name, 2,5) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p87261836155412">SELECT round(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p19726336145413">SELECT sqrt(number) FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p1972611368548">SELECT concat_ws(' ', age, height) AS combined FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p372618366547">SELECT number / 100 FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p19727153655417">SELECT number % 100 FROM my-index</p>
</td>
</tr>
<tr id="css_01_0061__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__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__p3727436145418">SELECT date_format(date, 'Y') FROM my-index</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="css_01_0061__note16422449165417"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="css_01_0061__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__ul1695269155520"><li id="css_01_0061__li19952139195510">Joins
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="css_01_0061__table2631133710555" frame="border" border="1" rules="all"><caption><b>Table 6 </b>Joins</caption><thead align="left"><tr id="css_01_0061__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__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__p1416024945513">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__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__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__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__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__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__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__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__p1489516104565">For details about the constraints and limitations, see <a href="#css_01_0061__section89917481618">Joins</a>.</p>
</li></ul>
<ul id="css_01_0061__ul481615419575"><li id="css_01_0061__li19816204125713">Show<p id="css_01_0061__p138722362573"><a name="css_01_0061__li19816204125713"></a><a name="li19816204125713"></a>Show commands display indices 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__table1919121475815" frame="border" border="1" rules="all"><caption><b>Table 7 </b>Show</caption><thead align="left"><tr id="css_01_0061__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__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__p2098418342580">Example</p>
</th>
</tr>
</thead>
<tbody><tr id="css_01_0061__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__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__p8985133410588">SHOW TABLES LIKE logs-*</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
</div>
<div class="section" id="css_01_0061__section89917481618"><a name="css_01_0061__section89917481618"></a><a name="section89917481618"></a><h4 class="sectiontitle">Joins</h4><p id="css_01_0061__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__ul9814142441718"><li id="css_01_0061__li8814142481718">You can only join two indices.</li></ul>
<ul id="css_01_0061__ul28561231121711"><li id="css_01_0061__li128569311174">You must use an alias for an index (for example, people p).</li></ul>
<ul id="css_01_0061__ul8256838151713"><li id="css_01_0061__li225673851720">In an ON clause, you can only use the AND conditions.</li></ul>
<ul id="css_01_0061__ul1848794614174"><li id="css_01_0061__li14870468176">In a WHERE statement, do not combine trees that contain multiple indices. For example, the following statement will work:<pre class="screen" id="css_01_0061__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__p2551183710167">The following statement will not work:<pre class="screen" id="css_01_0061__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__ul14929185615174"><li id="css_01_0061__li292955641714">You cannot use GROUP BY or ORDER BY to obtain results.</li></ul>
<ul id="css_01_0061__ul81119714183"><li id="css_01_0061__li81119791815">LIMIT with OFFSET (for example, LIMIT 25 OFFSET 25) is not supported.</li></ul>
</div>
<div class="section" id="css_01_0061__section153416302213"><h4 class="sectiontitle">JDBC Driver</h4><p id="css_01_0061__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__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>