Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to reference #1076

Merged
merged 14 commits into from
Feb 3, 2020
8 changes: 8 additions & 0 deletions docs/examples/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Following you can find some examples on how to use the client.
* Executing a <<bulk_examples,bulk>> request;
* Executing a <<exists_examples,exists>> request;
* Executing a <<get_examples,get>> request;
* Executing a <<sql_query_examples,sql.query>> request;
* Executing a <<update_examples,update>> request;
* Executing a <<update_by_query_examples,update by query>> request;
* Executing a <<reindex_examples,reindex>> request;
* Use of the <<ignore_examples,ignore>> parameter;
* Executing a <<msearch_examples,msearch>> request;
* How do I <<scroll_examples,scroll>>?
Expand All @@ -26,3 +30,7 @@ include::search.asciidoc[]
include::suggest.asciidoc[]
include::transport.request.asciidoc[]
include::typescript.asciidoc[]
include::sql.query.asciidoc[]
include::update.asciidoc[]
include::update_by_query.asciidoc[]
include::reindex.asciidoc[]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[sql_examples]]
[[sql_query_examples]]
== SQL

Elasticsearch SQL is an X-Pack component that allows SQL-like queries to be executed in real-time against Elasticsearch. Whether using the REST interface, command-line or JDBC, any client can use SQL to search and aggregate data natively inside Elasticsearch. One can think of Elasticsearch SQL as a translator, one that understands both SQL and Elasticsearch and makes it easy to read and process data in real-time, at scale by leveraging Elasticsearch capabilities.

In the following example we will search all the documents that has the field `house` equals to `stark`, log the result with the tabular view and then manipulate the result to obtain an object easy to navigate.
In the following example we will search all the documents that has the field `house` equals to `stark`, log the result with the tabular view and then manipulate the result to obtain an object easy to navigate.

[source,js]
----
Expand Down
10 changes: 10 additions & 0 deletions docs/reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ client.bulk({
})
----
link:{ref}/docs-bulk.html[Reference]
{jsclient}/bulk_examples.html[Example]
[cols=2*]
|===
|`index`
Expand Down Expand Up @@ -1750,6 +1751,7 @@ client.exists({
})
----
link:{ref}/docs-get.html[Reference]
{jsclient}/exists_examples.html[Example]
[cols=2*]
|===
|`id`
Expand Down Expand Up @@ -1982,6 +1984,7 @@ client.get({
})
----
link:{ref}/docs-get.html[Reference]
{jsclient}/get_examples.html[Example]
[cols=2*]
|===
|`id`
Expand Down Expand Up @@ -3745,6 +3748,7 @@ client.msearch({
})
----
link:{ref}/search-multi-search.html[Reference]
{jsclient}/msearch_examples.html[Example]
[cols=2*]
|===
|`index`
Expand Down Expand Up @@ -4156,6 +4160,7 @@ client.reindex({
})
----
link:{ref}/docs-reindex.html[Reference]
{jsclient}/reindex_examples.html[Example]
[cols=2*]
|===
|`refresh`
Expand Down Expand Up @@ -4259,6 +4264,7 @@ client.scroll({
})
----
link:{ref}/search-request-body.html#request-body-search-scroll[Reference]
{jsclient}/scroll_examples.html[Example]
[cols=2*]
|===
|`scroll_id` or `scrollId`
Expand Down Expand Up @@ -4329,6 +4335,7 @@ client.search({
})
----
link:{ref}/search-search.html[Reference]
{jsclient}/search_examples.html[Example]
[cols=2*]
|===
|`index`
Expand Down Expand Up @@ -5056,6 +5063,7 @@ client.update({
})
----
link:{ref}/docs-update.html[Reference]
{jsclient}/update_examples.html[Example]
[cols=2*]
|===
|`id`
Expand Down Expand Up @@ -5151,6 +5159,7 @@ client.updateByQuery({
})
----
link:{ref}/docs-update-by-query.html[Reference]
{jsclient}/update_by_query_examples.html[Example]
[cols=2*]
|===
|`index`
Expand Down Expand Up @@ -8575,6 +8584,7 @@ client.sql.query({
})
----
link:Execute SQL[Reference]
{jsclient}/sql.query_examples.html[Example]
delvedor marked this conversation as resolved.
Show resolved Hide resolved
[cols=2*]
|===
|`format`
Expand Down
9 changes: 9 additions & 0 deletions scripts/utils/generateDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

'use strict'

const { readdirSync } = require('fs')
const { join } = require('path')
const dedent = require('dedent')

const codeExamples = readdirSync(join(__dirname, '..', '..', 'docs', 'examples'))
.map(file => file.slice(0, -9))
.filter(api => api !== 'index')

function generateDocs (common, spec) {
var doc = dedent`
[[api-reference]]
Expand Down Expand Up @@ -198,6 +204,9 @@ function generateApiDoc (spec) {
if (documentationUrl) {
doc += `link:${documentationUrl}[Reference]\n`
}
if (codeExamples.includes(name)) {
doc += `{jsclient}/${name}_examples.html[Example]\n`
}

if (params.length !== 0) {
doc += dedent`[cols=2*]
Expand Down