Skip to content

Commit 943eebc

Browse files
committed
Refactor index-basics.md to use snippet includes
- Extract code examples into _snippets/index-basics/ directory - Replace inline code blocks with include directives - Generate snippet files
1 parent 75ccb18 commit 943eebc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1555
-1395
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```console
2+
PUT /books
3+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```bash
2+
curl -X PUT "$ELASTICSEARCH_URL/books" \
3+
-H "Authorization: ApiKey $ELASTIC_API_KEY"
4+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```js
2+
const { Client } = require("@elastic/elasticsearch");
3+
4+
const client = new Client({
5+
nodes: [process.env["ELASTICSEARCH_URL"]],
6+
auth: {
7+
apiKey: process.env["ELASTIC_API_KEY"],
8+
},
9+
});
10+
11+
async function run() {
12+
const response = await client.indices.create({
13+
index: "books",
14+
});
15+
console.log(response);
16+
}
17+
18+
run();
19+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
```php
2+
<?php
3+
4+
require(__DIR__ . "/vendor/autoload.php");
5+
6+
use Elastic\Elasticsearch\ClientBuilder;
7+
8+
$client = ClientBuilder::create()
9+
->setHosts([getenv("ELASTICSEARCH_URL")])
10+
->setApiKey(getenv("ELASTIC_API_KEY"))
11+
->build();
12+
13+
$resp = $client->indices()->create([
14+
"index" => "books",
15+
]);
16+
echo $resp->asString();
17+
18+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```python
2+
import os
3+
from elasticsearch import Elasticsearch
4+
5+
client = Elasticsearch(
6+
hosts=[os.getenv("ELASTICSEARCH_URL")],
7+
api_key=os.getenv("ELASTIC_API_KEY"),
8+
)
9+
10+
resp = client.indices.create(
11+
index="books",
12+
)
13+
print(resp)
14+
15+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```ruby
2+
require "elasticsearch"
3+
4+
client = Elasticsearch::Client.new(
5+
host: ENV["ELASTICSEARCH_URL"],
6+
api_key: ENV["ELASTIC_API_KEY"]
7+
)
8+
9+
response = client.indices.create(
10+
index: "books"
11+
)
12+
print(resp)
13+
14+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```console
2+
POST books/_doc
3+
{
4+
"name": "Snow Crash",
5+
"author": "Neal Stephenson",
6+
"release_date": "1992-06-01",
7+
"page_count": 470
8+
}
9+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```bash
2+
curl -X POST "$ELASTICSEARCH_URL/books/_doc" \
3+
-H "Authorization: ApiKey $ELASTIC_API_KEY" \
4+
-H "Content-Type: application/json" \
5+
-d '{"name":"Snow Crash","author":"Neal Stephenson","release_date":"1992-06-01","page_count":470}'
6+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```js
2+
const response = await client.index({
3+
index: "books",
4+
document: {
5+
name: "Snow Crash",
6+
author: "Neal Stephenson",
7+
release_date: "1992-06-01",
8+
page_count: 470,
9+
},
10+
});
11+
console.log(response);
12+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
```php
2+
$resp = $client->index([
3+
"index" => "books",
4+
"body" => [
5+
"name" => "Snow Crash",
6+
"author" => "Neal Stephenson",
7+
"release_date" => "1992-06-01",
8+
"page_count" => 470,
9+
],
10+
]);
11+
echo $resp->asString();
12+
13+
```

0 commit comments

Comments
 (0)