Name | esrt JSON |
Version |
4.15.0
JSON |
| download |
home_page | None |
Summary | None |
upload_time | 2025-03-18 19:37:26 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# esrt - Elasticsearch Request Tool
[](https://pypi.python.org/pypi/esrt)
```sh
# use `pipx`
pip install pipx # install pipx
alias esrt='pipx run esrt==4.6.0'
esrt -V
```
```sh
# or use `uv`
pip install uv # install uv
alias esrt='uvx esrt@4.6.0'
esrt -V
```
## Commands
- `search`
- `scan`
- `request`
- `bulk`
<!-- - `sql` -->
- `ping`
---
## Example
You can start an es service with docker.
```sh
docker run --name "esrt-es" --rm -itd --platform=linux/amd64 -p 9200:9200 elasticsearch:5.6.9-alpine
# install sql command and restart container:
docker exec "esrt-es" elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/5.6.9.0/elasticsearch-sql-5.6.9.0.zip
docker restart "esrt-es"
```
---
## `request`
Check server:
```sh
esrt request localhost -X HEAD
# ->
# true
```
Create a index:
```sh
esrt request localhost -X PUT -u /my-index
# ->
# {
# "acknowledged": true,
# "shards_acknowledged": true,
# "index": "my-index"
# }
```
*If you want to `esrt` quote url path for you, add flag: `-Q`(`--quote-url`)*
Cat it:
```sh
esrt request localhost -X GET -u _cat/indices
# ->
# yellow open my-index NMHssX4qTgeMFrA3cXPoKg 5 1 0 0 324b 324b
esrt request localhost -X GET -u _cat/indices -p v=
# ->
# health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
# yellow open my-index NMHssX4qTgeMFrA3cXPoKg 5 1 0 0 810b 810b
esrt request localhost -X GET -u _cat/indices -p v= -p format=json
# ->
# [
# {
# "health": "yellow",
# "status": "open",
# "index": "my-index",
# "uuid": "NMHssX4qTgeMFrA3cXPoKg",
# "pri": "5",
# "rep": "1",
# "docs.count": "0",
# "docs.deleted": "0",
# "store.size": "810b",
# "pri.store.size": "810b"
# }
# ]
```
---
## `bulk` - Transmit data (`streaming_bulk`)
Bulk with data from file `examples/bulk.ndjson`:
```json
{ "_op_type": "index", "_index": "my-index", "_type": "type1", "_id": "1", "field1": "ii" }
{ "_op_type": "delete", "_index": "my-index", "_type": "type1", "_id": "1" }
{ "_op_type": "create", "_index": "my-index", "_type": "type1", "_id": "1", "field1": "cc" }
{ "_op_type": "update", "_index": "my-index", "_type": "type1", "_id": "1", "doc": {"field2": "uu"} }
```
```sh
esrt bulk localhost -y -f examples/bulk.ndjson
# ->
# ⠋ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:00 4/? ?
```
---
Read payload from `stdin`. And `-d` can be omitted.
```sh
esrt bulk localhost -y <<EOF
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "1", "field1": "11" }
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "2", "field1": "22" }
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "3", "field1": "33" }
EOF
# ->
# ⠋ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:00 3/? ?
```
Piping `heredoc` also works.
```sh
cat <<EOF | esrt bulk localhost -y
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "1", "field1": "11" }
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "2", "field1": "22" }
{ "_op_type": "index", "_index": "my-index-2", "_type": "type1", "_id": "3", "field1": "33" }
EOF
# ->
# ⠋ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:00 3/? ?
```
---
Pipe `_search` result and update `_index` with `customized handler` to do more operations before bulk!
```sh
alias jq_es_hits="jq '.hits.hits[]'"
```
```sh
esrt request localhost -X GET -u my-index-2/_search | jq_es_hits -c | esrt bulk localhost -y -w examples.my-handlers:handle # <- `examples/my-handlers.py`
# ->
# ⠹ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:00 3/? ?
```
```py
# examples/my-handlers.py
import json
import typing as t
from esrt import DocHandler
# function style
def my_handler(actions: t.Iterable[str]):
for action in actions:
obj = json.loads(action)
prefix = 'new-'
if not t.cast(str, obj['_index']).startswith(prefix):
obj['_index'] = prefix + obj['_index']
yield obj
# class style
class MyHandler(DocHandler):
def handle(self, actions: t.Iterable[str]):
for action in actions:
yield self.handle_one(action)
def handle_one(self, action: str):
obj = super().handle_one(action)
prefix = 'new-'
if not t.cast(str, obj['_index']).startswith(prefix):
obj['_index'] = prefix + obj['_index']
return obj
```
---
## `search`
```sh
esrt search localhost | jq_es_hits -c
# ->
# {"_index":"my-index-2","_type":"type1","_id":"2","_score":1.0,"_source":{"field1":"22"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"2","_score":1.0,"_source":{"field1":"22"}}
# {"_index":"my-index","_type":"type1","_id":"1","_score":1.0,"_source":{"field1":"cc","field2":"uu"}}
# {"_index":"my-index-2","_type":"type1","_id":"1","_score":1.0,"_source":{"field1":"11"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"1","_score":1.0,"_source":{"field1":"11"}}
# {"_index":"my-index-2","_type":"type1","_id":"3","_score":1.0,"_source":{"field1":"33"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"3","_score":1.0,"_source":{"field1":"33"}}
```
```sh
esrt search localhost -f - <<EOF | jq_es_hits -c
{"query": {"term": {"_index": "new-my-index-2"}}}
EOF
# ->
# {"_index":"new-my-index-2","_type":"type1","_id":"2","_score":1.0,"_source":{"field1":"22"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"1","_score":1.0,"_source":{"field1":"11"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"3","_score":1.0,"_source":{"field1":"33"}}
```
## `scan`
```sh
esrt scan localhost -y
# ->
# {"_index": "my-index-2", "_type": "type1", "_id": "2", "_score": null, "_source": {"field1": "22"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "2", "_score": null, "_source": {"field1": "22"}, "sort": [0]}
# {"_index": "my-index", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "cc", "field2": "uu"}, "sort": [0]}
# {"_index": "my-index-2", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "11"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "11"}, "sort": [0]}
# {"_index": "my-index-2", "_type": "type1", "_id": "3", "_score": null, "_source": {"field1": "33"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "3", "_score": null, "_source": {"field1": "33"}, "sort": [0]}
```
```sh
esrt scan localhost -y -f - <<EOF
{"query": {"term": {"field1": "cc"}}}
EOF
# ->
# {"_index": "my-index", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "cc", "field2": "uu"}, "sort": [0]}
```
<!--
## `sql` - Elasticsearch SQL
```sh
# Elasticsearch v6
export ESRT_SQL_API=_xpack/sql
```
```sh
esrt sql localhost -f - <<EOF | jq_es_hits -c
SELECT * from new-my-index-2
EOF
# ->
# {"_index":"new-my-index-2","_type":"type1","_id":"2","_score":1.0,"_source":{"field1":"22"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"1","_score":1.0,"_source":{"field1":"11"}}
# {"_index":"new-my-index-2","_type":"type1","_id":"3","_score":1.0,"_source":{"field1":"33"}}
```
-->
---
## Other Examples
```py
# examples/create-massive-docs.py
import json
import uuid
if __name__ == '__main__':
for i, _ in enumerate(range(54321), start=1):
d = {
'_index': 'my-index-a',
'_id': i,
'_type': 'type1',
'_source': {'field1': str(uuid.uuid4())},
}
print(json.dumps(d))
```
```sh
python examples/create-massive-docs.py | tee _.ndjson | esrt bulk localhost -y -c 10000
# ->
# ⠋ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:26 654321/? 24504/s
cat _.ndjson # <- 79M
head _.ndjson
# ->
# {"_index": "my-index-a", "_type": "type1", "_id": "70004", "_score": null, "_source": {"field1": "7fc553c1-d09f-4793-bc28-2a16a6050ef4"}, "sort": [0]}
# {"_index": "my-index-a", "_type": "type1", "_id": "80002", "_score": null, "_source": {"field1": "7fddf2f7-195f-4964-81f1-bb32d63be8b0"}, "sort": [0]}
# {"_index": "my-index-2", "_type": "type1", "_id": "2", "_score": null, "_source": {"field1": "22"}, "sort": [0]}
# {"_index": "my-index-a", "_type": "type1", "_id": "70003", "_score": null, "_source": {"field1": "2a08f0e0-cdbd-47d3-b7e3-ee8fd1e27ff8"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "2", "_score": null, "_source": {"field1": "22"}, "sort": [0]}
# {"_index": "my-index", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "cc", "field2": "uu"}, "sort": [0]}
# {"_index": "my-index-2", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "11"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "1", "_score": null, "_source": {"field1": "11"}, "sort": [0]}
# {"_index": "my-index-2", "_type": "type1", "_id": "3", "_score": null, "_source": {"field1": "33"}, "sort": [0]}
# {"_index": "new-my-index-2", "_type": "type1", "_id": "3", "_score": null, "_source": {"field1": "33"}, "sort": [0]}
```
---
```py
# examples/copy-more-docs.py
from copy import deepcopy
import json
import typing as t
import uuid
if __name__ == '__main__':
for i, _ in enumerate(range(54321), start=1):
d = {
'_index': 'my-index-b',
'_id': i,
'_type': 'type1',
'_source': {'field1': str(uuid.uuid4())},
}
print(json.dumps(d))
def handle(actions: t.Iterable[str]):
for action in actions:
d: dict[str, t.Any] = json.loads(action)
yield d
d2 = deepcopy(d)
d2['_source']['field1'] += '!!!'
d2['_source']['field2'] = str(uuid.uuid4())
yield d2
```
```sh
python examples/copy-more-docs.py | esrt bulk localhost -y -w examples.copy-more-docs:handle
# ->
# ⠏ bulk ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:00:05 108642/? 18963/s
```
Raw data
{
"_id": null,
"home_page": null,
"name": "esrt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/08/ff/06d0a4e548e0827f27a1149a58970ee85c1089106842ea634724c764e9ff/esrt-4.15.0.tar.gz",
"platform": null,
"description": "# esrt - Elasticsearch Request Tool\n\n[](https://pypi.python.org/pypi/esrt)\n\n```sh\n# use `pipx`\npip install pipx # install pipx\nalias esrt='pipx run esrt==4.6.0'\nesrt -V\n```\n\n```sh\n# or use `uv`\npip install uv # install uv\nalias esrt='uvx esrt@4.6.0'\nesrt -V\n```\n\n## Commands\n\n- `search`\n- `scan`\n- `request`\n- `bulk`\n<!-- - `sql` -->\n- `ping`\n\n---\n\n## Example\n\nYou can start an es service with docker.\n\n```sh\ndocker run --name \"esrt-es\" --rm -itd --platform=linux/amd64 -p 9200:9200 elasticsearch:5.6.9-alpine\n\n# install sql command and restart container:\ndocker exec \"esrt-es\" elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/5.6.9.0/elasticsearch-sql-5.6.9.0.zip\ndocker restart \"esrt-es\"\n```\n\n---\n\n## `request`\n\nCheck server:\n\n```sh\nesrt request localhost -X HEAD\n# ->\n# true\n```\n\nCreate a index:\n\n```sh\nesrt request localhost -X PUT -u /my-index\n# ->\n# {\n# \"acknowledged\": true,\n# \"shards_acknowledged\": true,\n# \"index\": \"my-index\"\n# }\n```\n\n*If you want to `esrt` quote url path for you, add flag: `-Q`(`--quote-url`)*\n\nCat it:\n\n```sh\nesrt request localhost -X GET -u _cat/indices\n# ->\n# yellow open my-index NMHssX4qTgeMFrA3cXPoKg 5 1 0 0 324b 324b\n\nesrt request localhost -X GET -u _cat/indices -p v=\n# ->\n# health status index uuid pri rep docs.count docs.deleted store.size pri.store.size\n# yellow open my-index NMHssX4qTgeMFrA3cXPoKg 5 1 0 0 810b 810b\n\nesrt request localhost -X GET -u _cat/indices -p v= -p format=json\n# ->\n# [\n# {\n# \"health\": \"yellow\",\n# \"status\": \"open\",\n# \"index\": \"my-index\",\n# \"uuid\": \"NMHssX4qTgeMFrA3cXPoKg\",\n# \"pri\": \"5\",\n# \"rep\": \"1\",\n# \"docs.count\": \"0\",\n# \"docs.deleted\": \"0\",\n# \"store.size\": \"810b\",\n# \"pri.store.size\": \"810b\"\n# }\n# ]\n```\n\n---\n\n## `bulk` - Transmit data (`streaming_bulk`)\n\nBulk with data from file `examples/bulk.ndjson`:\n\n```json\n{ \"_op_type\": \"index\", \"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"field1\": \"ii\" }\n{ \"_op_type\": \"delete\", \"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\" }\n{ \"_op_type\": \"create\", \"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"field1\": \"cc\" }\n{ \"_op_type\": \"update\", \"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"doc\": {\"field2\": \"uu\"} }\n```\n\n```sh\nesrt bulk localhost -y -f examples/bulk.ndjson\n# ->\n# \u280b bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:00 4/? ?\n```\n\n---\n\nRead payload from `stdin`. And `-d` can be omitted.\n\n```sh\nesrt bulk localhost -y <<EOF\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"field1\": \"11\" }\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"field1\": \"22\" }\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"field1\": \"33\" }\nEOF\n# ->\n# \u280b bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:00 3/? ?\n```\n\nPiping `heredoc` also works.\n\n```sh\ncat <<EOF | esrt bulk localhost -y\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"field1\": \"11\" }\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"field1\": \"22\" }\n{ \"_op_type\": \"index\", \"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"field1\": \"33\" }\nEOF\n# ->\n# \u280b bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:00 3/? ?\n```\n\n---\n\nPipe `_search` result and update `_index` with `customized handler` to do more operations before bulk!\n\n```sh\nalias jq_es_hits=\"jq '.hits.hits[]'\"\n```\n\n```sh\nesrt request localhost -X GET -u my-index-2/_search | jq_es_hits -c | esrt bulk localhost -y -w examples.my-handlers:handle # <- `examples/my-handlers.py`\n# ->\n# \u2839 bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:00 3/? ?\n```\n\n```py\n# examples/my-handlers.py\nimport json\nimport typing as t\n\nfrom esrt import DocHandler\n\n\n# function style\ndef my_handler(actions: t.Iterable[str]):\n for action in actions:\n obj = json.loads(action)\n prefix = 'new-'\n if not t.cast(str, obj['_index']).startswith(prefix):\n obj['_index'] = prefix + obj['_index']\n yield obj\n\n\n# class style\nclass MyHandler(DocHandler):\n def handle(self, actions: t.Iterable[str]):\n for action in actions:\n yield self.handle_one(action)\n\n def handle_one(self, action: str):\n obj = super().handle_one(action)\n prefix = 'new-'\n if not t.cast(str, obj['_index']).startswith(prefix):\n obj['_index'] = prefix + obj['_index']\n return obj\n\n```\n\n---\n\n## `search`\n\n```sh\nesrt search localhost | jq_es_hits -c\n# ->\n# {\"_index\":\"my-index-2\",\"_type\":\"type1\",\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"field1\":\"22\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"field1\":\"22\"}}\n# {\"_index\":\"my-index\",\"_type\":\"type1\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"field1\":\"cc\",\"field2\":\"uu\"}}\n# {\"_index\":\"my-index-2\",\"_type\":\"type1\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"field1\":\"11\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"field1\":\"11\"}}\n# {\"_index\":\"my-index-2\",\"_type\":\"type1\",\"_id\":\"3\",\"_score\":1.0,\"_source\":{\"field1\":\"33\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"3\",\"_score\":1.0,\"_source\":{\"field1\":\"33\"}}\n```\n\n```sh\nesrt search localhost -f - <<EOF | jq_es_hits -c\n{\"query\": {\"term\": {\"_index\": \"new-my-index-2\"}}}\nEOF\n# ->\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"field1\":\"22\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"field1\":\"11\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"3\",\"_score\":1.0,\"_source\":{\"field1\":\"33\"}}\n```\n\n## `scan`\n\n```sh\nesrt scan localhost -y\n# ->\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"_score\": null, \"_source\": {\"field1\": \"22\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"_score\": null, \"_source\": {\"field1\": \"22\"}, \"sort\": [0]}\n# {\"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"cc\", \"field2\": \"uu\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"11\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"11\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"_score\": null, \"_source\": {\"field1\": \"33\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"_score\": null, \"_source\": {\"field1\": \"33\"}, \"sort\": [0]}\n\n```\n\n```sh\nesrt scan localhost -y -f - <<EOF\n{\"query\": {\"term\": {\"field1\": \"cc\"}}}\nEOF\n# ->\n# {\"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"cc\", \"field2\": \"uu\"}, \"sort\": [0]}\n\n```\n\n<!--\n## `sql` - Elasticsearch SQL\n\n```sh\n# Elasticsearch v6\nexport ESRT_SQL_API=_xpack/sql\n```\n\n```sh\nesrt sql localhost -f - <<EOF | jq_es_hits -c\nSELECT * from new-my-index-2\nEOF\n# ->\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"field1\":\"22\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"field1\":\"11\"}}\n# {\"_index\":\"new-my-index-2\",\"_type\":\"type1\",\"_id\":\"3\",\"_score\":1.0,\"_source\":{\"field1\":\"33\"}}\n```\n-->\n\n---\n\n## Other Examples\n\n```py\n# examples/create-massive-docs.py\nimport json\nimport uuid\n\n\nif __name__ == '__main__':\n for i, _ in enumerate(range(54321), start=1):\n d = {\n '_index': 'my-index-a',\n '_id': i,\n '_type': 'type1',\n '_source': {'field1': str(uuid.uuid4())},\n }\n print(json.dumps(d))\n```\n\n```sh\npython examples/create-massive-docs.py | tee _.ndjson | esrt bulk localhost -y -c 10000\n# ->\n# \u280b bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:26 654321/? 24504/s\n\ncat _.ndjson # <- 79M\n\nhead _.ndjson\n# ->\n# {\"_index\": \"my-index-a\", \"_type\": \"type1\", \"_id\": \"70004\", \"_score\": null, \"_source\": {\"field1\": \"7fc553c1-d09f-4793-bc28-2a16a6050ef4\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-a\", \"_type\": \"type1\", \"_id\": \"80002\", \"_score\": null, \"_source\": {\"field1\": \"7fddf2f7-195f-4964-81f1-bb32d63be8b0\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"_score\": null, \"_source\": {\"field1\": \"22\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-a\", \"_type\": \"type1\", \"_id\": \"70003\", \"_score\": null, \"_source\": {\"field1\": \"2a08f0e0-cdbd-47d3-b7e3-ee8fd1e27ff8\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"2\", \"_score\": null, \"_source\": {\"field1\": \"22\"}, \"sort\": [0]}\n# {\"_index\": \"my-index\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"cc\", \"field2\": \"uu\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"11\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"1\", \"_score\": null, \"_source\": {\"field1\": \"11\"}, \"sort\": [0]}\n# {\"_index\": \"my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"_score\": null, \"_source\": {\"field1\": \"33\"}, \"sort\": [0]}\n# {\"_index\": \"new-my-index-2\", \"_type\": \"type1\", \"_id\": \"3\", \"_score\": null, \"_source\": {\"field1\": \"33\"}, \"sort\": [0]}\n\n```\n\n---\n\n```py\n# examples/copy-more-docs.py\nfrom copy import deepcopy\nimport json\nimport typing as t\nimport uuid\n\n\nif __name__ == '__main__':\n for i, _ in enumerate(range(54321), start=1):\n d = {\n '_index': 'my-index-b',\n '_id': i,\n '_type': 'type1',\n '_source': {'field1': str(uuid.uuid4())},\n }\n print(json.dumps(d))\n\n\ndef handle(actions: t.Iterable[str]):\n for action in actions:\n d: dict[str, t.Any] = json.loads(action)\n yield d\n d2 = deepcopy(d)\n d2['_source']['field1'] += '!!!'\n d2['_source']['field2'] = str(uuid.uuid4())\n yield d2\n```\n\n```sh\npython examples/copy-more-docs.py | esrt bulk localhost -y -w examples.copy-more-docs:handle\n# ->\n# \u280f bulk \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 0:00:05 108642/? 18963/s\n```\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "4.15.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "32b87345b40a65d19b542697374c16f614092bf1e424b7d00f3f117e93d88909",
"md5": "8ceea8f3a48093a9d19efad0565052ce",
"sha256": "f8fc92d3d1514f7a2adbb2933ba944160c834e25031f98fa5a47ea43e1324b25"
},
"downloads": -1,
"filename": "esrt-4.15.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ceea8f3a48093a9d19efad0565052ce",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16991,
"upload_time": "2025-03-18T19:37:25",
"upload_time_iso_8601": "2025-03-18T19:37:25.041979Z",
"url": "https://files.pythonhosted.org/packages/32/b8/7345b40a65d19b542697374c16f614092bf1e424b7d00f3f117e93d88909/esrt-4.15.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "08ff06d0a4e548e0827f27a1149a58970ee85c1089106842ea634724c764e9ff",
"md5": "dcc0347407b7d771d55110c94503192b",
"sha256": "f026e26b9784acdb3126d8d97e074df2b40584b56f2a6e2ee82cd26f2f426392"
},
"downloads": -1,
"filename": "esrt-4.15.0.tar.gz",
"has_sig": false,
"md5_digest": "dcc0347407b7d771d55110c94503192b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 39362,
"upload_time": "2025-03-18T19:37:26",
"upload_time_iso_8601": "2025-03-18T19:37:26.426155Z",
"url": "https://files.pythonhosted.org/packages/08/ff/06d0a4e548e0827f27a1149a58970ee85c1089106842ea634724c764e9ff/esrt-4.15.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-18 19:37:26",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "esrt"
}