pyes

Python Elastic Search driver
Download

pyes Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Publisher Name:
  • Alberto Paro
  • Publisher web site:
  • http://ingparo.it

pyes Tags


pyes Description

Python Elastic Search driver pyes is a connector to use elasticsearch from python.For now it is in alpha state, but working.ConnectingThese function are taken from pycassa.Import the module: >>> import pyesFor a single connection (which is _not_ thread-safe), pass a list of servers. >>> client = pyes.connect() # Defaults to connecting to the server at '127.0.0.1:9500' >>> client = pyes.connect()Framed transport is the default. You may disable it by passing framed_transport=False. >>> client = pyes.connect(framed_transport=False)Thread-local connections opens a connection for every thread that calls an ElasticSearch function. It also automatically balances the number of connections between servers, unless round_robin=False. >>> client = pyes.connect_thread_local() # Defaults to connecting to the server at '127.0.0.1:9500' >>> client = pyes.connect_thread_local() # Round robin connections >>> client = pyes.connect_thread_local(, round_robin=False) # Connect in list orderConnections are robust to server failures. Upon a disconnection, it will attempt to connect to each server in the list in turn. If no server is available, it will raise a NoServerAvailable exception.Timeouts are also supported and should be used in production to prevent a thread from freezing while waiting for Cassandra to return. >>> client = pyes.connect(timeout=3.5) # 3.5 second timeout (Make some pyes calls and the connection to the server suddenly becomes unresponsive.) Traceback (most recent call last): ... pyes.connection.NoServerAvailableNote that this only handles socket timeouts.UsageCreating a connection: >>> from pyes import * >>> conn = ElasticSearch('http://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}, )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()Execute a query >>> q = TermQuery("name", "joe") >>> result = self.conn.search(query = q)For more examples looks at the tests. Requirements: · Python What's New in This Release: · Added collecting server info. · Version 0.12 or above requirement. Fixed attachment plugin. Updated bulk insert to use new api. Added facet support (except geotypes). Added river support. Cleanup some method. Added default_indexes variable. Added datetime deserialization. Improved performance and memory usage in bulk insert replacing list with StringIO. Initial propagation of elasticsearch exception to Python.


pyes Related Software