-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7effece
commit 8dc33f2
Showing
7 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Examples | ||
|
||
1. Configured your Ray cluster address in the `RAY_ADDRESS` environment variable. | ||
2. Adapt the runtime environment in [`env.yml`](env.yml) to include your Elasticsearch host, index, and credentials. | ||
3. Launch the examples like this: | ||
|
||
```shell | ||
# Write some test data into the index. | ||
ray job submit --runtime-env examples/env.yml -- python write.py | ||
|
||
# Sum the numbers of all documents in the index. | ||
ray job submit --runtime-env examples/env.yml -- python read.py | ||
|
||
# Sum the numbers of documents in the index that match a query. | ||
ray job submit --runtime-env examples/env.yml -- python read_query.py | ||
|
||
# Sum the numbers of documents in the index that match a query (using the `elasticsearch-dsl` query DSL). | ||
ray job submit --runtime-env examples/env.yml -- python read_query_dsl.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
working_dir: examples/ | ||
pip: | ||
- elasticsearch~=8.14 | ||
- ray-elasticsearch~=0.1.0 | ||
|
||
env_vars: | ||
ELASTICSEARCH_HOST: https://example.com | ||
ELASTICSEARCH_INDEX: test | ||
ELASTICSEARCH_USERNAME: example | ||
ELASTICSEARCH_PASSWORD: example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from os import environ | ||
from ray import init | ||
from ray.data import read_datasource | ||
from ray_elasticsearch import ElasticsearchDatasource | ||
|
||
init() | ||
source = ElasticsearchDatasource( | ||
index=environ["ELASTICSEARCH_INDEX"], | ||
client_kwargs=dict( | ||
hosts=environ["ELASTICSEARCH_HOST"], | ||
http_auth=( | ||
environ["ELASTICSEARCH_USERNAME"], | ||
environ["ELASTICSEARCH_PASSWORD"], | ||
), | ||
), | ||
) | ||
print(f"Num rows: {source.num_rows()}") | ||
res = read_datasource(source)\ | ||
.map(lambda x: x["_source"])\ | ||
.sum("id") | ||
print(f"Read complete. Sum: {res}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from os import environ | ||
from ray import init | ||
from ray.data import read_datasource | ||
from ray_elasticsearch import ElasticsearchDatasource | ||
|
||
init() | ||
source = ElasticsearchDatasource( | ||
index=environ["ELASTICSEARCH_INDEX"], | ||
client_kwargs=dict( | ||
hosts=environ["ELASTICSEARCH_HOST"], | ||
http_auth=( | ||
environ["ELASTICSEARCH_USERNAME"], | ||
environ["ELASTICSEARCH_PASSWORD"], | ||
), | ||
), | ||
query={ | ||
"range": { | ||
"id": { | ||
"lte": 100, | ||
}, | ||
}, | ||
}, | ||
) | ||
print(f"Num rows: {source.num_rows()}") | ||
res = read_datasource(source)\ | ||
.map(lambda x: x["_source"])\ | ||
.sum("id") | ||
print(f"Read complete. Sum: {res}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from os import environ | ||
from elasticsearch_dsl.query import Range | ||
from ray import init | ||
from ray.data import read_datasource | ||
from ray_elasticsearch import ElasticsearchDslDatasource | ||
|
||
init() | ||
source = ElasticsearchDslDatasource( | ||
index=environ["ELASTICSEARCH_INDEX"], | ||
client_kwargs=dict( | ||
hosts=environ["ELASTICSEARCH_HOST"], | ||
http_auth=( | ||
environ["ELASTICSEARCH_USERNAME"], | ||
environ["ELASTICSEARCH_PASSWORD"], | ||
), | ||
), | ||
query=Range(id={"lte": 100}), | ||
) | ||
print(f"Num rows: {source.num_rows()}") | ||
res = read_datasource(source)\ | ||
.map(lambda x: x["_source"])\ | ||
.sum("id") | ||
print(f"Read complete. Sum: {res}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from os import environ | ||
from ray import init | ||
from ray.data import range | ||
from ray_elasticsearch import ElasticsearchDatasink | ||
|
||
init() | ||
sink = ElasticsearchDatasink( | ||
index=environ["ELASTICSEARCH_INDEX"], | ||
client_kwargs=dict( | ||
hosts=environ["ELASTICSEARCH_HOST"], | ||
http_auth=( | ||
environ["ELASTICSEARCH_USERNAME"], | ||
environ["ELASTICSEARCH_PASSWORD"], | ||
), | ||
), | ||
) | ||
|
||
range(10_000)\ | ||
.map(lambda x: {"_source": x})\ | ||
.write_datasink(sink) | ||
print("Write complete.") |