Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```console
PUT /books
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```bash
curl -X PUT "$ELASTICSEARCH_URL/books" \
-H "Authorization: ApiKey $ELASTIC_API_KEY"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```js
const { Client } = require("@elastic/elasticsearch");

const client = new Client({
nodes: [process.env["ELASTICSEARCH_URL"]],
auth: {
apiKey: process.env["ELASTIC_API_KEY"],
},
});

async function run() {
const response = await client.indices.create({
index: "books",
});
console.log(response);
}

run();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```php
<?php

require(__DIR__ . "/vendor/autoload.php");

use Elastic\Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()
->setHosts([getenv("ELASTICSEARCH_URL")])
->setApiKey(getenv("ELASTIC_API_KEY"))
->build();

$resp = $client->indices()->create([
"index" => "books",
]);
echo $resp->asString();

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```python
import os
from elasticsearch import Elasticsearch

client = Elasticsearch(
hosts=[os.getenv("ELASTICSEARCH_URL")],
api_key=os.getenv("ELASTIC_API_KEY"),
)

resp = client.indices.create(
index="books",
)
print(resp)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```ruby
require "elasticsearch"

client = Elasticsearch::Client.new(
host: ENV["ELASTICSEARCH_URL"],
api_key: ENV["ELASTIC_API_KEY"]
)

response = client.indices.create(
index: "books"
)
print(resp)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```console
POST books/_doc
{
"name": "Snow Crash",
"author": "Neal Stephenson",
"release_date": "1992-06-01",
"page_count": 470
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```bash
curl -X POST "$ELASTICSEARCH_URL/books/_doc" \
-H "Authorization: ApiKey $ELASTIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"Snow Crash","author":"Neal Stephenson","release_date":"1992-06-01","page_count":470}'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```js
const response = await client.index({
index: "books",
document: {
name: "Snow Crash",
author: "Neal Stephenson",
release_date: "1992-06-01",
page_count: 470,
},
});
console.log(response);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```php
$resp = $client->index([
"index" => "books",
"body" => [
"name" => "Snow Crash",
"author" => "Neal Stephenson",
"release_date" => "1992-06-01",
"page_count" => 470,
],
]);
echo $resp->asString();

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```python
resp = client.index(
index="books",
document={
"name": "Snow Crash",
"author": "Neal Stephenson",
"release_date": "1992-06-01",
"page_count": 470
},
)
print(resp)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```ruby
response = client.index(
index: "books",
body: {
"name": "Snow Crash",
"author": "Neal Stephenson",
"release_date": "1992-06-01",
"page_count": 470
}
)
print(resp)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```console
POST /_bulk
{ "index" : { "_index" : "books" } }
{"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
{ "index" : { "_index" : "books" } }
{"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
{ "index" : { "_index" : "books" } }
{"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
{ "index" : { "_index" : "books" } }
{"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
{ "index" : { "_index" : "books" } }
{"name": "The Handmaids Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```bash
curl -X POST "$ELASTICSEARCH_URL/_bulk" \
-H "Authorization: ApiKey $ELASTIC_API_KEY" \
-H "Content-Type: application/x-ndjson" \
-d $'{"index":{"_index":"books"}}\n{"name":"Revelation Space","author":"Alastair Reynolds","release_date":"2000-03-15","page_count":585}\n{"index":{"_index":"books"}}\n{"name":"1984","author":"George Orwell","release_date":"1985-06-01","page_count":328}\n{"index":{"_index":"books"}}\n{"name":"Fahrenheit 451","author":"Ray Bradbury","release_date":"1953-10-15","page_count":227}\n{"index":{"_index":"books"}}\n{"name":"Brave New World","author":"Aldous Huxley","release_date":"1932-06-01","page_count":268}\n{"index":{"_index":"books"}}\n{"name":"The Handmaids Tale","author":"Margaret Atwood","release_date":"1985-06-01","page_count":311}\n'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
```js
const response = await client.bulk({
operations: [
{
index: {
_index: "books",
},
},
{
name: "Revelation Space",
author: "Alastair Reynolds",
release_date: "2000-03-15",
page_count: 585,
},
{
index: {
_index: "books",
},
},
{
name: "1984",
author: "George Orwell",
release_date: "1985-06-01",
page_count: 328,
},
{
index: {
_index: "books",
},
},
{
name: "Fahrenheit 451",
author: "Ray Bradbury",
release_date: "1953-10-15",
page_count: 227,
},
{
index: {
_index: "books",
},
},
{
name: "Brave New World",
author: "Aldous Huxley",
release_date: "1932-06-01",
page_count: 268,
},
{
index: {
_index: "books",
},
},
{
name: "The Handmaids Tale",
author: "Margaret Atwood",
release_date: "1985-06-01",
page_count: 311,
},
],
});
console.log(response);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
```php
$resp = $client->bulk([
"body" => array(
[
"index" => [
"_index" => "books",
],
],
[
"name" => "Revelation Space",
"author" => "Alastair Reynolds",
"release_date" => "2000-03-15",
"page_count" => 585,
],
[
"index" => [
"_index" => "books",
],
],
[
"name" => "1984",
"author" => "George Orwell",
"release_date" => "1985-06-01",
"page_count" => 328,
],
[
"index" => [
"_index" => "books",
],
],
[
"name" => "Fahrenheit 451",
"author" => "Ray Bradbury",
"release_date" => "1953-10-15",
"page_count" => 227,
],
[
"index" => [
"_index" => "books",
],
],
[
"name" => "Brave New World",
"author" => "Aldous Huxley",
"release_date" => "1932-06-01",
"page_count" => 268,
],
[
"index" => [
"_index" => "books",
],
],
[
"name" => "The Handmaids Tale",
"author" => "Margaret Atwood",
"release_date" => "1985-06-01",
"page_count" => 311,
],
),
]);
echo $resp->asString();

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
```python
resp = client.bulk(
operations=[
{
"index": {
"_index": "books"
}
},
{
"name": "Revelation Space",
"author": "Alastair Reynolds",
"release_date": "2000-03-15",
"page_count": 585
},
{
"index": {
"_index": "books"
}
},
{
"name": "1984",
"author": "George Orwell",
"release_date": "1985-06-01",
"page_count": 328
},
{
"index": {
"_index": "books"
}
},
{
"name": "Fahrenheit 451",
"author": "Ray Bradbury",
"release_date": "1953-10-15",
"page_count": 227
},
{
"index": {
"_index": "books"
}
},
{
"name": "Brave New World",
"author": "Aldous Huxley",
"release_date": "1932-06-01",
"page_count": 268
},
{
"index": {
"_index": "books"
}
},
{
"name": "The Handmaids Tale",
"author": "Margaret Atwood",
"release_date": "1985-06-01",
"page_count": 311
}
],
)
print(resp)

```
Loading
Loading