Skip to content

Commit 2844ed4

Browse files
authored
Update README.md
1 parent a36f1e5 commit 2844ed4

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
# elasticsearch-laravel
1+
## Introduction
2+
This is a simple package that is used to integrate the Elasticsearch API with a Laravel project.
3+
The package is based on the Client class, which is not a builder.
4+
The package is still in development.
5+
6+
## Installation
7+
8+
Install using composer
9+
10+
```bash
11+
composer require ...
12+
```
13+
14+
Set Elasticsearch base URL in `.env` file
15+
16+
```txt
17+
ELASTICSEARCH_URL=http://localhost:9200
18+
```
19+
20+
21+
## Client class reference
22+
23+
```php
24+
public function search(string $index, array $data): SearchResponseDto;
25+
26+
public function find(string $index, string|int $id): ?FindResponseDto;
27+
28+
public function findOrFail(string $index, string|int $id): FindResponseDto;
29+
30+
public function create(string $index, string|int $id, array $data): IndexResponseDto;
31+
32+
public function update(string $index, string|int $id, array $data): IndexResponseDto;
33+
34+
public function delete(string $index, string|int $id): IndexResponseDto;
35+
36+
public function searchWhereIn(string $index, string $field, array $values): SearchResponseDto;
37+
38+
public function searchWhereKeyword(string $index, string $field, string $value): SearchResponseDto;
39+
40+
public function searchWhereLike(string $index, string $field, string|int|float $value): SearchResponseDto;
41+
42+
public function increment(string $index, string|int $id, string $field, int $value = 1): IndexResponseDto;
43+
44+
public function decrement(string $index, string|int $id, string $field, int $value = 1): IndexResponseDto;
45+
```
46+
47+
### Examples
48+
1. Index the new document
49+
```php
50+
use Olekjs\Elasticsearch\Client;
51+
52+
...
53+
54+
$client = new Client();
55+
$client->create(
56+
index: 'logs',
57+
id: 1,
58+
data: ['level' => 'error', 'message' => 'Error...', ...]
59+
);
60+
```
61+
62+
2. Find the document
63+
```php
64+
use Olekjs\Elasticsearch\Client;
65+
66+
...
67+
68+
$client = new Client();
69+
70+
// If document doesn't exists null will be returned
71+
$client->find(
72+
index: 'logs',
73+
id: 1
74+
);
75+
76+
// If document doesn't exists NotFoundResponseException will be thrown
77+
$client->findOrFail(
78+
index: 'logs',
79+
id: 2
80+
);
81+
82+
```

0 commit comments

Comments
 (0)