A base resource for working with the Elasticsearch and ElasticsearchDSL libraries in a simple way.
Project description
P_Elascticsearch_Easy
Description
P_Elascticsearch_Easy is a Python utility that provides a simplified class for interacting with elasticsearch and elasticsearch_dsl.
Features
- Create a connection with Elasticsearch
- Retrieve a document given an ID
- Perform a delete_by_query
- Update a document
- Perform an update_by_query
- Index a document
- Perform a bulk operation using the helpers library
- Perform a native bulk operation without using the helpers library
- Perform searches in indices using queries
- Retrieve all documents matching a query
- Perform searches using msearch
- Get a count of documents matching a query
Installation
You can install the package directly from PyPi using pip:
pip install p-elasticsearch-easy
Usage
Example of use ElasticsearchNative
from p_elasticsearch_easy import ElasticsearchNative
# Create de instancia of ElasticsearchNative
es_native: ElasticsearchNative = ElasticsearchNative("https://elastic.com:9243")
# Connect
es_native.connect()
# We execute the get_document_by_id
resp = es_native.search(id="id", index="name_index")
# We execute the delete_by_query
query = {"query":{"match_all":{}}}
es_native.delete_by_query(information=query, index="name_index")
# We execute de update
doc = {
"field1": "value",
"field_2": "value"
}
es_native.update(document=doc, id="id", index="name_index")
# We execute the update_by_query
query = {"query":{"match_all":{}}}
es_native.update_by_query(body=query, index="name_index", wait_for="true")
# We execute the index
doc = {
"field1": "value",
"field_2": "value"
}
es_native.index(document=doc, index="name_index")
# We execute the search
query = {
"size": 10,
"query": {"bool": {"must": [{"term": {"name_field": {"value": ""}}}]}},
}
resp = es_native.search(index="name_index", body=query)
# We execute the bulk
actions = [
{
"_op_type": "index",
"_index": "mi_indice",
"_source": {
"title": "Documento 1",
"contenido": "Este es el primer documento"
}
},
{
"_op_type": "index",
"_index": "mi_indice",
"_source": {
"title": "Documento 2",
"contenido": "Este es el segundo documento"
}
}
]
success_count, errors = es_native.bulk(actions=actions)
# We execute the bulk without helper
operations = [
json.dumps({ "index": { "_index": "mi_indice", "_id": "1" } }),
json.dumps({ "title": "Documento 1", "contenido": "Este es el primer documento" }),
json.dumps({ "index": { "_index": "mi_indice", "_id": "2" } }),
json.dumps({ "title": "Documento 2", "contenido": "Este es el segundo documento" })
]
es_native.bulk_without_helper(operations=operations, wait_for="wait_for")
# We execute the search_all
query = {
"query": {"bool": {"must": [{"term": {"name_field": {"value": ""}}}]}},
}
es_native.search_all(body=query, index="name_index")
# We execute the msearch
searches = [
{"index": "mi_indice"},
{
"query": {
"match": {
"contenido": "primer"
}
}
},
{"index": "mi_indice"},
{
"query": {
"match": {
"contenido": "segundo"
}
}
}
]
es_native.msearch(searches=searches)
# We execute the count
query = {
"query": {"bool": {"must": [{"term": {"name_field": {"value": ""}}}]}},
}
resp = es_native.count(index="name_index", body=query)
# We close the connection
es_native.close()
License
This project is licensed under the GNU GPLv3 license. See the LICENSE file for more details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file p_elasticsearch_easy-1.1.0.tar.gz.
File metadata
- Download URL: p_elasticsearch_easy-1.1.0.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
352b0c50492ca9ce64188cade021272ef67a7e16e06cac5b6be18945d0b10220
|
|
| MD5 |
9d2040aec1105b6b7951e0ef8ca18ecd
|
|
| BLAKE2b-256 |
4e30fcec027ce405ab2098691aba826103c156225a29d062707ebc00a891c8b3
|
Provenance
The following attestation bundles were made for p_elasticsearch_easy-1.1.0.tar.gz:
Publisher:
publish.yml on apo00015/P_Elascticsearch_Easy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p_elasticsearch_easy-1.1.0.tar.gz -
Subject digest:
352b0c50492ca9ce64188cade021272ef67a7e16e06cac5b6be18945d0b10220 - Sigstore transparency entry: 203214861
- Sigstore integration time:
-
Permalink:
apo00015/P_Elascticsearch_Easy@816312e4f42e896defddf7497f4f99b7068ce51b -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/apo00015
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@816312e4f42e896defddf7497f4f99b7068ce51b -
Trigger Event:
push
-
Statement type:
File details
Details for the file p_elasticsearch_easy-1.1.0-py3-none-any.whl.
File metadata
- Download URL: p_elasticsearch_easy-1.1.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6781d89807f45981205cc2fb1ecb455d11a013e2e1474812f667302f801f3b82
|
|
| MD5 |
cadf461cda4600be2d64411c99f535d8
|
|
| BLAKE2b-256 |
dc85dd33209fe50f3a52dc840ef6c8c2a7b707e99a2477948654c32d02477a4f
|
Provenance
The following attestation bundles were made for p_elasticsearch_easy-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on apo00015/P_Elascticsearch_Easy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p_elasticsearch_easy-1.1.0-py3-none-any.whl -
Subject digest:
6781d89807f45981205cc2fb1ecb455d11a013e2e1474812f667302f801f3b82 - Sigstore transparency entry: 203214862
- Sigstore integration time:
-
Permalink:
apo00015/P_Elascticsearch_Easy@816312e4f42e896defddf7497f4f99b7068ce51b -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/apo00015
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@816312e4f42e896defddf7497f4f99b7068ce51b -
Trigger Event:
push
-
Statement type: