Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def from_function(cls, func):
if not isinstance(func, types.FunctionType):
raise TypeError("{!r} is not a Python function".format(func))
Parameter = cls._parameter_cls
# Parameter information.
func_code = func.__code__
... | [
"Constructs Signature for the given python function"
] |
Please provide a description of the function:def replace(self, parameters=_void, return_annotation=_void):
if parameters is _void:
parameters = self.parameters.values()
if return_annotation is _void:
return_annotation = self._return_annotation
return type(self... | [
"Creates a customized copy of the Signature.\n Pass 'parameters' and/or 'return_annotation' arguments\n to override them in the new copy.\n "
] |
Please provide a description of the function:def _bind(self, args, kwargs, partial=False):
arguments = OrderedDict()
parameters = iter(self.parameters.values())
parameters_ex = ()
arg_vals = iter(args)
if partial:
# Support for binding arguments to 'functo... | [
"Private method. Don't use directly."
] |
Please provide a description of the function:def bind_partial(self, *args, **kwargs):
return self._bind(args, kwargs, partial=True) | [
"Get a BoundArguments object, that partially maps the\n passed `args` and `kwargs` to the function's signature.\n Raises `TypeError` if the passed arguments can not be bound.\n "
] |
Please provide a description of the function:def is_node(objecttype):
if not isclass(objecttype):
return False
if not issubclass(objecttype, ObjectType):
return False
for i in objecttype._meta.interfaces:
if issubclass(i, Node):
return True
return False | [
"\n Check if the given objecttype has Node as an interface\n "
] |
Please provide a description of the function:def get_complete_version(version=None):
if version is None:
from graphene import VERSION as version
else:
assert len(version) == 5
assert version[3] in ("alpha", "beta", "rc", "final")
return version | [
"Returns a tuple of the graphene version. If version argument is non-empty,\n then checks for correctness of the tuple provided.\n "
] |
Please provide a description of the function:def maybe_thenable(obj, on_resolve):
if isawaitable(obj) and not isinstance(obj, Promise):
return await_and_execute(obj, on_resolve)
if is_thenable(obj):
return Promise.resolve(obj).then(on_resolve)
# If it's not awaitable not a Promise, re... | [
"\n Execute a on_resolve function once the thenable is resolved,\n returning the same type of object inputed.\n If the object is not thenable, it should return on_resolve(obj)\n "
] |
Please provide a description of the function:def get_field_as(value, _as=None):
if isinstance(value, MountedType):
return value
elif isinstance(value, UnmountedType):
if _as is None:
return value
return _as.mounted(value) | [
"\n Get type mounted\n "
] |
Please provide a description of the function:def yank_fields_from_attrs(attrs, _as=None, sort=True):
fields_with_names = []
for attname, value in list(attrs.items()):
field = get_field_as(value, _as)
if not field:
continue
fields_with_names.append((attname, field))
... | [
"\n Extract all the fields in given attributes (dict)\n and return them ordered\n "
] |
Please provide a description of the function:def import_string(dotted_path, dotted_attributes=None):
try:
module_path, class_name = dotted_path.rsplit(".", 1)
except ValueError:
raise ImportError("%s doesn't look like a module path" % dotted_path)
module = import_module(module_path)
... | [
"\n Import a dotted module path and return the attribute/class designated by the\n last name in the path. When a dotted attribute path is also provided, the\n dotted attribute path would be applied to the attribute/class retrieved from\n the first step, and return the corresponding value designated by t... |
Please provide a description of the function:def scan_aggs(search, source_aggs, inner_aggs={}, size=10):
def run_search(**kwargs):
s = search[:0]
s.aggs.bucket('comp', 'composite', sources=source_aggs, size=size, **kwargs)
for agg_name, agg in inner_aggs.items():
s.aggs['com... | [
"\n Helper function used to iterate over all possible bucket combinations of\n ``source_aggs``, returning results of ``inner_aggs`` for each. Uses the\n ``composite`` aggregation under the hood to perform this.\n "
] |
Please provide a description of the function:def clean(self):
self.suggest = {
'input': [' '.join(p) for p in permutations(self.name.split())],
'weight': self.popularity
} | [
"\n Automatically construct the suggestion input and weight by taking all\n possible permutation of Person's name as ``input`` and taking their\n popularity as ``weight``.\n "
] |
Please provide a description of the function:def __list_fields(cls):
for name in cls._doc_type.mapping:
field = cls._doc_type.mapping[name]
yield name, field, False
if hasattr(cls.__class__, '_index'):
if not cls._index._mapping:
return
... | [
"\n Get all the fields defined for our class, if we have an Index, try\n looking at the index mappings as well, mark the fields from Index as\n optional.\n "
] |
Please provide a description of the function:def _clone(self):
ubq = super(UpdateByQuery, self)._clone()
ubq._response_class = self._response_class
ubq._script = self._script.copy()
ubq.query._proxied = self.query._proxied
return ubq | [
"\n Return a clone of the current search request. Performs a shallow copy\n of all the underlying objects. Used internally by most state modifying\n APIs.\n "
] |
Please provide a description of the function:def response_class(self, cls):
ubq = self._clone()
ubq._response_class = cls
return ubq | [
"\n Override the default wrapper used for the response.\n "
] |
Please provide a description of the function:def update_from_dict(self, d):
d = d.copy()
if 'query' in d:
self.query._proxied = Q(d.pop('query'))
if 'script' in d:
self._script = d.pop('script')
self._extra = d
return self | [
"\n Apply options from a serialized body to the current instance. Modifies\n the object in-place. Used mostly by ``from_dict``.\n "
] |
Please provide a description of the function:def script(self, **kwargs):
ubq = self._clone()
if ubq._script:
ubq._script = {}
ubq._script.update(kwargs)
return ubq | [
"\n Define update action to take:\n https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html\n for more details.\n\n Note: the API only accepts a single script, so calling the script multiple times will overwrite.\n\n Example::\n\n ub... |
Please provide a description of the function:def to_dict(self, **kwargs):
d = {}
if self.query:
d["query"] = self.query.to_dict()
if self._script:
d['script'] = self._script
d.update(self._extra)
d.update(kwargs)
return d | [
"\n Serialize the search into the dictionary that will be sent over as the\n request'ubq body.\n\n All additional keyword arguments will be included into the dictionary.\n "
] |
Please provide a description of the function:def execute(self):
es = connections.get_connection(self._using)
self._response = self._response_class(
self,
es.update_by_query(
index=self._index,
body=self.to_dict(),
**self._... | [
"\n Execute the search and return an instance of ``Response`` wrapping all\n the data.\n "
] |
Please provide a description of the function:def _collect_fields(self):
for f in itervalues(self.properties.to_dict()):
yield f
# multi fields
if hasattr(f, 'fields'):
for inner_f in itervalues(f.fields.to_dict()):
yield inner_f
... | [
" Iterate over all Field objects within, including multi fields. "
] |
Please provide a description of the function:def clone(self, name=None, using=None):
i = Index(name or self._name, using=using or self._using)
i._settings = self._settings.copy()
i._aliases = self._aliases.copy()
i._analysis = self._analysis.copy()
i._doc_types = self._d... | [
"\n Create a copy of the instance with another name or connection alias.\n Useful for creating multiple indices with shared configuration::\n\n i = Index('base-index')\n i.settings(number_of_shards=1)\n i.create()\n\n i2 = i.clone('other-index')\n ... |
Please provide a description of the function:def document(self, document):
self._doc_types.append(document)
# If the document index does not have any name, that means the user
# did not set any index already to the document.
# So set this index as document index
if docu... | [
"\n Associate a :class:`~elasticsearch_dsl.Document` subclass with an index.\n This means that, when this index is created, it will contain the\n mappings for the ``Document``. If the ``Document`` class doesn't have a\n default index yet (by defining ``class Index``), this instance will ... |
Please provide a description of the function:def analyzer(self, *args, **kwargs):
analyzer = analysis.analyzer(*args, **kwargs)
d = analyzer.get_analysis_definition()
# empty custom analyzer, probably already defined out of our control
if not d:
return
# mer... | [
"\n Explicitly add an analyzer to an index. Note that all custom analyzers\n defined in mappings will also be created. This is useful for search analyzers.\n\n Example::\n\n from elasticsearch_dsl import analyzer, tokenizer\n\n my_analyzer = analyzer('my_analyzer',\n ... |
Please provide a description of the function:def search(self, using=None):
return Search(
using=using or self._using,
index=self._name,
doc_type=self._doc_types
) | [
"\n Return a :class:`~elasticsearch_dsl.Search` object searching over the\n index (or all the indices belonging to this template) and its\n ``Document``\\\\s.\n "
] |
Please provide a description of the function:def updateByQuery(self, using=None):
return UpdateByQuery(
using=using or self._using,
index=self._name,
) | [
"\n Return a :class:`~elasticsearch_dsl.UpdateByQuery` object searching over the index\n (or all the indices belonging to this template) and updating Documents that match\n the search criteria.\n\n For more information, see here:\n https://www.elastic.co/guide/en/elasticsearch/ref... |
Please provide a description of the function:def create(self, using=None, **kwargs):
self._get_connection(using).indices.create(index=self._name, body=self.to_dict(), **kwargs) | [
"\n Creates the index in elasticsearch.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.create`` unchanged.\n "
] |
Please provide a description of the function:def save(self, using=None):
if not self.exists(using=using):
return self.create(using=using)
body = self.to_dict()
settings = body.pop('settings', {})
analysis = settings.pop('analysis', None)
current_settings = s... | [
"\n Sync the index definition with elasticsearch, creating the index if it\n doesn't exist and updating its settings and mappings if it does.\n\n Note some settings and mapping changes cannot be done on an open\n index (or at all on an existing index) and for those this method will\n ... |
Please provide a description of the function:def analyze(self, using=None, **kwargs):
return self._get_connection(using).indices.analyze(index=self._name, **kwargs) | [
"\n Perform the analysis process on a text and return the tokens breakdown\n of the text.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.analyze`` unchanged.\n "
] |
Please provide a description of the function:def refresh(self, using=None, **kwargs):
return self._get_connection(using).indices.refresh(index=self._name, **kwargs) | [
"\n Preforms a refresh operation on the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.refresh`` unchanged.\n "
] |
Please provide a description of the function:def flush(self, using=None, **kwargs):
return self._get_connection(using).indices.flush(index=self._name, **kwargs) | [
"\n Preforms a flush operation on the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.flush`` unchanged.\n "
] |
Please provide a description of the function:def get(self, using=None, **kwargs):
return self._get_connection(using).indices.get(index=self._name, **kwargs) | [
"\n The get index API allows to retrieve information about the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get`` unchanged.\n "
] |
Please provide a description of the function:def open(self, using=None, **kwargs):
return self._get_connection(using).indices.open(index=self._name, **kwargs) | [
"\n Opens the index in elasticsearch.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.open`` unchanged.\n "
] |
Please provide a description of the function:def close(self, using=None, **kwargs):
return self._get_connection(using).indices.close(index=self._name, **kwargs) | [
"\n Closes the index in elasticsearch.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.close`` unchanged.\n "
] |
Please provide a description of the function:def delete(self, using=None, **kwargs):
return self._get_connection(using).indices.delete(index=self._name, **kwargs) | [
"\n Deletes the index in elasticsearch.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.delete`` unchanged.\n "
] |
Please provide a description of the function:def exists(self, using=None, **kwargs):
return self._get_connection(using).indices.exists(index=self._name, **kwargs) | [
"\n Returns ``True`` if the index already exists in elasticsearch.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.exists`` unchanged.\n "
] |
Please provide a description of the function:def exists_type(self, using=None, **kwargs):
return self._get_connection(using).indices.exists_type(index=self._name, **kwargs) | [
"\n Check if a type/types exists in the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.exists_type`` unchanged.\n "
] |
Please provide a description of the function:def put_mapping(self, using=None, **kwargs):
return self._get_connection(using).indices.put_mapping(index=self._name, **kwargs) | [
"\n Register specific mapping definition for a specific type.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.put_mapping`` unchanged.\n "
] |
Please provide a description of the function:def get_mapping(self, using=None, **kwargs):
return self._get_connection(using).indices.get_mapping(index=self._name, **kwargs) | [
"\n Retrieve specific mapping definition for a specific type.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get_mapping`` unchanged.\n "
] |
Please provide a description of the function:def get_field_mapping(self, using=None, **kwargs):
return self._get_connection(using).indices.get_field_mapping(index=self._name, **kwargs) | [
"\n Retrieve mapping definition of a specific field.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get_field_mapping`` unchanged.\n "
] |
Please provide a description of the function:def put_alias(self, using=None, **kwargs):
return self._get_connection(using).indices.put_alias(index=self._name, **kwargs) | [
"\n Create an alias for the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.put_alias`` unchanged.\n "
] |
Please provide a description of the function:def exists_alias(self, using=None, **kwargs):
return self._get_connection(using).indices.exists_alias(index=self._name, **kwargs) | [
"\n Return a boolean indicating whether given alias exists for this index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.exists_alias`` unchanged.\n "
] |
Please provide a description of the function:def get_alias(self, using=None, **kwargs):
return self._get_connection(using).indices.get_alias(index=self._name, **kwargs) | [
"\n Retrieve a specified alias.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get_alias`` unchanged.\n "
] |
Please provide a description of the function:def delete_alias(self, using=None, **kwargs):
return self._get_connection(using).indices.delete_alias(index=self._name, **kwargs) | [
"\n Delete specific alias.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.delete_alias`` unchanged.\n "
] |
Please provide a description of the function:def get_settings(self, using=None, **kwargs):
return self._get_connection(using).indices.get_settings(index=self._name, **kwargs) | [
"\n Retrieve settings for the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get_settings`` unchanged.\n "
] |
Please provide a description of the function:def put_settings(self, using=None, **kwargs):
return self._get_connection(using).indices.put_settings(index=self._name, **kwargs) | [
"\n Change specific index level settings in real time.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.put_settings`` unchanged.\n "
] |
Please provide a description of the function:def stats(self, using=None, **kwargs):
return self._get_connection(using).indices.stats(index=self._name, **kwargs) | [
"\n Retrieve statistics on different operations happening on the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.stats`` unchanged.\n "
] |
Please provide a description of the function:def segments(self, using=None, **kwargs):
return self._get_connection(using).indices.segments(index=self._name, **kwargs) | [
"\n Provide low level segments information that a Lucene index (shard\n level) is built with.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.segments`` unchanged.\n "
] |
Please provide a description of the function:def validate_query(self, using=None, **kwargs):
return self._get_connection(using).indices.validate_query(index=self._name, **kwargs) | [
"\n Validate a potentially expensive query without executing it.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.validate_query`` unchanged.\n "
] |
Please provide a description of the function:def clear_cache(self, using=None, **kwargs):
return self._get_connection(using).indices.clear_cache(index=self._name, **kwargs) | [
"\n Clear all caches or specific cached associated with the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.clear_cache`` unchanged.\n "
] |
Please provide a description of the function:def recovery(self, using=None, **kwargs):
return self._get_connection(using).indices.recovery(index=self._name, **kwargs) | [
"\n The indices recovery API provides insight into on-going shard\n recoveries for the index.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.recovery`` unchanged.\n "
] |
Please provide a description of the function:def upgrade(self, using=None, **kwargs):
return self._get_connection(using).indices.upgrade(index=self._name, **kwargs) | [
"\n Upgrade the index to the latest format.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.upgrade`` unchanged.\n "
] |
Please provide a description of the function:def get_upgrade(self, using=None, **kwargs):
return self._get_connection(using).indices.get_upgrade(index=self._name, **kwargs) | [
"\n Monitor how much of the index is upgraded.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.get_upgrade`` unchanged.\n "
] |
Please provide a description of the function:def flush_synced(self, using=None, **kwargs):
return self._get_connection(using).indices.flush_synced(index=self._name, **kwargs) | [
"\n Perform a normal flush, then add a generated unique marker (sync_id) to\n all shards.\n\n Any additional keyword arguments will be passed to\n ``Elasticsearch.indices.flush_synced`` unchanged.\n "
] |
Please provide a description of the function:def shard_stores(self, using=None, **kwargs):
return self._get_connection(using).indices.shard_stores(index=self._name, **kwargs) | [
"\n Provides store information for shard copies of the index. Store\n information reports on which nodes shard copies exist, the shard copy\n version, indicating how recent they are, and any exceptions encountered\n while opening the shard index or from earlier engine failure.\n\n ... |
Please provide a description of the function:def forcemerge(self, using=None, **kwargs):
return self._get_connection(using).indices.forcemerge(index=self._name, **kwargs) | [
"\n The force merge API allows to force merging of the index through an\n API. The merge relates to the number of segments a Lucene index holds\n within each shard. The force merge operation allows to reduce the\n number of segments by merging them.\n\n This call will block until ... |
Please provide a description of the function:def shrink(self, using=None, **kwargs):
return self._get_connection(using).indices.shrink(index=self._name, **kwargs) | [
"\n The shrink index API allows you to shrink an existing index into a new\n index with fewer primary shards. The number of primary shards in the\n target index must be a factor of the shards in the source index. For\n example an index with 8 primary shards can be shrunk into 4, 2 or 1\n... |
Please provide a description of the function:def configure(self, **kwargs):
for k in list(self._conns):
# try and preserve existing client to keep the persistent connections alive
if k in self._kwargs and kwargs.get(k, None) == self._kwargs[k]:
continue
... | [
"\n Configure multiple connections at once, useful for passing in config\n dictionaries obtained from other sources, like Django's settings or a\n configuration management tool.\n\n Example::\n\n connections.configure(\n default={'hosts': 'localhost'},\n ... |
Please provide a description of the function:def remove_connection(self, alias):
errors = 0
for d in (self._conns, self._kwargs):
try:
del d[alias]
except KeyError:
errors += 1
if errors == 2:
raise KeyError('There is ... | [
"\n Remove connection from the registry. Raises ``KeyError`` if connection\n wasn't found.\n "
] |
Please provide a description of the function:def create_connection(self, alias='default', **kwargs):
kwargs.setdefault('serializer', serializer)
conn = self._conns[alias] = Elasticsearch(**kwargs)
return conn | [
"\n Construct an instance of ``elasticsearch.Elasticsearch`` and register\n it under given alias.\n "
] |
Please provide a description of the function:def get_connection(self, alias='default'):
# do not check isinstance(Elasticsearch) so that people can wrap their
# clients
if not isinstance(alias, string_types):
return alias
# connection already established
try... | [
"\n Retrieve a connection, construct it if necessary (only configuration\n was passed to us). If a non-string alias has been passed through we\n assume it's already a client instance and will just return it as-is.\n\n Raises ``KeyError`` if no client (or its definition) is registered\n ... |
Please provide a description of the function:def setup():
# create an index template
index_template = BlogPost._index.as_template(ALIAS, PATTERN)
# upload the template into elasticsearch
# potentially overriding the one already there
index_template.save()
# create the first index if it doe... | [
"\n Create the index template in elasticsearch specifying the mappings and any\n settings to be used. This can be run at any time, ideally at every new code\n deploy.\n "
] |
Please provide a description of the function:def migrate(move_data=True, update_alias=True):
# construct a new index name by appending current timestamp
next_index = PATTERN.replace('*', datetime.now().strftime('%Y%m%d%H%M%S%f'))
# get the low level connection
es = connections.get_connection()
... | [
"\n Upgrade function that creates a new index for the data. Optionally it also can\n (and by default will) reindex previous copy of the data into the new index\n (specify ``move_data=False`` to skip this step) and update the alias to\n point to the latest index (set ``update_alias=False`` to skip).\n\n ... |
Please provide a description of the function:def simulate(self, text, using='default', explain=False, attributes=None):
es = connections.get_connection(using)
body = {'text': text, 'explain': explain}
if attributes:
body['attributes'] = attributes
definition = self... | [
"\n Use the Analyze API of elasticsearch to test the outcome of this analyzer.\n\n :arg text: Text to be analyzed\n :arg using: connection alias to use, defaults to ``'default'``\n :arg explain: will output all token attributes for each token. You can\n filter token attributes... |
Please provide a description of the function:def get_answers(self):
if 'inner_hits' in self.meta and 'answer' in self.meta.inner_hits:
return self.meta.inner_hits.answer.hits
return list(self.search_answers()) | [
"\n Get answers either from inner_hits already present or by searching\n elasticsearch.\n "
] |
Please provide a description of the function:def get_aggregation(self):
agg = A(self.agg_type, **self._params)
if self._metric:
agg.metric('metric', self._metric)
return agg | [
"\n Return the aggregation object.\n "
] |
Please provide a description of the function:def add_filter(self, filter_values):
if not filter_values:
return
f = self.get_value_filter(filter_values[0])
for v in filter_values[1:]:
f |= self.get_value_filter(v)
return f | [
"\n Construct a filter.\n "
] |
Please provide a description of the function:def get_values(self, data, filter_values):
out = []
for bucket in data.buckets:
key = self.get_value(bucket)
out.append((
key,
self.get_metric(bucket),
self.is_filtered(key, filt... | [
"\n Turn the raw bucket data into a list of tuples containing the key,\n number of documents and a flag indicating whether this value has been\n selected or not.\n "
] |
Please provide a description of the function:def add_filter(self, name, filter_values):
# normalize the value into a list
if not isinstance(filter_values, (tuple, list)):
if filter_values is None:
return
filter_values = [filter_values, ]
# rememb... | [
"\n Add a filter for a facet.\n "
] |
Please provide a description of the function:def search(self):
s = Search(doc_type=self.doc_types, index=self.index, using=self.using)
return s.response_class(FacetedResponse) | [
"\n Returns the base Search object to which the facets are added.\n\n You can customize the query by overriding this method and returning a\n modified search object.\n "
] |
Please provide a description of the function:def query(self, search, query):
if query:
if self.fields:
return search.query('multi_match', fields=self.fields, query=query)
else:
return search.query('multi_match', query=query)
return search | [
"\n Add query part to ``search``.\n\n Override this if you wish to customize the query used.\n "
] |
Please provide a description of the function:def aggregate(self, search):
for f, facet in iteritems(self.facets):
agg = facet.get_aggregation()
agg_filter = MatchAll()
for field, filter in iteritems(self._filters):
if f == field:
c... | [
"\n Add aggregations representing the facets selected, including potential\n filters.\n "
] |
Please provide a description of the function:def filter(self, search):
if not self._filters:
return search
post_filter = MatchAll()
for f in itervalues(self._filters):
post_filter &= f
return search.post_filter(post_filter) | [
"\n Add a ``post_filter`` to the search request narrowing the results based\n on the facet filters.\n "
] |
Please provide a description of the function:def highlight(self, search):
return search.highlight(*(f if '^' not in f else f.split('^', 1)[0]
for f in self.fields)) | [
"\n Add highlighting for all the fields\n "
] |
Please provide a description of the function:def sort(self, search):
if self._sort:
search = search.sort(*self._sort)
return search | [
"\n Add sorting information to the request.\n "
] |
Please provide a description of the function:def build_search(self):
s = self.search()
s = self.query(s, self._query)
s = self.filter(s)
if self.fields:
s = self.highlight(s)
s = self.sort(s)
self.aggregate(s)
return s | [
"\n Construct the ``Search`` object.\n "
] |
Please provide a description of the function:def execute(self):
r = self._s.execute()
r._faceted_search = self
return r | [
"\n Execute the search and return the response.\n "
] |
Please provide a description of the function:def params(self, **kwargs):
s = self._clone()
s._params.update(kwargs)
return s | [
"\n Specify query params to be used when executing the search. All the\n keyword arguments will override the current values. See\n https://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.search\n for all available parameters.\n\n Example::\n\n ... |
Please provide a description of the function:def index(self, *index):
# .index() resets
s = self._clone()
if not index:
s._index = None
else:
indexes = []
for i in index:
if isinstance(i, string_types):
inde... | [
"\n Set the index for the search. If called empty it will remove all information.\n\n Example:\n\n s = Search()\n s = s.index('twitter-2015.01.01', 'twitter-2015.01.02')\n s = s.index(['twitter-2015.01.01', 'twitter-2015.01.02'])\n "
] |
Please provide a description of the function:def doc_type(self, *doc_type, **kwargs):
# .doc_type() resets
s = self._clone()
if not doc_type and not kwargs:
s._doc_type = []
s._doc_type_map = {}
else:
s._doc_type.extend(doc_type)
s... | [
"\n Set the type to search through. You can supply a single value or\n multiple. Values can be strings or subclasses of ``Document``.\n\n You can also pass in any keyword arguments, mapping a doc_type to a\n callback that should be used instead of the Hit class.\n\n If no doc_type... |
Please provide a description of the function:def using(self, client):
s = self._clone()
s._using = client
return s | [
"\n Associate the search request with an elasticsearch client. A fresh copy\n will be returned with current instance remaining unchanged.\n\n :arg client: an instance of ``elasticsearch.Elasticsearch`` to use or\n an alias to look up in ``elasticsearch_dsl.connections``\n\n "
... |
Please provide a description of the function:def extra(self, **kwargs):
s = self._clone()
if 'from_' in kwargs:
kwargs['from'] = kwargs.pop('from_')
s._extra.update(kwargs)
return s | [
"\n Add extra keys to the request body. Mostly here for backwards\n compatibility.\n "
] |
Please provide a description of the function:def _clone(self):
s = super(Search, self)._clone()
s._response_class = self._response_class
s._sort = self._sort[:]
s._source = copy.copy(self._source) \
if self._source is not None else None
s._highlight = self._... | [
"\n Return a clone of the current search request. Performs a shallow copy\n of all the underlying objects. Used internally by most state modifying\n APIs.\n "
] |
Please provide a description of the function:def response_class(self, cls):
s = self._clone()
s._response_class = cls
return s | [
"\n Override the default wrapper used for the response.\n "
] |
Please provide a description of the function:def update_from_dict(self, d):
d = d.copy()
if 'query' in d:
self.query._proxied = Q(d.pop('query'))
if 'post_filter' in d:
self.post_filter._proxied = Q(d.pop('post_filter'))
aggs = d.pop('aggs', d.pop('aggre... | [
"\n Apply options from a serialized body to the current instance. Modifies\n the object in-place. Used mostly by ``from_dict``.\n "
] |
Please provide a description of the function:def script_fields(self, **kwargs):
s = self._clone()
for name in kwargs:
if isinstance(kwargs[name], string_types):
kwargs[name] = {'script': kwargs[name]}
s._script_fields.update(kwargs)
return s | [
"\n Define script fields to be calculated on hits. See\n https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html\n for more details.\n\n Example::\n\n s = Search()\n s = s.script_fields(times_two=\"doc['field'].value * 2\")\... |
Please provide a description of the function:def source(self, fields=None, **kwargs):
s = self._clone()
if fields and kwargs:
raise ValueError("You cannot specify fields and kwargs at the same time.")
if fields is not None:
s._source = fields
return... | [
"\n Selectively control how the _source field is returned.\n\n :arg fields: wildcard string, array of wildcards, or dictionary of includes and excludes\n\n If ``fields`` is None, the entire document will be returned for\n each hit. If fields is a dictionary with keys of 'include' and/or... |
Please provide a description of the function:def sort(self, *keys):
s = self._clone()
s._sort = []
for k in keys:
if isinstance(k, string_types) and k.startswith('-'):
if k[1:] == '_score':
raise IllegalOperation('Sorting by `-_score` is n... | [
"\n Add sorting information to the search request. If called without\n arguments it will remove all sort requirements. Otherwise it will\n replace them. Acceptable arguments are::\n\n 'some.field'\n '-some.other.field'\n {'different.field': {'any': 'dict'}}\n\n ... |
Please provide a description of the function:def highlight_options(self, **kwargs):
s = self._clone()
s._highlight_opts.update(kwargs)
return s | [
"\n Update the global highlighting options used for this request. For\n example::\n\n s = Search()\n s = s.highlight_options(order='score')\n "
] |
Please provide a description of the function:def highlight(self, *fields, **kwargs):
s = self._clone()
for f in fields:
s._highlight[f] = kwargs
return s | [
"\n Request highlighting of some fields. All keyword arguments passed in will be\n used as parameters for all the fields in the ``fields`` parameter. Example::\n\n Search().highlight('title', 'body', fragment_size=50)\n\n will produce the equivalent of::\n\n {\n ... |
Please provide a description of the function:def suggest(self, name, text, **kwargs):
s = self._clone()
s._suggest[name] = {'text': text}
s._suggest[name].update(kwargs)
return s | [
"\n Add a suggestions request to the search.\n\n :arg name: name of the suggestion\n :arg text: text to suggest on\n\n All keyword arguments will be added to the suggestions body. For example::\n\n s = Search()\n s = s.suggest('suggestion-1', 'Elasticsearch', term={... |
Please provide a description of the function:def to_dict(self, count=False, **kwargs):
d = {}
if self.query:
d["query"] = self.query.to_dict()
# count request doesn't care for sorting and other things
if not count:
if self.post_filter:
d... | [
"\n Serialize the search into the dictionary that will be sent over as the\n request's body.\n\n :arg count: a flag to specify if we are interested in a body for count -\n no aggregations, no pagination bounds etc.\n\n All additional keyword arguments will be included into the... |
Please provide a description of the function:def count(self):
if hasattr(self, '_response'):
return self._response.hits.total
es = connections.get_connection(self._using)
d = self.to_dict(count=True)
# TODO: failed shards detection
return es.count(
... | [
"\n Return the number of hits matching the query and filters. Note that\n only the actual number is returned.\n "
] |
Please provide a description of the function:def execute(self, ignore_cache=False):
if ignore_cache or not hasattr(self, '_response'):
es = connections.get_connection(self._using)
self._response = self._response_class(
self,
es.search(
... | [
"\n Execute the search and return an instance of ``Response`` wrapping all\n the data.\n\n :arg ignore_cache: if set to ``True``, consecutive calls will hit\n ES, while cached result will be ignored. Defaults to `False`\n "
] |
Please provide a description of the function:def scan(self):
es = connections.get_connection(self._using)
for hit in scan(
es,
query=self.to_dict(),
index=self._index,
**self._params
):
yield self._get_result(h... | [
"\n Turn the search into a scan search and return a generator that will\n iterate over all the documents matching the query.\n\n Use ``params`` method to specify any additional arguments you with to\n pass to the underlying ``scan`` helper from ``elasticsearch-py`` -\n https://ela... |
Please provide a description of the function:def delete(self):
es = connections.get_connection(self._using)
return AttrDict(
es.delete_by_query(
index=self._index,
body=self.to_dict(),
**self._params
)
) | [
"\n delete() executes the query by delegating to delete_by_query()\n "
] |
Please provide a description of the function:def add(self, search):
ms = self._clone()
ms._searches.append(search)
return ms | [
"\n Adds a new :class:`~elasticsearch_dsl.Search` object to the request::\n\n ms = MultiSearch(index='my-index')\n ms = ms.add(Search(doc_type=Category).filter('term', category='python'))\n ms = ms.add(Search(doc_type=Blog))\n "
] |
Please provide a description of the function:def execute(self, ignore_cache=False, raise_on_error=True):
if ignore_cache or not hasattr(self, '_response'):
es = connections.get_connection(self._using)
responses = es.msearch(
index=self._index,
bo... | [
"\n Execute the multi search request and return a list of search results.\n "
] |
Please provide a description of the function:def make_tarball(
base_name,
base_dir,
compress="gzip",
verbose=0,
dry_run=0,
owner=None,
group=None,
):
# XXX GNU tar 1.13 has a nifty option to add a prefix directory.
# It's pretty new, though, so we certainly can't require it --
... | [
"Create a tar file from all the files under 'base_dir'.\n This file may be compressed.\n\n :param compress: Compression algorithms. Supported algorithms are:\n 'gzip': (the default)\n 'compress'\n 'bzip2'\n None\n For 'gzip' and 'bzip2' the internal tarfile module will be used.\... |
Please provide a description of the function:def start_kex(self):
self._generate_x()
if self.transport.server_mode:
# compute f = g^x mod p, but don't send it yet
self.f = pow(self.G, self.x, self.P)
self.transport._expect_packet(MSG_KEXGSS_INIT)
... | [
"\n Start the GSS-API / SSPI Authenticated Diffie-Hellman Key Exchange.\n "
] |
Please provide a description of the function:def parse_next(self, ptype, m):
if self.transport.server_mode and (ptype == MSG_KEXGSS_INIT):
return self._parse_kexgss_init(m)
elif not self.transport.server_mode and (ptype == MSG_KEXGSS_HOSTKEY):
return self._parse_kexgss_h... | [
"\n Parse the next packet.\n\n :param ptype: The (string) type of the incoming packet\n :param `.Message` m: The paket content\n "
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.