This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Commit 1fd40e1
committed
elastic search module fix jooby-project#90
```java
{
use(new ElasticSearch("/search"));
}
```
Elastic search will listen under the ```/search``` path. Here are some examples:
Creating a index:
```bash
curl -XPUT 'localhost:8080/search/customer?pretty'
```
Indexing a doc:
```bash
curl -XPUT 'localhost:8080/search/customer/external/1?pretty' -d '
{
"name": "John Doe"
}'
```
Getting a doc:
```bash
curl 'localhost:8080/search/customer/external/1?pretty'
```
The module exposes a ```Client``` and ```Node``` instances, so it is possible to manage the index inside programmatically.
```java
post("/:id", req -> {
// index a document
Client client = req.require(Client.class);
Map<String, Object>; json = new HashMap<>();
json.put("user", "kimchy");
json.put("message", "trying out Elasticsearch");
return client.prepareIndex("twitter", "tweet", req.param("id").value())
.setSource(json)
.execute()
.actionGet();
});
get("/:id", req -> {
// get a doc
Client client = req.require(Client.class);
return client.prepareGet("twitter", "tweet", req.param("id").value())
.execute()
.actionGet()
.getSource();
});
delete("/:id", req -> {
// delete a doc
Client client = req.require(Client.class);
return client.prepareDelete("twitter", "tweet", req.param("id").value())
.execute()
.actionGet();
});
```
If it possible to setup or configure [Elastic Search](https://github.com/elastic/elasticsearch) via ```application.conf```, just make sure to prefix the property with ```elasticsearch```:
```properties
elasticsearch.http.jsonp.enable = true
```
or programmatically:
```java
{
use(new ElasticSearch().doWith(settings -> {
settings.put(..., ...);
});
}
```
HTTP is disabled and isn't possible to change this value. What does it mean? [Jooby](http://jooby.org) setup a custom
handler which makes it possible to use a [Jooby](http://jooby.org) server to serve Elastic Search requests and avoid
the need of starting up another server running in a different port.
Most of the ```http.*``` properties has no sense in Jooby.
Path data is set to a temporary directory: ```${application.tmpdir}/es/data```. It is
useful for development, but if you need want to make sure the index is persistent between server
restarts, please make sure to setup this path to something else.
Node name is set to: ```application.name```.
Cluster name is set to: ```${application.name}-cluster```.
That's all folks! Enjoy it!!!
```properties
elasticsearch {
cluster.name: ${application.name}-cluster
node.name: ${application.name}
node.local: true
path.data: ${application.tmpdir}/es/data
path.work: ${application.tmpdir}/es/work
network.host: ${application.host}
http.detailed_errors.enabled: true
}
```1 parent 6105ce7 commit 1fd40e1
File tree
32 files changed
+2820
-41
lines changed- coverage-report
- data/elasticsearch/nodes
- 0
- 1
- 2
- src/test/java/org/jooby/elasticsearch
- jooby-elasticsearch
- src
- main
- java/org/jooby
- elasticsearch
- internal/elasticsearch
- resources/org/jooby/elasticsearch
- test/java/org/jooby
- elasticsearch
- internal/elasticsearch
- jooby-jackson
- jooby/src
- main/java/org/jooby
- internal
- test/java/org/jooby
- internal
- test
- md
- doc/elasticsearch
32 files changed
+2820
-41
lines changedWhitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments