Giter VIP home page Giter VIP logo

opensearch-dsl-py's Introduction

CI Integration Chat PRs welcome!

OpenSearch logo

OpenSearch DSL Python Client

Welcome!

opensearch-dsl-py is a community-driven, open source fork of elasticsearch-dsl-py licensed under the Apache v2.0 License. For more information, see opensearch.org.

Installation

pip install opensearch-dsl

Sample Code

from opensearchpy import OpenSearch
from opensearch_dsl import Search

host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
ca_certs_path = '/full/path/to/root-ca.pem' # Provide a CA bundle if you use intermediate CAs with your root CA.

# Optional client certificates if you don't want to use HTTP basic authentication.
# client_cert_path = '/full/path/to/client.pem'
# client_key_path = '/full/path/to/client-key.pem'

# Create the client with SSL/TLS enabled, but hostname verification disabled.
client = OpenSearch(
    hosts = [{'host': host, 'port': port}],
    http_compress = True, # enables gzip compression for request bodies
    http_auth = auth,
    # client_cert = client_cert_path,
    # client_key = client_key_path,
    use_ssl = True,
    verify_certs = True,
    ssl_assert_hostname = False,
    ssl_show_warn = False,
    ca_certs = ca_certs_path
)

index_name = 'my-dsl-index'

response = client.indices.create(index_name)
print('\nCreating index:')
print(response)

# Add a document to the index.
document = {
  'title': 'python',
  'description': 'beta',
  'category': 'search'
}
id = '1'

response = client.index(
    index = index_name,
    body = document,
    id = id,
    refresh = True
)

print('\nAdding document:')
print(response)

# Search for the document.
s = Search(using=client, index=index_name) \
    .filter("term", category="search") \
    .query("match", title="python")

response = s.execute()

print('\nSearch results:')
for hit in response:
    print(hit.meta.score, hit.title)

# Delete the document.
print('\nDeleting document:')
print(response)

# Delete the index.
response = client.indices.delete(
    index = index_name
)

print('\nDeleting index:')
print(response)

Project Resources

Code of Conduct

This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact [email protected] with any additional questions or comments.

License

This project is licensed under the Apache v2.0 License.

Copyright

Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

opensearch-dsl-py's People

Contributors

0bsearch avatar agentjeremywelkley avatar andrecimander avatar annawinkler avatar artembernatskyy avatar barseghyanartur avatar benoss avatar brainix avatar dcwatson avatar dsanders11 avatar fxdgear avatar honzakral avatar hugovk avatar jesushernandez avatar jvalhondo avatar konstin avatar marcelometal avatar mattjmcnaughton avatar nonbeing avatar okke-formsma avatar ratanshreshtha avatar robhudson avatar safwanrahman avatar sangheestyle avatar schuyler avatar sethmlarson avatar smal avatar tommyzli avatar trishnaguha avatar ziky90 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.