Exemple #1
0
    def create_alarm(self):
        """
        _plugins/_alerting/monitors
        @return:
        """
        pdb.set_trace()
        self.client.transport.perform_request("GET",
                                              _make_path("Test"),
                                              params=None,
                                              headers=None)

        self.client.transport.perform_request("GET",
                                              _make_path(
                                                  "_cat", "indices", None),
                                              params=None,
                                              headers=None)

        self.client.transport.perform_request("POST",
                                              _make_path(
                                                  "_plugins", "_alerting",
                                                  "monitors"),
                                              params=None,
                                              headers=None)
        self.client.transport.perform_request("GET",
                                              _make_path(
                                                  "_plugins", "_alerting",
                                                  "monitors", "alerts"),
                                              params=None,
                                              headers=None)
        ""
    def update(self, index, doc_type, id, body=None, params=None):
        """
        Update a document based on a script or partial data provided.
        `<http://elasticsearch.org/guide/reference/api/update/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg id: Document ID
        :arg body: The request definition using either `script` or partial `doc`
        :arg consistency: Explicit write consistency setting for the operation
        :arg fields: A comma-separated list of fields to return in the response
        :arg lang: The script language (default: mvel)
        :arg parent: ID of the parent document
        :arg percolate: Perform percolation during the operation; use specific
            registered query name, attribute, or wildcard
        :arg refresh: Refresh the index after performing the operation
        :arg replication: Specific replication type (default: sync)
        :arg retry_on_conflict: Specify how many times should the operation be
            retried when a conflict occurs (default: 0)
        :arg routing: Specific routing value
        :arg script: The URL-encoded script definition (instead of using
            request body)
        :arg timeout: Explicit operation timeout
        :arg timestamp: Explicit timestamp for the document
        :arg ttl: Expiration time for the document
        :arg version: Explicit version number for concurrency control
        :arg version_type: Explicit version number for concurrency control
        """
        _, data = yield self.transport.perform_request('POST',
                                                       _make_path(index,
                                                                  doc_type, id,
                                                                  '_update'),
                                                       params=params, body=body)
        raise gen.Return(data)
    def mget(self, body, index=None, doc_type=None, params=None):
        """
        Get multiple documents based on an index, type (optional) and ids.
        `<http://elasticsearch.org/guide/reference/api/multi-get/>`_

        :arg body: Document identifiers; can be either `docs` (containing full
            document information) or `ids` (when index and type is provided
                in the URL.
        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg _source: True or false to return the _source field or not, or a
            list of fields to return
        :arg _source_exclude: A list of fields to exclude from the returned
            _source field
        :arg _source_include: A list of fields to extract and return from the
            _source field
        :arg fields: A comma-separated list of fields to return in the response
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        _, data = yield self.transport.perform_request('GET',
                                                       _make_path(index,
                                                                  doc_type,
                                                                  '_mget'),
                                                       params=params, body=body)
        raise gen.Return(data)
    def index(self, index, doc_type, body, id=None, params=None):
        """
        Adds or updates a typed JSON document in a specific index, making it
        searchable. `<http://elasticsearch.org/guide/reference/api/index_/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg body: The document
        :arg id: Document ID
        :arg consistency: Explicit write consistency setting for the operation
        :arg op_type: Explicit operation type (default: index)
        :arg parent: ID of the parent document
        :arg percolate: Percolator queries to execute while indexing the doc
        :arg refresh: Refresh the index after performing the operation
        :arg replication: Specific replication type (default: sync)
        :arg routing: Specific routing value
        :arg timeout: Explicit operation timeout
        :arg timestamp: Explicit timestamp for the document
        :arg ttl: Expiration time for the document
        :arg version: Explicit version number for concurrency control
        :arg version_type: Specific version type

        """
        _, data = yield self.transport.perform_request(
            'PUT' if id else 'POST', _make_path(index, doc_type, id),
            params=params, body=body)
        raise gen.Return(data)
    def delete_by_query(self, index, doc_type=None, body=None, params=None):
        """
        Delete documents from one or more indices and one or more types based
        on a query.
        `<http://www.elasticsearch.org/guide/reference/api/delete-by-query/>`_

        :arg index: A comma-separated list of indices to restrict the operation
        :arg doc_type: A comma-separated list of types to restrict the operation
        :arg body: A query to restrict the operation
        :arg consistency: Specific write consistency setting for the operation
        :arg ignore_indices: When performed on multiple indices, allows to
            ignore `missing` ones (default: none)
        :arg replication: Specific replication type (default: sync)
        :arg routing: Specific routing value
        :arg source: The URL-encoded query definition (instead of using the
        request body)
        :arg q: Query in the Lucene query string syntax
        :arg timeout: Explicit operation timeout
        """
        _, data = yield self.transport.perform_request('DELETE',
                                                       _make_path(index,
                                                                  doc_type,
                                                                  '_query'),
                                                       params=params, body=body)
        raise gen.Return(data)
Exemple #6
0
 def account(self, params=None, headers=None):
     return self.transport.perform_request(
         "GET",
         _make_path("_opendistro", "_security", "api", "account"),
         params=params,
         headers=headers,
     )
Exemple #7
0
 def _req(self, method: str, store: Optional[str], suffix: Iterable[str],
          body: Optional[Mapping], params: Optional[Mapping]) -> Mapping:
     path = _make_path('_ltr', store, self.store_type, *suffix)
     return self.transport.perform_request(method,
                                           path,
                                           body=body,
                                           params=params)
    def exists(self, index, id, doc_type='_all', params=None):
        """
        Returns a boolean indicating whether or not given document exists in
        Elasticsearch. `<http://elasticsearch.org/guide/reference/api/get/>`_

        :arg index: The name of the index
        :arg id: The document ID
        :arg doc_type: The type of the document (uses `_all` by default to
            fetch the first document matching the ID across all types)
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        try:
            self.transport.perform_request('HEAD',
                                           _make_path(index, doc_type, id),
                                           params=params)
        except NotFoundError:
            return gen.Return(False)
        raise gen.Return(True)
 def _determine_clusters(self, keywords):
     request = {
         "search_request": {
             "query": {
                 "terms": {
                     "text": keywords
                 }
             },
             "size": 10000
         },
         "query_hint": ' '.join(keywords),
         "max_hits": 0,
         "field_mapping": {
             "content": ["_source.text"]
         },
         "algorithm": "lingo",
         "attributes": {
             "LingoClusteringAlgorithm.desiredClusterCountBase": 7,
             "LingoClusteringAlgorithm.clusterMergingThreshold": 0.15,
             "TermDocumentMatrixBuilder.maxWordDf": 0.05,
             "DocumentAssigner.minClusterSize": 20
         }
     }
     _, data = es.transport.perform_request('POST', _make_path('twitter', 'tweet', '_search_with_clusters'),
                                            params=dict(request_timeout=120), body=request)
     return data
