{ "info": { "author": "Constituent Voice", "author_email": "chris.brown@constituentvoice.com", "bugtrack_url": null, "classifiers": [], "description": "Velociwrapper\n=============\n\nVelociwrapper is a wrapper to create ORM like features around Elasticsearch indexes.\nVelociwrapper is not a true ORM since Elasticsearch isn't a relational database\n\nInstallation\n------------\n\n::\n\n pip install Velociwrapper\n\nOr download manually and run setup.py \n\nGetting Started\n---------------\n\n::\n\n # configuration\n import velociwrapper\n velociwrapper.config.dsn = [\"localhost\"]\n velociwrapper.config.default_index = 'my_elasticsearch_index'\n velociwrapper.config.results_per_page = 50\n \n from velociwrapper import VWBase, VWCollection\n from velociwrapper.es_type import String, Integer, DateTime\n from velociwrapper.mapper import Mapper # for creating or reindexing indexes\n\n # create models, similar to SQLAlchemy\n\n class User(VWBase):\n \n __index__ = 'user_index' # each model can have a custom index. If omitted, uses the default\n __type__ = 'user' # each model most specify the type. Cooresponds to the doc_type in Elasticsearch\n\n username = String(analyzed=False) # keyword arguments can be used to affect the mapping \n password = String(analyzed=False)\n email = String()\n permission_level = String('default_permission', analyzed=False) # ES Types can have default values\n name = '' # Velociwrapper will automatically convert python types to the appropriate type (but you can't specify mappings)\n created = DateTime() # defaults to current time\n address = {} # models can also have nested information\n\n # define a collection. You only need to specify the model\n class Users(VWCollection):\n __model__ = User\n\n \n if __name__ == '__main__':\n # create indexes\n Mapper().create_indices() # creates all defined VWBase models\n\n # create a model\n user = User(\n username='johndoe',\n password=some_encrypt_method('password'),\n email='johndoe@example.com',\n permission_level='admin',\n name='John Doe',\n address={ 'street': '123 Some Street', 'city':'Somewhere','state':'TX','zip':'75000' }\n )\n \n # commit the info to the index\n user.commit()\n\n # (id is created automatically unless specified)\n \n # data is retrieved using a collection class\n\n # search for a user by id\n user_by_id = Users().get(user.id)\n\n # search by another field and return 1 \n user_by_username = Users().filter_by(username='johndoe').one()\n\n # search by multiple fields\n user_by_fields = Users().filter_by(username='johndoe', email='johndoe@example.com').one()\n\n # or chain search conditions together\n user_by_fields = Users().filter_by(username='johndoe').filter_by(email='johndoe@example.com').one()\n\n # specify boolean conditions. ( all() gets all related records for the page)\n users = Users().filter_by(username='johndoe', email='quazimoto@example.com', condition='or').all()\n\n # find out how many records match the criteria in the entire index\n user_count = Users().filter_by(username='johndoe', email='quazimoto@example.com', condition='or').count()\n\n # or using len()\n user_count = len(Users().filter_by(username='johndoe', email='quazimoto@example.com', condition='or'))\n\n # nested objects can automatically be searched as well\n users = Users().filter_by(city='Somewhere').all()\n\nVelociwrapper can do many more things. Read on!\n\n-----\n\nDear God, Why?\n--------------\n\nLike most things it started off as a useful tool and took on a life of its own.\nWe had a ton of code written around SQLAlchemy but wanted the power and convience of\nElasticSearch. We started off mapping results to objects and then added methods that make\nwriting most searches easier.\n\nConfiguration\n-------------\n\n*velociwrapper.config.dsn*\n\nA list of nodes to connect to. Each node can be a string hostname or a dict with options. \nSee http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch for valid values. \n(sets the value of the ``hosts`` parameter). Defaults to ``localhost``.\n\n*velociwrapper.config.connection_params*\n\nA ``dict`` of additional parameters to pass to the client connection. \nSee http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch\nDefaults to ``{}``\n\n*velociwrapper.config.default_index*\n\nA string index to use if it is not specified in the model. Defaults to ``es_model``\n\n*velociwrapper.config.bulk_chunk_size*\n\nA few calls such as ``VWCollection.delete()``, ``VWCollection.commit()``, or ``Mapper.reindex()`` can act on\nlarge collections. The ``bulk_chunk_size`` tells Elasticsearch how many records to operate on at a time.\nDefaults to 1000\n\n*velociwrapper.config.results_per_page*\n\nFor performance reasons Elasticsearch will not return large numbers of documents in a single call. As such\nreturn values are limited. This value is the default results but you can also pass the parameter to ``all()``\nto change the result for a single value. Defaults to 50\n\n*velociwrapper.config.strict_types*\n\nPerform type checks when creating objects. When ``True`` velociwrapper will throw an exception if the value\nyou're setting doesn't match the attribute's assigned type.\n\n**Configuration using environment variables**\n\nAll configuration variables can be set via the environment. \n\n``VW_DSN`` maps to ``dsn``. Can be a comma separated string or JSON\n\n``VW_CONNECTION_PARAMS`` maps to ``connection_params``. Must be JSON\n\n``VW_DEFAULT_INDEX`` maps to ``default_index``. String\n\n``VW_BULK_CHUNK_SIZE`` maps to ``bulk_chunk_size``\n\n``VW_RESULTS_PER_PAGE`` maps to ``results_per_page``\n\n----\n\nTypes\n------------------\n\nElasticsearch is extremely flexible when it comes to adding types but less forgiving about changing them. To\nhelp with this we created a metaclass called ``ESType`` to define mappings used in Elasticsearch. The types are \nused when ``strict_types`` is on and both the mapping options and types are used when creating or reindexing the\nindices. The mapping options are set in the metaclass, otherwise the types subclass normal Python types and \nare used the same way.\n\nUsing Velociwrapper's types is completely optional. If you define the models using normal Python types, everything\nwill work as expected. The biggest drawback is that Velociwrapper will not automatically be able to use filter\nsyntax on ``not_analyzed`` string fields.\n\nAll defaults in Velociwrapper's types are set to Elasticsearch's defaults:\nhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html\n\nIn cases where the option begins with \"_\" Velociwrapper requires the underscore be appended rather than prepended.\n\n**Available Types**\n\n**String** *([str],\\*\\*kwargs)*\n \nKeyword args:\n\n- ``analyzed``\n- ``norms``\n- ``index_options``\n- ``analyzer``\n- ``index_analyzer``\n- ``search_analyzer``\n- ``ignore_above``\n- ``position_offset_gap``\n- ``value_``\n- ``boost_``\n\nThe ``analyzed`` argument maps to ``index=analyzed|not_analyzed`` default is ``analyzed``\n\n**Number** *([number], \\*\\*kwargs)*\n\nGeneric number type. Normally you should use the number type classes that derive from this. If ``type`` is omitted\ndefaults to ``float``\n\nKeyword args:\n\n- ``type``\n- ``index_``\n- ``precision_step``\n- ``ignore_malformed``\n- ``coerce``\n\nThe following types use the same arguments (except for type which is specified automatically)\n\n- ``Float`` *([float], \\*\\*kwargs)*\n- ``Integer`` *([int], \\*\\*kwargs)*\n- ``Long`` *([float], \\*\\*kwargs)*\n- ``Short`` *([float], \\*\\*kwargs)*\n- ``Byte`` *([float], \\*\\*kwargs)*\n- ``Tokencount`` *([number],\\*\\*kwargs)*\n\n**Date** *([date|str] | [year int, month int, day int], \\*\\*kwargs)* and **DateTime** *([datetime|str] | [year int, month int, day int, [hour int, [minute int,[second int, [microsecond int]]]]], \\*\\*kwargs)*\n\nKeyword args:\n\n- ``format``\n- ``precision_step``\n- ``ignore_malformed``\n\n**Array** - new in 1.0.8\n\nSpecial type that specifies a list of items that are a single type. Accepts any keyword argument above. ``type_`` keyword specifies the type to be used. Default is string\n\n**Binary** *()*\n\nExperimental. Keyword arguments:\n\n- ``compress``\n- ``compress_threshold``\n\n**IP** *([str])*\n\nKeyword args:\n\n- ``precision_step``\n\n**GeoShape** / **GeoPoint**\n\nExperimental. Will work as regular objects as well.\n\n----\n\nType Functions\n--------------\n\n**create_es_type** *(value)*\n\nTakes ``value`` and returns the equivalent Elasticsearch type. If an appropriate type cannot be determined then the value itself is returned.\n\n----\n\nModels\n---------------\n\nCreate a model by defining the name of the model and extending ``VWBase`` (or a subclass of ``VWBase``).\nProperties for the model should be statically defined. They can be ESTypes as described above or as regular\nPython types. Values set in the model are defaults in each instance.\n\nThe ``__type__`` attribute is required and maps to the Elasticsearch ``doctype``. ``__index__`` is recommended\nbut if it is not present then the value of ``velociwrapper.config.default_index`` is used.\n\nExample:\n\n::\n\n class User(VWBase):\n __index__ = 'user_index'\n __type__ = 'user'\n username = String(analyzed=False)\n password = String(analyzed=False)\n email = String(analyzed=False)\n name = String()\n profile_image = String('default.jpg')\n\n\nOr without using ESTypes:\n\n::\n\n class User(VWBase):\n __index__ = 'user_index'\n __type__ = 'user'\n username = ''\n password = ''\n email = ''\n name = ''\n profile_image = ''\n\nThe added benefit of using ESTypes is specifying the mappings. This helps velociwrapper know what kind of searches to build\nand can create the mappings for you, if you haven't specified them yourself.\n\nOnce models are created they must be committed to save into the Elasticsearch cluster\n\n::\n\n u = User(\n username='jsmith', \n password=crypt_method('password123'), \n email='jsmith@example.com', \n name='John Smith', \n profile_image='jsmith.jpg'\n )\n\n u.commit()\n\nThe call to ``commit()`` generates an id for the document. If you want to explicitly set the id first, you can set the id attribute:\n\n::\n\n u = User( ... )\n u.id = 'my-unique-id'\n u.commit()\n\n*Be careful!*. IDs have to be unique across all types in your index. If your ID is not unique, the ID specified will be updated by\nyour new data. It is recommended to let Velociwrapper handle ID creation unless you're certain of what you're doing.\n\n**Model API**\n\n**collection** *()*\n\nReturns a ``VWCollection`` for this model. If a custom subclass has been defined it will be returned. Otherwise a new collection will be created.\n\n**commit** *()*\n\nCommits the model to Elasticsearch. New models will be created as new documents. Existing models will be updated.\n\n**delete** *()*\n\nDeletes the cooresponding document from Elasticsearch. New operations cannot be performed on the model once it is marked\nfor delete.\n\n**sync** *()*\n\nSyncs the document in Elasticsearch to the model. Overwrites any uncommitted changes.\n\n**to_dict** *()*\n\nConverts the model to a dictionary. Very useful for outputting models to JSON web services. This method is intended to be overridden for\ncustom output.\n\n**more_like_this** *()*\n\nPerforms a search to get documents that are \"like\" the current document. Returns a VWCollectionGen.\n\n----\n\nCollections\n------------\n\nCollections are used to search and return collections of models. Searches can be chained together to create complex queries of Elasticsearch\n(much like SQLAlchemy). Currently collections are of one document type only. This may change in a future release.\n\nExample:\n \n::\n\n # all users named john\n users = Users().filter_by(name='John').all()\n\n # users named john who live in texas\n users = Users().filter_by(name='John', state='TX').all()\n\n # another way to write the same as above\n users = Users().filter_by(name='John').filter_by(state='TX').all()\n\nBy default chained criteria are joined with \"AND\" (\"must\" in most cases internally). But can be controlled:\n\n::\n\n # users who live in texas or are named john:\n users = Users().filter_by(name='John', state='TX', condition='or').all()\n\nFor more complex queries see the ``raw()`` method and the QDSL module.\n\n**Creating Collections**\n\nCreated a collection by calling ``Model().collection()``. If a subclass of the collection exists it will be created and returned\notherwise an base collection will be created for the model by calling ``VWCollection(baseobj=Model)``. ``collection()`` is \nconvienent because it allows collections and models to be defined in separate files without recursive import errors.\n\nWhen creating a subclass for a collection, specify the model using the ``__model__`` property.\n\n::\n\n class Users(VWCollection):\n __model__ = User\n\n**Conditions**\n\nConditions in Elasticsearch are a little tricky. Internally the ``bool`` queries / filters are used. Instead of the traditional\n``and``, ``or``, ``not``. Elasticsearch uses ``must``, ``should`` and ``must_not``. To make things a bit more interesting the\ntraditional boolean values exist as well and Elasticsearch recommends they be used is certain cases (such as geo filters) \nVelociwrapper converts ``and``, ``or``, ``not`` to the Elasticsearch equivalents except in the case of ``search_geo()``.\n\nThe ``must``, ``should``, ``must_not`` options can be used instead and will work. ``minimum_should_match`` is also available. If \nthe explicit options are needed you can use ``explicit_and``, ``explicit_or``, and ``explicit_not``.\n\nConditions can become complex very quickly. Velociwrapper tries to take a \"do what I mean\" approach to chained conditions. First\nthe current filter is checked for a specific condition. If no condition exists then the *preceeding* condition is used. If there\nis no preceeding condition, the condition is set to and/must by default.\n\nExamples:\n\n::\n\n # get users in named John or Stacy \n users = Users().filter_by(name='John').filter_by(name='Stacy', condition='or').all()\n\n # equivalent because the second filter_by() will use the preceeding or condition:\n users = Users().filter_by(name='John', condition='or').filter_by(name='Stacy').all()\n\n # add another condition, such as state, might not always do what we expect. This would return anyone\n # who's name is stacy or john or lives in Texas\n users = Users().filter_by(name='John').filter_by(name='Stacy', condition='or').filter_by(state='TX').all()\n\n # (john or stacy) and state\n users = Users().filter_by(name='John').filter_by(name='Stacy', condition='or').filter_by(state='TX',condition='and').all()\n\nObviously order matters. For more complex queries the other option is to use the ``raw()`` method and the QDSL module (see below)\n\n**API**\n\nMethods marked chainable internally change the search query to affect the output on ``all()``, ``delete()``, and ``one()``. Chainable methods can be\ncalled multiple times with different parameters.\n\n**all** *(\\*\\*kwargs)*\n\nExecutes the current search and returns ``results_per_page`` results. (default 50). ``results_per_page`` is specified in ``velociwrapper.config.results_per_page``\nbut can also be specified by keyword arguments. \n\nIf no search has been specified, Velociwrapper will call ``match_all``.\n\nIf no results are matched ``all()`` returns an empty VWCollectionGen.\n\nArguments:\n\n- ``results_per_page`` *int*: number of results to return\n- ``size`` *int*: same as results_per_page\n- ``start`` *int*: Record count to start with\n\n**clear_previous_search** *()*\n\nClear all search parameters and reset the object. Even after a call to an output method the search can be output again. This allows the collection to be reused.\nGenerally its better to create a new object.\n\n**commit** *([callback=callable])*\n\nBulk commits a list of items specified on ``__init__()`` or if no items were specified will bulk commit against the items matched in the current search. (be careful! Calling something like Users().commit() will commit all users!)\n\nThe ``callback`` argument should be a callable. The raw item will be passed to it and it must return either a ``dict`` or a ``VWBase`` \n(model) object. Note that velociwrapper does not call each model's ``commit()`` or ``to_dict()`` methods but rather issues the request\nin bulk. Thus you cannot affect the behavior by overriding these methods. Use the ``callback`` to make changes or change the items before\npassing them to the collection.\n\nAs of 2.0 it is also possible to register a callback to manipulate items in the commit. See \"Callbacks\".\n\n**count** *()*\n\nReturns the total number of documents matched (not that will be returned!) by the search. \n\n**delete** *(\\*\\*kwargs)*\n\nDelete the records specified by the search query.\n\n**delete_in** *(ids=list)*\n\nDelete the records specified by a list of ids. Equivalent to:\n\n::\n\n Users().filter_by(ids=list_of_ids).delete()\n\n**exact** *(field=str, value=mixed)*\n\nChainable. Find records where ``field`` is the exact ``value``. String based fields **must** be specified as ``not_analyzed`` in the index. Otherwise results\nmay not be as expected. ``exact()`` is more for completeness. ``filter_by()`` uses exact values when available. The only difference is ``exact()``\nwill warn if the field cannot be searched while ``filter_by()`` silently converts to a query.\n\nKeyword arguments:\n\n- ``boost`` *float*: An explicit boost value for this boolean query\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**exists** *(field, [kwargs])*\n\nChainable. Find records if the specified field exists is the document.\n\nKeyword arguments:\n\n- ``boost`` *float*: An explicit boost value for this boolean query\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**filter_by** *([condition], kwargs)*\n\nChainable. Filter or query elasticsearch for ``field=\"search\"``. Automatically creates filters or queries based on field mappings. If the ``search`` parameter is a list, filter_by will create\nan ``in()`` filter / query. ``condition`` can be set as the first argument or passed as a keyword argument.\n\nKeyword arguments\n\n- ``[field]`` *str*: A field in the document set to the value to try to find.\n- ``id`` *value*: Explicitly search for particular id. \n- ``ids`` *list*: Explicitly search for using a list of ids. \n- ``boost`` *float*: An explicit boost value for this boolean query\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**multi_match** *(fields=list,query=str,\\*\\*kwargs)*\n\nChainable. Search the list of fields for the value of query. Accepts standard kwargs arguments.\n\n**get** *(id=value)*\n\nReturns the single record specified by ``id`` or ``None`` if it does not exist.\n\n**get_in** *(ids=list)*\n\nReturns a list of records specified by the list of ids or an empty list if no ids exist. Note this method cannot be sorted. If sorting is needed it is better to call\n\n::\n\n filter_by(ids=list).sort(...).all()\n\n**get_like_this** *(id)*\n\nReturns records like the document specified by id or an empty list if none exists. Note this method cannot be sorted.\n\n**\\_\\_init\\_\\_** *([items=list],[\\*\\*kwargs])*\n\nCreate a collection. If ``items`` are specified they are stored internally to ``commit()`` in bulk. Stored items must be models (subclassing ``VWBase``) or ``dict``.\n\nKeyword arguments:\n\n- ``bulk_chunk_size`` *int*: override default chunk size for this collection\n- ``results_per_page`` *int*\n\n**\\_\\_len\\_\\_** *()*\n\nSame as ``count()``. Allows for the entire collection to be passed to ``len()``\n\n**missing** *(field=str,\\*\\*kwargs)*\n\nChainable. Finds records where the specified ``field`` is missing\n\nKeyword arguments:\n\n- ``boost`` *float*: An explicit boost value for this boolean query\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**one** *()*\n\nExecutes the search and returns the first record only. Raises ``NoResultFound`` if the search did not match any documents.\n\n**range** *(field=str, \\*\\*kwargs)*\n\nChainable. Filters the results by a range of values in ``field``. The keyword arguments coorespond to arguments used by the range filter\nin Query DSL: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html\n\nOther search keywords are available except for ``boost``. ``boost`` affects the range query itself. Keyword arguemtns are:\n\n- ``gte`` *number or date*: greater than or equal\n- ``gt`` *number or date*: greater than\n- ``lte`` *number or date*: less than or equal\n- ``lt`` *number or date*: less than\n- ``boost`` *float*: boost value for the range query itself\n- ``time_zone`` *str*: timezone offset. Only used if comparison is a date and doesn't contain a timezone offset already.\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**raw** *(rawquery=dict)*\n\nExecute a raw Query DSL query. Chainable but all other search filters are ignored. Can still be used with ``sort()``.\n\n***search** *(query=string)*\n\nExecute a Lucene query against the server. Chainable.\n\n**search_geo** *(field=str,distance=float,lat=float,lon=float,\\*\\*kwargs)*\n\nChainable. Filter the search based on distance from a geopoint.\n\n- ``boost`` *float*: An explicit boost value for this boolean query\n- ``condition`` *str*: \"and\",\"or\",\"not\",\"explicit_and\",\"explicit_or\",\"explicit_not\",\n- ``minimum_should_match`` *int*: When executing a should (or) query, specify the number of options that should match to return the document. Default = 1\n- ``with_explicit`` *str*: \"and\",\"or\",\"not\". Only used if explicit conditions exist and there's a question of how an additional condtion should be added to the query. \n\n**sort** *(\\*\\*kwargs)*\n\nChainable (and can appear anywhere before an output method, including by having other filters chained to it). Arguments are ``field=asc|desc``. ``asc`` sorts the field\nfirst to last. ``desc`` sorts the field last to first. ``asc`` is the default.\n\n----\n\nAdditional Methods for ``VWCollectionGen``\n------------------------------------------\n\n``VWCollectionGen`` is returned by calls from ``VWCollection.all()`` and ``VWCollection.get_in()``. \n\n**results** *(self)*\n\nReturns the underlying ElasticSearch results. Useful for getting meta information\n\nQuery Bodies with ``querybuilder.QueryBody`` \n--------------------------------------------\n\nUnderlying chainable methods is the ``querybuilder.QueryBody`` class. This class helps build simple query bodies\nfor Elasticsearch but attempts not to get too crazy. It stores an internal structure of the query and then\nbuilds it into a ``dict`` that can be passed to the underlying Elasticsearch client. The class is used internally\nby ``VWCollection`` but you could use it directly to build queries to then pass to the ``raw()`` method.\n\n``QueryBody`` only supports queries and filters. For other wrappers, such as constant_score, you'll need to manually\nbuild the queries by hand or with the ``QDSL`` functions described below.\n\n**QueryBody methods**\n\n**chain** *(self, newpart=dict, \\*\\*kwargs)*\n\nChains a new part of the query into the existing query. Newpart must be a ``dict`` with additional query parameters\nto pass to Elasticsearch. Note that ``newpart`` is not checked for correctness. \n\nReturns ``self`` so additional methods can be called. \n\nKeyword Arguments:\n\n- ``type`` *string*: either \"query\" or \"filter\". If not specified checks ``newpart`` for one of these keywords. Otherwise uses \"query\"\n- ``condition`` *string*: must|should|must_not|and|or|not. Defaults to \"must\". Specifies how this part of the query is treated in relation to the existing query\n- ``with_explicit`` *string*: and|or|not. Included for legacy purposes. Overrides ``condition`` and is useful if a nested bool was manually created. Generally should not be used.\n\n**is_filtered** *(self)*\n\nReturns ``True`` if the current query body contains a filter.\n\n**is_query** *(self)*\n\nReturns ``True`` if the current query body contains a query other than ``match_all {}``\n\n**build** *(self)*\n\nBuilds the current query into a representation understood by Elasticsearch. Returns ``dict``\n\n----\n\nQDSL and Building Raw Queries\n-----------------------------\n\n``velociwrapper.qdsl`` contains functions to help make writing QDSL easier.\n\n**QDSL Functions**\n\n**query** *(params=dict)*\n\nReturns ``params`` wrapped by ``{ \"query\": params }``\n\n**filter_** *(params=dict)*\n\nReturns ``params`` wrapped by ``{ \"filter\": params }``.\n\nNote the \"_\" appended to ``filter_`` to prevent confusion with Python's ``filter()``\n\n**match** *(field=str,value=str|dict,\\*\\*kwargs)*\n\nReturns ``{\"match\": { field: { \"query\": value } } }``\n\nAdditional keyword arguments should be Elasticsearch arguments on ``match``\n\n**match_phrase** *(field=str,value=str|dict,\\*\\*kwargs)*\n\nEquivalent to ``match(field,value,type=\"phrase\")``\n\n**match_phrase_prefix** *(field=str,value=str|dict,\\*\\*kwargs)*\n\nEquivalent to ``match(field,value,type=\"phrase_prefix\")``\n\n**multi_match** *(query=str|dict, fields=list,\\*\\*kwargs)*\n\nReturns ``{\"multi_match\": {\"query\": query, \"fields\": fields } }``\n\nAdditional keyword arguments should be Elasticsearch arguments on ``multi_match``\n\n**bool_** *(\\*args,\\*\\*kwargs)*\n\nArgs are any number of dicts containing \"must\", \"should\" or \"must_not\" keys. Note the appended \"_\" to prevent\nconfusion with Python's ``bool``.\n\nKeyword arguments are Elasticsearch options for ``bool`` such as ``minimum_should_match``\n\nExample:\n\n::\n\n from velociwrapper.qdsl import bool_, must, must_not, match\n mybool = bool_(\n must( match('foo','some value') ), \n must_not( match( 'bar', 'some other value' ) )\n )\n\nSpecial Keyword arguments\n\n- *__vw_set_current* *dict*: set a current ``bool`` dictionary that will be updated rather than creating a blank one.\n\n**must** *(params=str|dict, value=str|dict|None,\\*\\*kwargs)*\n\nCreates a ``must`` arguement for ``bool``. If params is a ``dict`` then it is passed on directly. If it is a string or value\nis set then the params are treated as a field name and passed to ``term``.\n\nExample:\n\n::\n\n must( match('foo', 'some value' ) )\n # returns { \"must\": { \"match\": { \"foo\": {\"query\": \"some value\" } } } }\n\n must('foo', 'some value' ) )\n # returns { \"must\": { \"term\" { \"foo\": {\"value\": \"some value\" } } } }\n\n**must_not** *(params=str|dict,value=str|dict|None,\\*\\*kwargs)*\n\nLike ``must`` but uses \"must_not\"\n\n**should** *(params=str|dict,value=str|dict|None,\\*\\*kwargs)*\n\nLike ``must`` but uses \"should\"\n\n**term** *(field=str, value=str,\\*\\*kwargs)*\n\nLike ``match`` but for filters\n\n**terms** *(field=str,value=list,\\*\\*kwargs)*\n\nLike ``term`` but values are a list of strings to match in a field.\n\n**boosting** *(\\*args, \\*\\*kwargs)*\n\nSimilar to ``bool`` allows any number of dicts with the key ``positive`` or ``negative``. Keyword arguments are options\npassed to ``boosting``\n\n**positive** *(field,value)*\n\nReturns ``{ \"positive\": { \"term\": { field: value } } }``\n\n**negative** *(field,value)*\n\nReturns ``{ \"negative\": {\"term\": { field:value } } }``\n\n**common** *(field, value, \\*\\*kwargs)*\n\nReturns ``{ \"common\": { field: { \"query\": value } } }``\n\nKeyword arguments are passed as additional key values to the ``field`` dict.\n\n**constant_score** *(\\*args, \\*\\*kwargs)*\n\nArguments should be ``dict``. A single argument is wrapped directly by ``constant_score``. In the case of multiple arguments the function searches each\nfor ``query`` or ``filter`` keys to wrap in the output.\n\n**filtered** *(\\*args, \\*\\*kwargs)*\n\nArguments should be ``dict``. A single argument is wrapped directly by ``filtered``. In the case of multiple arguments the function searches each\nfor ``query`` or ``filter`` keys to wrap in the output.\n\nAdditional keyword arguments are set on the ``filtered`` dict.\n\n**function_score** *(\\*args, \\*\\*kwargs)*\n\nArguments should be ``dict``. A single argument is wrapped directly by ``function_score``. In the case of multiple arguments the function searches each\nfor ``query``, ``filter``, ``FUNCTION``, or ``functions`` keys to wrap in the output. No magic happens here to check the validity of the functions!\n\nKeyword arguments are set on the ``function_score`` dict.\n\n**fuzzy**\n\n**ids**\n\n**query_term**\n\n**indices**\n\n**match_all**\n\n**more_like_this**\n\n**nested**\n\n**prefix**\n\n**query_string**\n\n**simple_query_string**\n\n**range**\n\n**regexp**\n\n**span_term**\n\n**span_first**\n\n**span_multi**\n\n**span_near**\n\n**span_not**\n\n**span_or**\n\n**wildcard**\n\n**and_**\n\n**or_**\n\n**not_**\n\n**exists**\n\n**geo_bounding_box**\n\n**geo_distance**\n\n**geo_range**\n\n**geo_polygon**\n\n**geo_shape**\n\n**geohash_cell**\n\n**has_child**\n\n**has_parent**\n\n**missing**\n\n**script**\n\n**type_**\n\n\n----\n\nMapper\n------\n\nUse the mapper by importing it:\n\n::\n\n from velociwrapper.mapper import Mapper\n\nThe Mapper class has utilities for managing the Elasticsearch index.\n\n**Mapper API**\n\n**get_index_map** *(\\*\\*kwargs)*\n\nSearches for currently loaded VWBase models and returns the their indexes as defined by code, along with their mappings. The only keyword argument is ``index``, passed to specify \na particular index or group of indexes (must be a ``str`` or ``list``).\n\n**get_server_map** *(\\*\\*kwargs)*\n\n*New in version 1.0.10*. Like *get_index_map()*, but returns the mapping as saved on the server.\n\n**create_indices** *(\\*\\*kwargs)*\n\nCreates indexes based on currently loaded VWBase models or for the index or indexes specified by the ``index`` keyword argument.\n\n**get_index_for_alias** *(alias=str)*\n\nReturn the name of the index for the specified ``alias``. If ``alias`` is an index, then the same name will be returned.\n\n**reindex** *(index=str,newindex=str,\\*\\*kwargs)*\n\nRe-indexes the specified index to a new index. Useful for making model changes and then creating them in Elastic search\n\nKeyword arguments\n\n- ``alias_name`` *string*: specify a new alias name when re-mapping an alias. If omitted the previous alias name is used.\n- ``remap_alias`` *bool*: Aliases the index under a new name. Useful for making on-the-fly changes\n\n**describe** *(cls=class)*\n\nOutput the index mapping for a VWBase class.\n\n----\n\nCallbacks\n---------\n\nThere are several events built-in to Velociwrapper on which you can register callbacks. \nCallbacks are registered at the class level so all instances will have the callback. You \ncan also register multiple methods for the same event. Callbacks recieve the instance and \na single (optional) argument. The argument is returned. In the case of multiple callbacks \non an event, the callbacks are fired in the order they were registered. The return value \nfrom one method is passed to the next as the argument.\n\nExample:\n\n::\n\n from your_models import Document\n \n # check a user for entry in another database\n def doc_database_check( vwinst, argument=None ):\n if not doc_in_database(vwinst.id):\n insert_into_database( vwinst.id, vwinst.name, vwinst.content ) # or whatever\n return argument \n\n Document.register_callback( 'after_commit', doc_database_check )\n\nCallbacks are defined in the ``VWCallback`` class in base.py. ``VWCollection`` and ``VWBase`` \nderive from ``VWCallback``\n\n**Callback API**\n\n**register_callback** *(cls, callback_event=str, callback=callable)* *- classmethod*\n\nRegister a callback for the event *callback_event* on the collection or base class. This is a class method,\nthe callback becomes active on all instances.\n\n**deregister_callback** *(cls, callback_event=str, callback=callable|str)* *- classmethod*\n\nDeregister a callback for the event *callback_event* by its name or original function *callback*. Returns None\neven if there was not a callback by the name or for the event.\n\n**execute_callbacks** *(self, event=string, argument=None, \\*\\*kwargs)*\n\nExecutes the current instances callbacks for *event* in the order they were registered. Returns *argument*.\nIf no callback was registered for the event the method returns *None*\n\n**Available Events**\n\n*before_manual_create_model*\n\nExecuted when a model instance is created directly but not when the model is created as the result of a search.\n*argument* is ignored, only the model's instance is passed. The event fires before mapping information is copied\nfrom the class and before the id is created. An example use is a custom ID creation method.\n\n*after_manual_create_model*\n\nExecuted when a model instance is created directly but not when the model is created as the result of a search.\n*argument* is ignored, only the model's instance is passed. The event fires after the class variables are copied\nto the instance, *id* is created, and the *__index__* is set.\n\n*on_delete*\n\nExecuted when ``commit()`` is called on a deleted instance. Fires just before the underlying DELETE to Elasticsearch.\nArgument is ignored. Does not execute on a bulk delete call in ``VWCollection``.\n\n*before_commit*\n\nExecuted before the INDEX call to Elasticsearch. The argument is ignored. Does not execute on bulk commit calls in\n``VWCollection``.\n\n*after_commit*\n\nExecuted after the INDEX call to Elasticsearch. The argument is ignored. Does not execute on bulk commit calls in\n``VWCollection``.\n\n*before_sync*\n\nExecuted before retrieveing the underlying document from Elasticsearch to sync the object. The argument is ignored. \n\n*after_sync*\n\nExecuted after variables from Elasticsearch have overwritten object attributes. The argument is ignored.\n\n*before_query_build*\n\nExecuted just before a search query is created. The argument is the current ``QueryBody``.\n\n*after_query_build*\n\nExecutes after the search query is created as a ``dict``. The argument is the ``dict`` to be passed to the Elasticsearch client.\n\n*on_bulk_commit*\n\nExecutes for each item before being appended to a bulk commit operation. The argument is the item. The item can be a \n``dict`` source document or a ``VWBase`` object depending on what was passed to the collections items. (If the commit\ncriteria was a search query then ``VWBase`` objects are passed.\n\n*before_auto_create_model*\n\nExecutes after a source document is retrieved from Elasticsearch but before the document is converted to a model\ninstance. Note this does not fire until accessed in the ``VWCollectionGen`` generator. The argument passed is the\nsource document\n\n*after_auto_create_model*\n\nExecutes after the a source document result is converted to a model instance. Does not occur until the model \ninstance is accessed in the generator. Due to the way the generator works the instance passed to the callback\nis empty, while the argument is the newly created instance to manipulate.\n\n**Creating New Events**\n\nYou can register your own events and fire them yourself.\n\n::\n\n # register an event when your generic document is something specific\n def is_pdf(inst, argument=None, **kwargs):\n # do something\n return argument\n\n Document.register_callback( 'on_edit', is_pdf )\n\n # then somewhere in your code (maybe an edit function?)\n document_instance.execute_callbacks('on_edit')\n\n----\n\nAUTHOR\n------\n\nChris Brown, Drew Goin and Boyd Hitt \n\n----\n\nCOPYRIGHT\n---------\n\nCopyright (c) 2015-2019 Constituent Voice LLC", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/constituentvoice/Velociwrapper", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "Velociwrapper", "package_url": "https://pypi.org/project/Velociwrapper/", "platform": "", "project_url": "https://pypi.org/project/Velociwrapper/", "project_urls": { "Homepage": "https://github.com/constituentvoice/Velociwrapper" }, "release_url": "https://pypi.org/project/Velociwrapper/2.1.0/", "requires_dist": null, "requires_python": "", "summary": "Wrapper to create models and collections around Elastic Search", "version": "2.1.0" }, "last_serial": 5239212, "releases": { "2.0.10": [ { "comment_text": "", "digests": { "md5": "c3fb6e0717da8f5195874e0c3ac46475", "sha256": "6e4aa396108a48eda8506579ca202730892571737822be17a5a210d5311eec09" }, "downloads": -1, "filename": "Velociwrapper-2.0.10.tar.gz", "has_sig": false, "md5_digest": "c3fb6e0717da8f5195874e0c3ac46475", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43279, "upload_time": "2015-12-17T23:20:53", "url": "https://files.pythonhosted.org/packages/d1/99/d91a57b0ccbe51535ce37a547c2daff6d87f07ac9d48dc9f909fe45d773b/Velociwrapper-2.0.10.tar.gz" } ], "2.0.11": [ { "comment_text": "", "digests": { "md5": "c1d66a53d0eeafe29ea72715c083ae49", "sha256": "8d05add4143a9f3a7bd22f6d9ed1d57fcdd13757083564af6fc0efaccfa10673" }, "downloads": -1, "filename": "Velociwrapper-2.0.11.tar.gz", "has_sig": false, "md5_digest": "c1d66a53d0eeafe29ea72715c083ae49", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43277, "upload_time": "2016-01-06T22:17:21", "url": "https://files.pythonhosted.org/packages/3f/0d/1939dca8a195b9c4acf87fac8810891fdbcde947b5fb9f98f0df33b60cbe/Velociwrapper-2.0.11.tar.gz" } ], "2.0.12": [ { "comment_text": "", "digests": { "md5": "5e6de49add3e85882b44a71f1d80d2c6", "sha256": "878d52d8d5bca08b793a02b94ef84d3dff6e9f2fab370017200c8f4115783b10" }, "downloads": -1, "filename": "Velociwrapper-2.0.12.tar.gz", "has_sig": false, "md5_digest": "5e6de49add3e85882b44a71f1d80d2c6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43291, "upload_time": "2016-02-16T00:48:19", "url": "https://files.pythonhosted.org/packages/ea/d5/85872fe4f1fc6bdf660b304139272dfb644d4fdaf58b204fb6fcd52e6e67/Velociwrapper-2.0.12.tar.gz" } ], "2.0.13": [ { "comment_text": "", "digests": { "md5": "2719873a412428e1fb9a9d15612e535a", "sha256": "1c3c7024ff6312e9669aff8e916faf5b0dabe46abc3352945f64f00b1cbd49b2" }, "downloads": -1, "filename": "Velociwrapper-2.0.13.tar.gz", "has_sig": false, "md5_digest": "2719873a412428e1fb9a9d15612e535a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43324, "upload_time": "2016-02-16T00:55:05", "url": "https://files.pythonhosted.org/packages/e3/21/5e5b853816082418835504db222de14420b5a719811dbee3c2b6e14c2256/Velociwrapper-2.0.13.tar.gz" } ], "2.0.14": [ { "comment_text": "", "digests": { "md5": "1d9c8cf09abd2ebfd6acc3992680d750", "sha256": "2813b6b93bb57f0110bc25f500a969e233728c6c2e7aa79a5a013fb3f17be87b" }, "downloads": -1, "filename": "Velociwrapper-2.0.14.tar.gz", "has_sig": false, "md5_digest": "1d9c8cf09abd2ebfd6acc3992680d750", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43458, "upload_time": "2016-03-16T03:30:09", "url": "https://files.pythonhosted.org/packages/c5/c5/d1c7fb55e5f195a4e805c8fea0786a53d9106c9feea805c1c0e912a49b26/Velociwrapper-2.0.14.tar.gz" } ], "2.0.15": [ { "comment_text": "", "digests": { "md5": "6c18f1d9bbdb739bd36c4879f75301ab", "sha256": "a817f23c76e95887e33f77212755b46a18abf3782b1621e339201ded00729937" }, "downloads": -1, "filename": "Velociwrapper-2.0.15.tar.gz", "has_sig": false, "md5_digest": "6c18f1d9bbdb739bd36c4879f75301ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43678, "upload_time": "2016-10-27T00:53:41", "url": "https://files.pythonhosted.org/packages/cd/88/75e23d8e532801a070ac20790037148a5c2acafc719713ffabbf237654a0/Velociwrapper-2.0.15.tar.gz" } ], "2.0.16": [ { "comment_text": "", "digests": { "md5": "bf1336774f55fe7805345e7ab88e24ab", "sha256": "60b0aec4d1c38e2a6deb7907e9579826494a650e7c80cba000f9b0aa4d05bf2f" }, "downloads": -1, "filename": "Velociwrapper-2.0.16.tar.gz", "has_sig": false, "md5_digest": "bf1336774f55fe7805345e7ab88e24ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43686, "upload_time": "2016-10-27T00:54:58", "url": "https://files.pythonhosted.org/packages/2d/d1/fbb9ac268561dfc9299372fdebb8ded6ae1abb8cddba059ecfaf6a945d9b/Velociwrapper-2.0.16.tar.gz" } ], "2.0.18": [ { "comment_text": "", "digests": { "md5": "0364c28814a0f8a05b6fb1f8ffeceb8b", "sha256": "28dfd7bc176ffffcaf4270a7c83d665fb4dd5da96e93cbf7ee63db90ce583043" }, "downloads": -1, "filename": "Velociwrapper-2.0.18.tar.gz", "has_sig": false, "md5_digest": "0364c28814a0f8a05b6fb1f8ffeceb8b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44014, "upload_time": "2017-09-19T22:26:08", "url": "https://files.pythonhosted.org/packages/40/57/33673cb7dcb9b3bcafddc111684746ef7eaf5b2f3b68ec3acdd2f30440bb/Velociwrapper-2.0.18.tar.gz" } ], "2.0.6": [ { "comment_text": "", "digests": { "md5": "ddbac7bfd2e1a8e30da8e3e0966826d7", "sha256": "f8045627eefde812f47dd45f5607e5628a67dd792452aa75cd49d42b7f0e6d9d" }, "downloads": -1, "filename": "Velociwrapper-2.0.6.tar.gz", "has_sig": false, "md5_digest": "ddbac7bfd2e1a8e30da8e3e0966826d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 41692, "upload_time": "2015-09-12T19:41:51", "url": "https://files.pythonhosted.org/packages/c0/47/e363a61a142515d65f369e42e2dc8050cd0f1461eb422bfaa8770aa9cb49/Velociwrapper-2.0.6.tar.gz" } ], "2.0.7": [ { "comment_text": "", "digests": { "md5": "705a70f4912bdc1f1e6ce9879202dd8b", "sha256": "c04edc360aec4fbd5610dece7eb8c1efccab3ba5fece9910a10a3db5e475a9da" }, "downloads": -1, "filename": "Velociwrapper-2.0.7.tar.gz", "has_sig": false, "md5_digest": "705a70f4912bdc1f1e6ce9879202dd8b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42293, "upload_time": "2015-10-29T21:18:28", "url": "https://files.pythonhosted.org/packages/8c/09/9ed5a323e0f26e7df71d46b8f6557fb848caf3eeae0817baef0dcd903e09/Velociwrapper-2.0.7.tar.gz" } ], "2.0.8": [ { "comment_text": "", "digests": { "md5": "d20716192f58ad15586c8417c84a0eb9", "sha256": "224440dfe0105671ba0fc7ce3eee553df0b9e7b06e758aedb512f9878c1e6030" }, "downloads": -1, "filename": "Velociwrapper-2.0.8.tar.gz", "has_sig": false, "md5_digest": "d20716192f58ad15586c8417c84a0eb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42402, "upload_time": "2015-11-02T21:14:16", "url": "https://files.pythonhosted.org/packages/66/3c/f34250ea12a55d8068910803764fb5e5d438973edb6660bb96b0a9709bdf/Velociwrapper-2.0.8.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "077317b278dba7c0e303f266024aff7f", "sha256": "2c6e19bdc1d852f107abb2ffd13e3fb0fbd21283b338c2a64f32e34634071a47" }, "downloads": -1, "filename": "Velociwrapper-2.1.0.tar.gz", "has_sig": false, "md5_digest": "077317b278dba7c0e303f266024aff7f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44925, "upload_time": "2019-05-07T17:41:30", "url": "https://files.pythonhosted.org/packages/2d/2e/6bcce97faf67473996b2d1727c407353cf8db912a248a07c7ee1d4fbc46a/Velociwrapper-2.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "077317b278dba7c0e303f266024aff7f", "sha256": "2c6e19bdc1d852f107abb2ffd13e3fb0fbd21283b338c2a64f32e34634071a47" }, "downloads": -1, "filename": "Velociwrapper-2.1.0.tar.gz", "has_sig": false, "md5_digest": "077317b278dba7c0e303f266024aff7f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44925, "upload_time": "2019-05-07T17:41:30", "url": "https://files.pythonhosted.org/packages/2d/2e/6bcce97faf67473996b2d1727c407353cf8db912a248a07c7ee1d4fbc46a/Velociwrapper-2.1.0.tar.gz" } ] }