Skip to content

hardtke/pyelasticsearch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyelasticsearch

A Python client for elasticsearch.

Usage

pyelasticsearch handles the low-level interactions with elasticsearch, allowing you to use native Python datatypes to index or perform queries.

Example:

conn = ElasticSearch('http://localhost:9200/')
# for a cluster, you can use an array -- if the first fails, it will try the next, and so forth.
conn = ElasticSearch(['http://node1.cluster.com:9200','http://node2.cluster.com:9200'])

# auth
# use authentication.  To use basic auth:
conn = ElasticSearch(['http://node1.cluster.com:9200','http://node2.cluster.com:9200'],auth=('user','password'))
# for a list of authentication methods see: http://docs.python-requests.org/en/latest/user/quickstart/#basic-authentication


# Index some documents.
conn.index({"name":"Joe Tester", "age": 25, "title": "QA Master"}, "contacts", "person", 1)
conn.index({"name":"Jessica Coder", "age": 32, "title": "Programmer"}, "contacts", "person", 2)
conn.index({"name":"Freddy Tester", "age": 29, "title": "Office Assistant"}, "contacts", "person", 3)

# Refresh the index to pick up the latest documents.
conn.refresh(["contacts"])

# Get just Jessica's document.
jessica = conn.get("contacts", "person", 2)

# Perform a simple search.
results = conn.search("name:joe OR name:freddy")

# Perform a search using the elasticsearch Query DSL (http://www.elasticsearch.org/guide/reference/query-dsl)
query = {
    "query_string": {
        "query": "name:tester"
    },
    "filtered": {
        "filter": {
            "range": {
                "age": {
                    "from": 27,
                    "to": 37,
                },
            },
        },
    },
}
results = conn.search(query)

# Clean up.
conn.delete_index("contacts")

For more examples, please check out the doctests & tests.py.

License

Licensed under the New BSD license.

Credits

Used pysolr as a jumping off point - thanks guys.

About

python elasticsearch client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%