Exemple #10
0
    def stats(self, params: Optional[Mapping] = None) -> Mapping:
        """Query the ltr model cache stats api

        The cache stats api retieves cluster-wide stats about the ltr model cache.
        """
        path = _make_path('_ltr', '_cachestats')
        return self.transport.perform_request('GET', path)
    def scroll(self, scroll_id, scroll, params=None):
        """
        Scroll a search request created by specifying the scroll parameter.
        `<http://www.elasticsearch.org/guide/reference/api/search/scroll/>`_

        :arg scroll_id: The scroll ID
        :arg scroll: Specify how long a consistent view of the index should be
            maintained for scrolled search
        """
        body = {
            "scroll": scroll,
            "scroll_id": scroll_id
        }

        if params:
            if "scroll" in params.keys():
                params.pop("scroll")
            if "scroll_id" in params.keys():
                params.pop("scroll_id")

        _, data = yield self.transport.perform_request('POST',
                                                       _make_path('_search',
                                                                  'scroll'),
                                                       body=body,
                                                       params=params)
        raise gen.Return(data)
 def test_handles_utf_encoded_string(self):
     if not PY2:
         raise SkipTest("Only relevant for py2")
     id = "中文".encode("utf-8")
     self.assertEqual(
         "/some-index/type/%E4%B8%AD%E6%96%87", _make_path("some-index", "type", id)
     )
    def get_source(self, index, id, doc_type='_all', params=None):
        """
        Get the source of a document by it's index, type and id.
        `<http://elasticsearch.org/guide/reference/api/get/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document (uses `_all` by default to
            fetch the first document matching the ID across all types)
        :arg id: The document ID
        :arg exclude: A list of fields to exclude from the returned
            _source field
        :arg include: A list of fields to extract and return from the
            _source field
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        _, data = yield self.transport.perform_request('GET',
                                                       _make_path(index,
                                                                  doc_type, id,
                                                                  '_source'),
                                                       params=params)
        raise gen.Return(data)
    def index(self, index, doc_type, body, id=None, params=None):
        """
        Adds or updates a typed JSON document in a specific index, making it
        searchable. `<http://elasticsearch.org/guide/reference/api/index_/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg body: The document
        :arg id: Document ID
        :arg consistency: Explicit write consistency setting for the operation
        :arg op_type: Explicit operation type (default: index)
        :arg parent: ID of the parent document
        :arg percolate: Percolator queries to execute while indexing the doc
        :arg refresh: Refresh the index after performing the operation
        :arg replication: Specific replication type (default: sync)
        :arg routing: Specific routing value
        :arg timeout: Explicit operation timeout
        :arg timestamp: Explicit timestamp for the document
        :arg ttl: Expiration time for the document
        :arg version: Explicit version number for concurrency control
        :arg version_type: Specific version type

        """
        _, data = yield self.transport.perform_request('PUT' if id else 'POST',
                                                       _make_path(index,
                                                                  doc_type, id),
                                                       params=params, body=body)
        raise gen.Return(data)
    def mget(self, body, index=None, doc_type=None, params=None):
        """
        Get multiple documents based on an index, type (optional) and ids.
        `<http://elasticsearch.org/guide/reference/api/multi-get/>`_

        :arg body: Document identifiers; can be either `docs` (containing full
            document information) or `ids` (when index and type is provided
                in the URL.
        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg _source: True or false to return the _source field or not, or a
            list of fields to return
        :arg _source_exclude: A list of fields to exclude from the returned
            _source field
        :arg _source_include: A list of fields to extract and return from the
            _source field
        :arg fields: A comma-separated list of fields to return in the response
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        _, data = yield self.transport.perform_request(
            'GET', _make_path(index, doc_type, '_mget'),
            params=params, body=body)
        raise gen.Return(data)
Exemple #16
0
    def count(self, index=None, doc_type=None, body=None, params=None):
        """
        Execute a query and get the number of matches for that query.
        `<http://elasticsearch.org/guide/reference/api/count/>`_

        :arg index: A comma-separated list of indices to restrict the results
        :arg doc_type: A comma-separated list of types to restrict the results
        :arg body: A query to restrict the results (optional)
        :arg ignore_indices: When performed on multiple indices, allows to
            ignore `missing` ones (default: none)
        :arg min_score: Include only documents with a specific `_score` value
            in the result
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg routing: Specific routing value
        :arg source: The URL-encoded query definition (instead of using the
            request body)
        """
        _, data = yield self.transport.perform_request('POST',
                                                       _make_path(
                                                           index, doc_type,
                                                           '_count'),
                                                       params=params,
                                                       body=body)
        raise gen.Return(data)
Exemple #17
0
    def get_influencers(self, job_id, body=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html>`_

        :arg job_id: None
        :arg body: Influencer selection criteria
        :arg desc: whether the results should be sorted in decending order
        :arg end: end timestamp for the requested influencers
        :arg exclude_interim: Exclude interim results
        :arg from_: skips a number of influencers
        :arg influencer_score: influencer score threshold for the requested
            influencers
        :arg size: specifies a max number of influencers to get
        :arg sort: sort field for the requested influencers
        :arg start: start timestamp for the requested influencers
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError(
                "Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request(
            'GET',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id, 'results',
                       'influencers'),
            params=params,
            body=body)
Exemple #18
0
    def upload_model(self, featureset, model, params=None):
        """
        Upload a model to Elasticsearch

        `<https://elasticsearch-learning-to-rank.readthedocs.io/en/latest/training-models.html>`_

        :arg featureset: Name of the featureset related to the model
        :arg model: Model object to be uploaded
        :type model: A elasticsearch_ltrModel object from the
        :arg master_timeout: Specify timeout for connection to master
        :arg timeout: Explicit operation timeout
        :arg wait_for_active_shards: Set the number of active shards to wait for
            before the operation returns.

        """
        return self.transport.perform_request('POST',
                                              _make_path(
                                                  '_ltr', '_featureset',
                                                  featureset, '_createmodel'),
                                              params=params,
                                              body={
                                                  'model': {
                                                      "name": model.name,
                                                      "model": {
                                                          "type":
                                                          model.type,
                                                          "definition":
                                                          model.definition
                                                      }
                                                  }
                                              })
Exemple #19
0
    def exists(self, index, id, doc_type='_all', params=None):
        """
        Returns a boolean indicating whether or not given document exists in
        Elasticsearch. `<http://elasticsearch.org/guide/reference/api/get/>`_

        :arg index: The name of the index
        :arg id: The document ID
        :arg doc_type: The type of the document (uses `_all` by default to
            fetch the first document matching the ID across all types)
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        try:
            self.transport.perform_request('HEAD',
                                           _make_path(index, doc_type, id),
                                           params=params)
        except NotFoundError:
            return gen.Return(False)
        raise gen.Return(True)
    def delete_by_query(self, index, doc_type=None, body=None, params=None):
        """
        Delete documents from one or more indices and one or more types based
        on a query.
        `<http://www.elasticsearch.org/guide/reference/api/delete-by-query/>`_

        :arg index: A comma-separated list of indices to restrict the operation
        :arg doc_type: A comma-separated list of types to restrict the operation
        :arg body: A query to restrict the operation
        :arg consistency: Specific write consistency setting for the operation
        :arg ignore_indices: When performed on multiple indices, allows to
            ignore `missing` ones (default: none)
        :arg replication: Specific replication type (default: sync)
        :arg routing: Specific routing value
        :arg source: The URL-encoded query definition (instead of using the
        request body)
        :arg q: Query in the Lucene query string syntax
        :arg timeout: Explicit operation timeout
        """
        _, data = yield self.transport.perform_request('DELETE',
                                                       _make_path(index,
                                                                  doc_type,
                                                                  '_query'),
                                                       params=params, body=body)
        raise gen.Return(data)
    def scroll(self, scroll_id, scroll, params=None):
        """
        Scroll a search request created by specifying the scroll parameter.
        `<http://www.elasticsearch.org/guide/reference/api/search/scroll/>`_

        :arg scroll_id: The scroll ID
        :arg scroll: Specify how long a consistent view of the index should be
            maintained for scrolled search
        """
        body = {
            "scroll": scroll,
            "scroll_id": scroll_id
        }

        if params:
            if "scroll" in params.keys():
                params.pop("scroll")
            if "scroll_id" in params.keys():
                params.pop("scroll_id")

        _, data = yield self.transport.perform_request('POST',
                                                       _make_path('_search',
                                                                  'scroll'),
                                                       body=body,
                                                       params=params)
        raise gen.Return(data)
Exemple #22
0
    def get_records(self, job_id, body=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-record.html>`_

        :arg job_id: None
        :arg body: Record selection criteria
        :arg desc: Set the sort direction
        :arg end: End time filter for records
        :arg exclude_interim: Exclude interim results
        :arg from_: skips a number of records
        :arg record_score:
        :arg size: specifies a max number of records to get
        :arg sort: Sort records by a particular field
        :arg start: Start time filter for records
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError(
                "Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request(
            'GET',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id, 'results',
                       'records'),
            params=params,
            body=body)
 def test_handles_utf_encoded_string(self):
     if not PY2:
         raise SkipTest("Only relevant for py2")
     id = "中文".encode("utf-8")
     self.assertEquals(
         "/some-index/type/%E4%B8%AD%E6%96%87", _make_path("some-index", "type", id)
     )
Exemple #24
0
    def flush_job(self, job_id, body=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html>`_

        :arg job_id: The name of the job to flush
        :arg body: Flush parameters
        :arg advance_time: Advances time to the given value generating results
            and updating the model for the advanced interval
        :arg calc_interim: Calculates interim results for the most recent bucket
            or all buckets within the latency period
        :arg end: When used in conjunction with calc_interim, specifies the
            range of buckets on which to calculate interim results
        :arg skip_time: Skips time to the given value without generating results
            or updating the model for the skipped interval
        :arg start: When used in conjunction with calc_interim, specifies the
            range of buckets on which to calculate interim results
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError(
                "Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request(
            'POST',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id, '_flush'),
            params=params,
            body=body)
Exemple #25
0
    def get_buckets(self, job_id, timestamp=None, body=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-bucket.html>`_

        :arg job_id: ID of the job to get bucket results from
        :arg timestamp: The timestamp of the desired single bucket result
        :arg body: Bucket selection details if not provided in URI
        :arg anomaly_score: Filter for the most anomalous buckets
        :arg desc: Set the sort direction
        :arg end: End time filter for buckets
        :arg exclude_interim: Exclude interim results
        :arg expand: Include anomaly records
        :arg from_: skips a number of buckets
        :arg size: specifies a max number of buckets to get
        :arg sort: Sort buckets by a particular field
        :arg start: Start time filter for buckets
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError(
                "Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request(
            'GET',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id, 'results',
                       'buckets', timestamp),
            params=params,
            body=body)
    def get_source(self, index, id, doc_type='_all', params=None):
        """
        Get the source of a document by it's index, type and id.
        `<http://elasticsearch.org/guide/reference/api/get/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document (uses `_all` by default to
            fetch the first document matching the ID across all types)
        :arg id: The document ID
        :arg exclude: A list of fields to exclude from the returned
            _source field
        :arg include: A list of fields to extract and return from the
            _source field
        :arg parent: The ID of the parent document
        :arg preference: Specify the node or shard the operation should be
            performed on (default: random)
        :arg realtime: Specify whether to perform the operation in realtime or
            search mode
        :arg refresh: Refresh the shard containing the document before
            performing the operation
        :arg routing: Specific routing value
        """
        _, data = yield self.transport.perform_request(
            'GET', _make_path(index, doc_type, id, '_source'), params=params)
        raise gen.Return(data)
Exemple #27
0
    def get_model_snapshots(self,
                            job_id,
                            snapshot_id=None,
                            body=None,
                            params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-snapshot.html>`_

        :arg job_id: The ID of the job to fetch
        :arg snapshot_id: The ID of the snapshot to fetch
        :arg body: Model snapshot selection criteria
        :arg desc: True if the results should be sorted in descending order
        :arg end: The filter 'end' query parameter
        :arg from_: Skips a number of documents
        :arg size: The default number of documents returned in queries as a
            string.
        :arg sort: Name of the field to sort on
        :arg start: The filter 'start' query parameter
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError(
                "Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request(
            'GET',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id,
                       'model_snapshots', snapshot_id),
            params=params,
            body=body)
    def update(self, index, doc_type, id, body=None, params=None):
        """
        Update a document based on a script or partial data provided.
        `<http://elasticsearch.org/guide/reference/api/update/>`_

        :arg index: The name of the index
        :arg doc_type: The type of the document
        :arg id: Document ID
        :arg body: The request definition using either `script` or partial `doc`
        :arg consistency: Explicit write consistency setting for the operation
        :arg fields: A comma-separated list of fields to return in the response
        :arg lang: The script language (default: mvel)
        :arg parent: ID of the parent document
        :arg percolate: Perform percolation during the operation; use specific
            registered query name, attribute, or wildcard
        :arg refresh: Refresh the index after performing the operation
        :arg replication: Specific replication type (default: sync)
        :arg retry_on_conflict: Specify how many times should the operation be
            retried when a conflict occurs (default: 0)
        :arg routing: Specific routing value
        :arg script: The URL-encoded script definition (instead of using
            request body)
        :arg timeout: Explicit operation timeout
        :arg timestamp: Explicit timestamp for the document
        :arg ttl: Expiration time for the document
        :arg version: Explicit version number for concurrency control
        :arg version_type: Explicit version number for concurrency control
        """
        _, data = yield self.transport.perform_request('POST',
                                                       _make_path(index,
                                                                  doc_type, id,
                                                                  '_update'),
                                                       params=params, body=body)
        raise gen.Return(data)
    def info(self, index=None, params=None):
        """
        `<http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html>`_

        :arg index: Index pattern
        """
        return self.transport.perform_request('GET', _make_path(index, '_xpack',
            'migration', 'deprecations'), params=params)
    def get_role_mapping(self, name=None, params=None):
        """
        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-role-mapping.html#security-api-get-role-mapping>`_

        :arg name: Role-Mapping name
        """
        return self.transport.perform_request('GET', _make_path('_xpack',
            'security', 'role_mapping', name), params=params)
 def delete_feature_store(self,
                          name: Optional[str] = None,
                          params=None,
                          headers=None):
     self.transport.perform_request("DELETE",
                                    _make_path("_ltr", name),
                                    params=params,
                                    headers=headers)
Exemple #32
0
    def log_features(self,
                     index,
                     documents,
                     featureset,
                     feature_params,
                     params=None):
        """
        Compute features for a set of documents and given parameters (the parameters required to compute the features
        like the query keywords, the user name, etc.

        `<https://elasticsearch-learning-to-rank.readthedocs.io/en/latest/logging-features.html>`_
        :arg documents List of identifiers of the documents for which the features are being computed
        :arg featureset: Name of the featureset
        :arg feature_params: Parameters needed to compute the features, such as the query keywords or the user name
        :arg master_timeout: Specify timeout for connection to master
        :arg timeout: Explicit operation timeout
        :arg wait_for_active_shards: Set the number of active shards to wait for
            before the operation returns.

        :return A list of objects containing the document identifier and the computed features
        """
        query = {
            "bool": {
                "filter": {
                    "terms": {
                        "_id": documents
                    }
                },
                "must": {
                    "sltr": {
                        "_name": "logged_featureset",
                        "featureset": featureset,
                        "params": feature_params
                    }
                }
            }
        }

        ext_features = {
            "ltr_log": {
                "log_specs": {
                    "name": "log_entry1",
                    "named_query": "logged_featureset"
                }
            }
        }

        body = {"query": query, "ext": ext_features}

        results = self.transport.perform_request('GET',
                                                 _make_path(index, '_search'),
                                                 body=body,
                                                 params=params)

        return [{
            '_id': result['_id'],
            'features': result['fields']['_ltrlog'][0]['log_entry1']
        } for result in results['hits']['hits']]
Exemple #33
0
    def delete_filter(self, filter_id, params=None):
        """

        :arg filter_id: The ID of the filter to delete
        """
        if filter_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'filter_id'.")
        return self.transport.perform_request('DELETE', _make_path('_xpack',
            'ml', 'filters', filter_id), params=params)
Exemple #34
0
    def get_jobs(self, job_id=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job.html>`_

        :arg job_id: The ID of the jobs to fetch
        """
        return self.transport.perform_request('GET', _make_path('_xpack', 'ml',
            'anomaly_detectors', job_id), params=params)
 def clear_cache(self,
                 store_name: Optional[str] = None,
                 params=None,
                 headers=None):
     self.transport.perform_request("POST",
                                    _make_path("_ltr", store_name,
                                               "_clearcache"),
                                    params=params,
                                    headers=headers)
 def info(self, params=None):
     """
     Get info about the xpack plugin.
     `<https://www.elastic.co/guide/en/x-pack/current/info-api.html>`_
     """
     data = self.transport.perform_request('GET',
                                           _make_path('_xpack'),
                                           params=params)
     return data
Exemple #37
0
    def get_filters(self, filter_id=None, params=None):
        """

        :arg filter_id: The ID of the filter to fetch
        :arg from_: skips a number of filters
        :arg size: specifies a max number of filters to get
        """
        return self.transport.perform_request('GET', _make_path('_xpack', 'ml',
            'filters', filter_id), params=params)
Exemple #38
0
    def get_datafeed_stats(self, datafeed_id=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed-stats.html>`_

        :arg datafeed_id: The ID of the datafeeds stats to fetch
        """
        return self.transport.perform_request('GET', _make_path('_xpack', 'ml',
            'datafeeds', datafeed_id, '_stats'), params=params)
Exemple #39
0
 def init_destinations(self):
     search_result = self.client.transport.perform_request(
         "GET", _make_path("_plugins", "_alerting", "destinations"))
     destinations = []
     for _metadata in search_result["destinations"]:
         destination = Destination()
         destination.init_from_search_reply(_metadata)
         destinations.append(destination)
     self.destinations = destinations
    def get_user(self, username=None, params=None):
        """

        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-users.html#security-api-get-user>`_

        :arg username: A comma-separated list of usernames
        """
        return self.transport.perform_request('GET', _make_path('_xpack',
            'security', 'user', username), params=params)
 def list_feature_sets(self,
                       store_name: Optional[str] = None,
                       params=None,
                       headers=None):
     return self.transport.perform_request("GET",
                                           _make_path(
                                               "_ltr", store_name,
                                               "_featureset"),
                                           params=params,
                                           headers=headers)
 def get_cache_stats(self,
                     store_name: Optional[str] = None,
                     params=None,
                     headers=None):
     return self.transport.perform_request("GET",
                                           _make_path(
                                               "_ltr", store_name,
                                               "_cachestats"),
                                           params=params,
                                           headers=headers)
    def get_watch(self, id, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html>`_

        :arg id: Watch ID
        """
        if id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'id'.")
        return self.transport.perform_request('GET', _make_path('_xpack',
            'watcher', 'watch', id), params=params)
    def stats(self, metric=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html>`_

        :arg metric: Controls what additional stat metrics should be include in
            the response
        :arg emit_stacktraces: Emits stack traces of currently running watches
        """
        return self.transport.perform_request('GET', _make_path('_xpack',
            'watcher', 'stats', metric), params=params)
    def execute_watch(self, id=None, body=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html>`_

        :arg id: Watch ID
        :arg body: Execution control
        :arg debug: indicates whether the watch should execute in debug mode
        """
        return self.transport.perform_request('PUT', _make_path('_xpack',
            'watcher', 'watch', id, '_execute'), params=params, body=body)
Exemple #46
0
    def get_job_stats(self, job_id=None, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html>`_

        :arg job_id: The ID of the jobs stats to fetch
        """
        return self.transport.perform_request(
            'GET',
            _make_path('_xpack', 'ml', 'anomaly_detectors', job_id, '_stats'),
            params=params)
    def clear_cached_roles(self, name, params=None):
        """

        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-roles.html#security-api-clear-role-cache>`_

        :arg name: Role name
        """
        if name in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'name'.")
        return self.transport.perform_request('POST', _make_path('_xpack',
            'security', 'role', name, '_clear_cache'), params=params)
Exemple #48
0
    def put_filter(self, filter_id, body, params=None):
        """

        :arg filter_id: The ID of the filter to create
        :arg body: The filter details
        """
        for param in (filter_id, body):
            if param in SKIP_IN_PATH:
                raise ValueError("Empty value passed for a required argument.")
        return self.transport.perform_request('PUT', _make_path('_xpack', 'ml',
            'filters', filter_id), params=params, body=body)
Exemple #49
0
    def get_role_mapping(self, name=None, params=None):
        """
        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-role-mapping.html#security-api-get-role-mapping>`_

        :arg name: Role-Mapping name
        """
        return self.transport.perform_request('GET',
                                              _make_path(
                                                  '_xpack', 'security',
                                                  'role_mapping', name),
                                              params=params)
Exemple #50
0
    def open_job(self, job_id, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html>`_

        :arg job_id: The ID of the job to open
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request('POST', _make_path('_xpack', 'ml',
            'anomaly_detectors', job_id, '_open'), params=params)
 def get_feature(self,
                 name: str,
                 store_name: Optional[str] = None,
                 params=None,
                 headers=None):
     return self.transport.perform_request("GET",
                                           _make_path(
                                               "_ltr", store_name,
                                               "_feature", name),
                                           params=params,
                                           headers=headers)
Exemple #52
0
    def info(self, index=None, params=None):
        """
        `<http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html>`_

        :arg index: Index pattern
        """
        return self.transport.perform_request('GET',
                                              _make_path(
                                                  index, '_xpack', 'migration',
                                                  'deprecations'),
                                              params=params)
Exemple #53
0
    def preview_datafeed(self, datafeed_id, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-preview-datafeed.html>`_

        :arg datafeed_id: The ID of the datafeed to preview
        """
        if datafeed_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'datafeed_id'.")
        return self.transport.perform_request('GET', _make_path('_xpack', 'ml',
            'datafeeds', datafeed_id, '_preview'), params=params)
Exemple #54
0
    def delete_job(self, job_id, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html>`_

        :arg job_id: The ID of the job to delete
        :arg force: True if the job should be forcefully deleted
        """
        if job_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'job_id'.")
        return self.transport.perform_request('DELETE', _make_path('_xpack',
            'ml', 'anomaly_detectors', job_id), params=params)
Exemple #55
0
    def delete_datafeed(self, datafeed_id, params=None):
        """

        `<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html>`_

        :arg datafeed_id: The ID of the datafeed to delete
        :arg force: True if the datafeed should be forcefully deleted
        """
        if datafeed_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'datafeed_id'.")
        return self.transport.perform_request('DELETE', _make_path('_xpack',
            'ml', 'datafeeds', datafeed_id), params=params)
    def get_watch(self, id, params=None):
        """
        Retrieve watch definition.
        `<http://www.elastic.co/guide/en/watcher/current/appendix-api-get-watch.html>`_

        :arg id: Watch ID
        """
        if id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'id'.")
        _, data = self.transport.perform_request('GET', _make_path('_watcher',
            'watch', id), params=params)
        return data
    def upgrade(self, index, params=None):
        """

        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-upgrade.html>`_

        :arg index: The name of the index
        :arg wait_for_completion: Should the request block until the upgrade
            operation is completed, default True
        """
        if index in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'index'.")
        return self.transport.perform_request('POST', _make_path('_xpack',
            'migration', 'upgrade', index), params=params)
    def clear_cached_realms(self, realms, params=None):
        """

        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-cache.html>`_

        :arg realms: Comma-separated list of realms to clear
        :arg usernames: Comma-separated list of usernames to clear from the
            cache
        """
        if realms in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'realms'.")
        return self.transport.perform_request('POST', _make_path('_xpack',
            'security', 'realm', realms, '_clear_cache'), params=params)
    def enable_user(self, username=None, params=None):
        """
        `<https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-users.html#security-api-enable-user>`_

        :arg username: The username of the user to enable
        :arg refresh: If `true` (the default) then refresh the affected shards
            to make this operation visible to search, if `wait_for` then wait
            for a refresh to make this operation visible to search, if `false`
            then do nothing with refreshes., valid choices are: 'true', 'false',
            'wait_for'
        """
        return self.transport.perform_request('PUT', _make_path('_xpack',
            'security', 'user', username, '_enable'), params=params)
    def execute_watch(self, id, body=None, params=None):
        """
        Execute watch manually.
        `<http://www.elastic.co/guide/en/watcher/current/appendix-api-execute-watch.html>`_

        :arg id: Watch ID
        :arg body: Execution control
        """
        if id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'id'.")
        _, data = self.transport.perform_request('PUT', _make_path('_watcher',
            'watch', id, '_execute'), params=params, body=body)
        return data