Creating a connection:
>>> from pyes import *
>>> conn = ES('127.0.0.1:9200')
Deleting an index:
>>> try:
>>> conn.delete_index("test-index")
>>> except:
>>> pass
(an exception is fored if the index is not present)
Create an index:
>>> conn.create_index("test-index")
Creating a mapping:
>>> mapping = { u'parsedtext': {'boost': 1.0,
>>> 'index': 'analyzed',
>>> 'store': 'yes',
>>> 'type': u'string',
>>> "term_vector" : "with_positions_offsets"},
>>> u'name': {'boost': 1.0,
>>> 'index': 'analyzed',
>>> 'store': 'yes',
>>> 'type': u'string',
>>> "term_vector" : "with_positions_offsets"},
>>> u'title': {'boost': 1.0,
>>> 'index': 'analyzed',
>>> 'store': 'yes',
>>> 'type': u'string',
>>> "term_vector" : "with_positions_offsets"},
>>> u'pos': {'store': 'yes',
>>> 'type': u'integer'},
>>> u'uuid': {'boost': 1.0,
>>> 'index': 'not_analyzed',
>>> 'store': 'yes',
>>> 'type': u'string'}}
>>> conn.put_mapping("test-type", {'properties':mapping}, ["test-index"])
Index some documents:
>>> conn.index({"name":"Joe Tester", "parsedtext":"Joe Testere nice guy", "uuid":"11111", "position":1}, "test-index", "test-type", 1)
>>> conn.index({"name":"Bill Baloney", "parsedtext":"Joe Testere nice guy", "uuid":"22222", "position":2}, "test-index", "test-type", 2)
Refresh an index:
>>> conn.refresh(["test-index"])
Execute a query
>>> q = TermQuery("name", "joe")
>>> results = self.conn.search(query = q)
Iterate on results:
>>> for r in results:
>>> print r
For more examples looks at the tests.