First install with pip
pip install opensearch-service
To use , simply do:
from opensearch_service import OpensearchService
##Configure your os Service with your parameters
With no authentification define your host(default=’localhost’ and port (default=9200):
os_service=OpensearchService() # default localhost and port 9200
OR (ONLY FOR URL DIFFERENT Of localhost AND PORT IS NOT 9200
os_service=OpensearchService('myurl',9201)
With HTTP basic authentification host, port and additional informations:
os_service=OpensearchService('localhost',9200,scheme = 'http',http_auth_username = 'myuser',http_auth_password='mypassword')
##To import objects in OpenSearch use :
os_service.import_documents(index_os ,list_of_dict )
where index_os is a string like ‘myos-index’ where list_of_dict is a list of dict like [{‘id’:’id1’,’field1’:’value1,’field1’,’field2’:’value2’},{‘id’:’id2’,’field1’:’value3,’field2’,’field2’:’value4’}]:
list_of_values=[{'_id':'myid1','field1':'value1','field2':'value2','date':'2016-07-15T15:29:50+02:00'},{'_id':'myid2','field1':'value33','field2':'value4','date':'2016-07-15T15:29:50+02:00'}]
os_service.import_documents('myos-index',list_of_values)
##To search Objects in OpenSearch use :
os_service.get_documents(index ,parameter )
where index is a string like ‘myos-index’
- where parameter are :
- To Specify a dateField use
timefield=’my_date_field’
- If so, you must specified a start date GREATER OR EQUAL
startdate=’2020-04-01’
- And a end date LESS than (and not EQUAL)
enddate=’2020-04-02’
- To Specify your query in a dict format use
filters={‘field1’:[‘value1’,’valuer2’],’field2:[value]}
- To specify your query you MUST NOT in a dict format use
exclude={‘field1’:[‘value1’,’valuer2’]}
- To specify query with wildcard use
{‘field1.keyword’: ‘value*’}
- To get only somme fields use :
field_to_include={‘include’:[‘field1’,’field2’]}
examples
hits=os_service.get_documents('myos-index')
hits=os_service.get_documents('myos-index',timefield='date',startdate='2020-04-01',enddate='2020-04-02')
hits=os_service.get_documents('myos-index',filters={'field1':['value1','value3'],'field2':['value4']})
hits=os_service.get_documents('myos-index',filters={'field1':['value1','value3']},wildcard={'field1.keyword':'value3*'})
examples to get values from search (to have hits):
for hit in hits: # if you want to access to your value in dict format values_in_dictformat=hit.to_dict() # OR # if you want to access to a specific value field1=hit.field1
##TO Export a document in json(default) or csv file use :
export_documents(INDEX ,FILENAME ,FORMAT ,PARAMETER )
where INDEX is the index to export (strings) where FILENAME is the file name (string) where FORMAT can be json (default) ou csv where PARAMETER is the same than method getDocument() see previous7
example:
os_service.export_documents(‘myos-index’,’osdata.json’) os_service.export_documents(‘myos-index’,’osdata.csv’,format=’csv’)
##TO Import a json or csv file use :
import_documents_from_file(INDEX ,FILENAME )<br/> Note that :<br/> for csv file : default delimiter is ; <br/> for json file: must be list of value like [{“id”: “id1”},{“id”: “id2”}] <br/>
where INDEX is the index to export (strings) where FILENAME is the file name (string) : can where FORMAT is the type of file : json (default) or csv
example :
os_service.import_documents_from_file(‘myos-index1’,’osdata.json’) os_service.import_documents_from_file(‘myos-index2’,’osdata.csv’) # if delimiter is ; os_service.import_documents_from_file(‘myos-index3’,’osdata.csv’,delimiter=’,’) # if delimiter is ,
Metadata
Release files for opensearch-service 0.23
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| opensearch-service-0.23.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opensearch_service-0.23-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / opensearch-service-0.23.tar.gz
| Download URL | opensearch-service-0.23.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
065cd6287bdcaa998e7384ada38165f6398c2f297cd7ca5e74618ad0645884d8
|
|
BLAKE2b-256 checksum How to use checksums |
5b7d5fbb55941c8c264c58e1b45fd30a6b9e3a28c26ddbabd52a192dc63982e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.5.2
|
Release files / opensearch_service-0.23-py3-none-any.whl
| Download URL | opensearch_service-0.23-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5977365df3fa9ae2a22280d83031975fae9e11afecb89d1f587f18b887fb3cf2
|
|
BLAKE2b-256 checksum How to use checksums |
fdb57ac2f7f79227d2cb4a3b9a563e8e79f2b4f3d32022a1582616eff9fce634
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.5.2
|
Security for opensearch-service 0.23
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.