pyes.es¶
-
class
pyes.es.ES(server='localhost:9200', timeout=30.0, bulk_size=400, encoder=None, decoder=None, max_retries=3, retry_time=60, default_indices=None, default_types=None, log_curl=False, dump_curl=False, model=<class 'pyes.models.ElasticSearchModel'>, basic_auth=None, raise_on_bulk_item_failure=False, document_object_field=None, bulker_class=<class 'pyes.models.ListBulker'>, cert_reqs='CERT_OPTIONAL')¶ ES connection object.
-
bulk_size¶ Get the current bulk_size
Return a int: the size of the bulk holder
-
collect_info()¶ Collect info about the connection and fill the info dictionary.
-
count(query=None, indices=None, doc_types=None, **query_params)¶ Execute a query against one or more indices and get hits count.
-
create_bulker()¶ Create a bulker object and return it to allow to manage custom bulk policies
-
create_percolator(index, name, query, **kwargs)¶ Create a percolator document
Any kwargs will be added to the document as extra properties.
-
create_river(river, river_name=None)¶ Create a river
-
decoder¶ alias of
ESJsonDecoder
-
default_indices¶
-
delete(index, doc_type, id, bulk=False, **query_params)¶ Delete a typed JSON document from a specific index based on its id. If bulk is True, the delete operation is put in bulk mode.
-
delete_by_query(indices, doc_types, query, **query_params)¶ Delete documents from one or more indices and one or more types based on a query.
-
delete_percolator(index, name)¶ Delete a percolator document
-
delete_river(river, river_name=None)¶ Delete a river
-
delete_warmer(doc_types=None, indices=None, name=None, querystring_args=None)¶ Retrieve warmer
Parameters: - doc_types – list of document types
- warmer – anything with
serializemethod or a dictionary - name – warmer name. If not provided, all warmers for given indices will be deleted
- querystring_args – additional arguments passed as GET params to ES
-
encode_json(serializable)¶ Serialize to json a serializable object (Search, Query, Filter, etc).
-
encoder¶ alias of
ESJsonEncoder
-
ensure_index(index, mappings=None, settings=None, clear=False)¶ Ensure if an index with mapping exists
-
exists(index, doc_type, id, **query_params)¶ Return if a document exists
-
factory_object(index, doc_type, data=None, id=None)¶ Create a stub object to be manipulated
-
flush_bulk(forced=False)¶ Send pending operations if forced or if the bulk threshold is exceeded.
-
force_bulk()¶ Force executing of all bulk data.
Return the bulk response
-
get(index, doc_type, id, fields=None, model=None, **query_params)¶ Get a typed JSON document from an index based on its id.
-
get_file(index, doc_type, id=None)¶ Return the filename and memory data stream
-
get_warmer(doc_types=None, indices=None, name=None, querystring_args=None)¶ Retrieve warmer
Parameters: - doc_types – list of document types
- warmer – anything with
serializemethod or a dictionary - name – warmer name. If not provided, all warmers will be returned
- querystring_args – additional arguments passed as GET params to ES
-
index(doc, index, doc_type, id=None, parent=None, force_insert=False, op_type=None, bulk=False, version=None, querystring_args=None, ttl=None)¶ Index a typed JSON document into a specific index and make it searchable.
-
index_raw_bulk(header, document)¶ Function helper for fast inserting
Parameters: - header – a string with the bulk header must be ended with a newline
- header – a json document string must be ended with a newline
-
mappings¶
-
mget(ids, index=None, doc_type=None, **query_params)¶ Get multi JSON documents.
- ids can be:
- list of tuple: (index, type, id) list of ids: index and doc_type are required
-
morelikethis(index, doc_type, id, fields, **query_params)¶ Execute a “more like this” search query against one or more fields and get back search hits.
-
partial_update(index, doc_type, id, doc=None, script=None, params=None, upsert=None, querystring_args=None)¶ Partially update a document with a script
-
percolate(index, doc_types, query)¶ Match a query with a document
-
put_file(filename, index, doc_type, id=None, name=None)¶ Store a file in a index
-
put_warmer(doc_types=None, indices=None, name=None, warmer=None, querystring_args=None)¶ Put new warmer into index (or type)
Parameters: - doc_types – list of document types
- warmer – anything with
serializemethod or a dictionary - name – warmer name
- querystring_args – additional arguments passed as GET params to ES
-
raise_on_bulk_item_failure¶ Get the raise_on_bulk_item_failure status
Return a bool: the status of raise_on_bulk_item_failure
-
search(query, indices=None, doc_types=None, model=None, scan=False, headers=None, **query_params)¶ Execute a search against one or more indices to get the resultset.
query must be a Search object, a Query object, or a custom dictionary of search parameters using the query DSL to be passed directly.
-
search_multi(queries, indices_list=None, doc_types_list=None, routing_list=None, search_type_list=None, models=None, scans=None)¶
-
search_raw(query, indices=None, doc_types=None, headers=None, **query_params)¶ Execute a search against one or more indices to get the search hits.
query must be a Search object, a Query object, or a custom dictionary of search parameters using the query DSL to be passed directly.
-
search_raw_multi(queries, indices_list=None, doc_types_list=None, routing_list=None, search_type_list=None)¶
-
search_scroll(scroll_id, scroll='10m')¶ Executes a scrolling given an scroll_id
-
suggest(name, text, field, type='term', size=None, params=None, **kwargs)¶ Execute suggester of given type.
Parameters: - name – name for the suggester
- text – text to search for
- field – field to search
- type – One of: completion, phrase, term
- size – number of results
- params – additional suggester params
- kwargs –
Returns:
-
suggest_from_object(suggest, indices=None, preference=None, routing=None, raw=False, **kwargs)¶
-
update(index, doc_type, id, script=None, lang='mvel', params=None, document=None, upsert=None, model=None, bulk=False, querystring_args=None, retry_on_conflict=None, routing=None, doc_as_upsert=None)¶
-
update_by_function(extra_doc, index, doc_type, id, querystring_args=None, update_func=None, attempts=2)¶ Update an already indexed typed JSON document.
The update happens client-side, i.e. the current document is retrieved, updated locally and finally pushed to the server. This may repeat up to
attemptstimes in case of version conflicts.Parameters: - update_func – A callable
update_func(current_doc, extra_doc)that computes and returns the updated doc. Alternatively it may updatecurrent_docin place and return None. The defaultupdate_funcisdict.update. - attempts – How many times to retry in case of version conflict.
- update_func – A callable
-
update_mapping_meta(doc_type, values, indices=None)¶ Update mapping meta :param doc_type: a doc type or a list of doctypes :param values: the dict of meta :param indices: a list of indices :return:
-
validate_types(types=None)¶ Return a valid list of types.
types may be a string or a list of strings. If types is not supplied, returns the default_types.
-
-
class
pyes.es.ESJsonDecoder(*args, **kwargs)¶ -
dict_to_object(d)¶ Decode datetime value from string to datetime
-
string_to_datetime(obj)¶ Decode a datetime string to a datetime object
-
-
class
pyes.es.ESJsonEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, item_sort_key=None, for_json=False, ignore_nan=False, int_as_string_bitcount=None, iterable_as_array=False)¶ -
default(value)¶ Convert rogue and mysterious data types. Conversion notes:
datetime.dateanddatetime.datetimeobjects are
converted into datetime strings.
-
-
class
pyes.es.ResultSet(connection, search, indices=None, doc_types=None, query_params=None, headers=None, auto_fix_keys=False, auto_clean_highlight=False, model=None)¶ -
aggs¶
-
clean_highlight()¶ Remove the empty highlight
-
count()¶
-
facets¶
-
fix_aggs()¶ This function convert date_histogram aggs to datetime
-
fix_facets()¶ This function convert date_histogram facets to datetime
-
fix_keys()¶ Remove the _ from the keys of the results
-
get_suggested_texts()¶
-
max_score¶
-
next()¶
-
total¶
-
-
class
pyes.es.ResultSetMulti(connection, searches, indices_list=None, doc_types_list=None, routing_list=None, search_type_list=None, models=None)¶ -
next()¶
-
-
pyes.es.expand_suggest_text(suggest)¶
-
pyes.es.file_to_attachment(filename, filehandler=None)¶ Convert a file to attachment
-
pyes.es.get_id(text)¶