vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php line 143

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace Elasticsearch;
  4. use Elasticsearch\Common\Exceptions\BadMethodCallException;
  5. use Elasticsearch\Common\Exceptions\InvalidArgumentException;
  6. use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
  7. use Elasticsearch\Common\Exceptions\BadRequest400Exception;
  8. use Elasticsearch\Common\Exceptions\Missing404Exception;
  9. use Elasticsearch\Common\Exceptions\TransportException;
  10. use Elasticsearch\Endpoints\AbstractEndpoint;
  11. use Elasticsearch\Namespaces\AbstractNamespace;
  12. use Elasticsearch\Namespaces\CatNamespace;
  13. use Elasticsearch\Namespaces\ClusterNamespace;
  14. use Elasticsearch\Namespaces\IndicesNamespace;
  15. use Elasticsearch\Namespaces\IngestNamespace;
  16. use Elasticsearch\Namespaces\NamespaceBuilderInterface;
  17. use Elasticsearch\Namespaces\NodesNamespace;
  18. use Elasticsearch\Namespaces\SnapshotNamespace;
  19. use Elasticsearch\Namespaces\BooleanRequestWrapper;
  20. use Elasticsearch\Namespaces\TasksNamespace;
  21. /**
  22.  * Class Client
  23.  *
  24.  * @category Elasticsearch
  25.  * @package  Elasticsearch
  26.  * @author   Zachary Tong <zach@elastic.co>
  27.  * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
  28.  * @link     http://elastic.co
  29.  */
  30. class Client
  31. {
  32.     const VERSION '7.2.2';
  33.     /**
  34.      * @var Transport
  35.      */
  36.     public $transport;
  37.     /**
  38.      * @var array
  39.      */
  40.     protected $params;
  41.     /**
  42.      * @var IndicesNamespace
  43.      */
  44.     protected $indices;
  45.     /**
  46.      * @var ClusterNamespace
  47.      */
  48.     protected $cluster;
  49.     /**
  50.      * @var NodesNamespace
  51.      */
  52.     protected $nodes;
  53.     /**
  54.      * @var SnapshotNamespace
  55.      */
  56.     protected $snapshot;
  57.     /**
  58.      * @var CatNamespace
  59.      */
  60.     protected $cat;
  61.     /**
  62.      * @var IngestNamespace
  63.      */
  64.     protected $ingest;
  65.     /**
  66.      * @var TasksNamespace
  67.      */
  68.     protected $tasks;
  69.     /**
  70.      * @var callable
  71.      */
  72.     protected $endpoints;
  73.     /**
  74.      * @var NamespaceBuilderInterface[]
  75.      */
  76.     protected $registeredNamespaces = [];
  77.     /**
  78.      * Client constructor
  79.      *
  80.      * @param Transport           $transport
  81.      * @param callable            $endpoint
  82.      * @param AbstractNamespace[] $registeredNamespaces
  83.      */
  84.     public function __construct(Transport $transport, callable $endpoint, array $registeredNamespaces)
  85.     {
  86.         $this->transport $transport;
  87.         $this->endpoints $endpoint;
  88.         $this->indices   = new IndicesNamespace($transport$endpoint);
  89.         $this->cluster   = new ClusterNamespace($transport$endpoint);
  90.         $this->nodes     = new NodesNamespace($transport$endpoint);
  91.         $this->snapshot  = new SnapshotNamespace($transport$endpoint);
  92.         $this->cat       = new CatNamespace($transport$endpoint);
  93.         $this->ingest    = new IngestNamespace($transport$endpoint);
  94.         $this->tasks     = new TasksNamespace($transport$endpoint);
  95.         $this->registeredNamespaces $registeredNamespaces;
  96.     }
  97.     /**
  98.      * Endpoint: info
  99.      *
  100.      * @see http://www.elastic.co/guide/
  101.      *
  102.      * @return callable|array
  103.      */
  104.     public function info(array $params = [])
  105.     {
  106.         /**
  107.  * @var callable $endpointBuilder
  108. */
  109.         $endpointBuilder $this->endpoints;
  110.         /**
  111.  * @var \Elasticsearch\Endpoints\Info $endpoint
  112. */
  113.         $endpoint $endpointBuilder('Info');
  114.         $endpoint->setParams($params);
  115.         return $this->performRequest($endpoint);
  116.     }
  117.     /**
  118.      * Endpoint: ping
  119.      *
  120.      * @see http://www.elastic.co/guide/
  121.      *
  122.      */
  123.     public function ping(array $params = []): bool
  124.     {
  125.         /**
  126.  * @var callable $endpointBuilder
  127. */
  128.         $endpointBuilder $this->endpoints;
  129.         /**
  130.  * @var \Elasticsearch\Endpoints\Ping $endpoint
  131. */
  132.         $endpoint $endpointBuilder('Ping');
  133.         $endpoint->setParams($params);
  134.         try {
  135.             $this->performRequest($endpoint);
  136.         } catch (Missing404Exception $exception) {
  137.             return false;
  138.         } catch (TransportException $exception) {
  139.             return false;
  140.         } catch (NoNodesAvailableException $exception) {
  141.             return false;
  142.         }
  143.         return true;
  144.     }
  145.     /**
  146.      * Endpoint: rank_eval
  147.      *
  148.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html
  149.      *
  150.      * $params[
  151.      *   'body'               => '(string) The ranking evaluation search definition, including search requests, document ratings and ranking metric definition. (Required)',
  152.      *   'index'              => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices',
  153.      *   'ignore_unavailable' => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  154.      *   'allow_no_indices'   => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  155.      *   'expand_wildcards'   => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  156.      * ]
  157.      * @return callable|array
  158.      */
  159.     public function rankEval(array $params)
  160.     {
  161.         $body $this->extractArgument($params'body');
  162.         $index $this->extractArgument($params'index');
  163.         /**
  164.  * @var callable $endpointBuilder
  165. */
  166.         $endpointBuilder $this->endpoints;
  167.         /**
  168.  * @var \Elasticsearch\Endpoints\RankEval $endpoint
  169. */
  170.         $endpoint $endpointBuilder('RankEval');
  171.         $endpoint->setBody($body)
  172.             ->setIndex($index);
  173.         $endpoint->setParams($params);
  174.         return $this->performRequest($endpoint);
  175.     }
  176.     /**
  177.      * Endpoint: get
  178.      *
  179.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html
  180.      *
  181.      * $params[
  182.      *   'id'               => '(string) The document ID (Required)',
  183.      *   'index'            => '(string) The name of the index (Required)',
  184.      *   'type'             => '(string) The type of the document (use `_all` to fetch the first document matching the ID across all types)',
  185.      *   'stored_fields'    => '(list) A comma-separated list of stored fields to return in the response',
  186.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  187.      *   'realtime'         => '(boolean) Specify whether to perform the operation in realtime or search mode',
  188.      *   'refresh'          => '(boolean) Refresh the shard containing the document before performing the operation',
  189.      *   'routing'          => '(string) Specific routing value',
  190.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  191.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  192.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  193.      *   'version'          => '(number) Explicit version number for concurrency control',
  194.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  195.      * ]
  196.      * @return callable|array
  197.      */
  198.     public function get(array $params)
  199.     {
  200.         $id $this->extractArgument($params'id');
  201.         $index $this->extractArgument($params'index');
  202.         $type $this->extractArgument($params'type');
  203.         /**
  204.  * @var callable $endpointBuilder
  205. */
  206.         $endpointBuilder $this->endpoints;
  207.         /**
  208.  * @var \Elasticsearch\Endpoints\Get $endpoint
  209. */
  210.         $endpoint $endpointBuilder('Get');
  211.         $endpoint->setID($id)
  212.             ->setIndex($index)
  213.             ->setType($type);
  214.         $endpoint->setParams($params);
  215.         return $this->performRequest($endpoint);
  216.     }
  217.     /**
  218.      * Endpoint: get_source
  219.      *
  220.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html
  221.      *
  222.      * $params[
  223.      *   'id'               => '(string) The document ID (Required)',
  224.      *   'index'            => '(string) The name of the index (Required)',
  225.      *   'type'             => '(string) The type of the document; deprecated and optional starting with 7.0',
  226.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  227.      *   'realtime'         => '(boolean) Specify whether to perform the operation in realtime or search mode',
  228.      *   'refresh'          => '(boolean) Refresh the shard containing the document before performing the operation',
  229.      *   'routing'          => '(string) Specific routing value',
  230.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  231.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  232.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  233.      *   'version'          => '(number) Explicit version number for concurrency control',
  234.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  235.      * ]
  236.      * @return callable|array
  237.      */
  238.     public function getSource(array $params)
  239.     {
  240.         $id $this->extractArgument($params'id');
  241.         $index $this->extractArgument($params'index');
  242.         $type $this->extractArgument($params'type');
  243.         /**
  244.  * @var callable $endpointBuilder
  245. */
  246.         $endpointBuilder $this->endpoints;
  247.         /**
  248.  * @var \Elasticsearch\Endpoints\Get $endpoint
  249. */
  250.         $endpoint $endpointBuilder('Source\Get');
  251.         $endpoint->setID($id)
  252.             ->setIndex($index)
  253.             ->setType($type);
  254.         $endpoint->setParams($params);
  255.         return $this->performRequest($endpoint);
  256.     }
  257.     /**
  258.      * Endpoint: exists_source
  259.      *
  260.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html
  261.      *
  262.      * $params[
  263.      *   'id'               => '(string) The document ID (Required)',
  264.      *   'index'            => '(string) The name of the index (Required)',
  265.      *   'type'             => '(string) The type of the document; deprecated and optional starting with 7.0',
  266.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  267.      *   'realtime'         => '(boolean) Specify whether to perform the operation in realtime or search mode',
  268.      *   'refresh'          => '(boolean) Refresh the shard containing the document before performing the operation',
  269.      *   'routing'          => '(string) Specific routing value',
  270.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  271.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  272.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  273.      *   'version'          => '(number) Explicit version number for concurrency control',
  274.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  275.      * ]
  276.      */
  277.     public function existsSource(array $params): bool
  278.     {
  279.         $id $this->extractArgument($params'id');
  280.         $index $this->extractArgument($params'index');
  281.         $type $this->extractArgument($params'type');
  282.         // manually make this verbose so we can check status code
  283.         $params['client']['verbose'] = true;
  284.         /**
  285.  * @var callable $endpointBuilder
  286. */
  287.         $endpointBuilder $this->endpoints;
  288.         /**
  289.  * @var \Elasticsearch\Endpoints\Exists $endpoint
  290. */
  291.         $endpoint $endpointBuilder('Source\Exists');
  292.         $endpoint->setID($id)
  293.             ->setIndex($index)
  294.             ->setType($type);
  295.         $endpoint->setParams($params);
  296.         return BooleanRequestWrapper::performRequest($endpoint$this->transport);
  297.     }
  298.     /**
  299.      * Endpoint: delete
  300.      *
  301.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html
  302.      *
  303.      * $params[
  304.      *   'id'                     => '(string) The document ID (Required)',
  305.      *   'index'                  => '(string) The name of the index (Required)',
  306.      *   'type'                   => '(string) The type of the document',
  307.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the delete operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  308.      *   'refresh'                => '(enum) If `true` then refresh the effected 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` (the default) then do nothing with refreshes. (Options = true,false,wait_for)',
  309.      *   'routing'                => '(string) Specific routing value',
  310.      *   'timeout'                => '(time) Explicit operation timeout',
  311.      *   'if_seq_no'              => '(number) only perform the delete operation if the last operation that has changed the document has the specified sequence number',
  312.      *   'if_primary_term'        => '(number) only perform the delete operation if the last operation that has changed the document has the specified primary term',
  313.      *   'version'                => '(number) Explicit version number for concurrency control',
  314.      *   'version_type'           => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  315.      * ]
  316.      * @return callable|array
  317.      */
  318.     public function delete(array $params)
  319.     {
  320.         $id $this->extractArgument($params'id');
  321.         $index $this->extractArgument($params'index');
  322.         $type $this->extractArgument($params'type');
  323.         $this->verifyNotNullOrEmpty("id"$id);
  324.         $this->verifyNotNullOrEmpty("index"$index);
  325.         /**
  326.  * @var callable $endpointBuilder
  327. */
  328.         $endpointBuilder $this->endpoints;
  329.         /**
  330.  * @var \Elasticsearch\Endpoints\Delete $endpoint
  331. */
  332.         $endpoint $endpointBuilder('Delete');
  333.         $endpoint->setID($id)
  334.             ->setIndex($index)
  335.             ->setType($type);
  336.         $endpoint->setParams($params);
  337.         return $this->performRequest($endpoint);
  338.     }
  339.     /**
  340.      * Endpoint: delete_by_query
  341.      *
  342.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html
  343.      *
  344.      * $params[
  345.      *   'body'                   => '(string) The search definition using the Query DSL (Required)',
  346.      *   'index'                  => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices (Required)',
  347.      *   'type'                   => '(list) A comma-separated list of document types to search; leave empty to perform the operation on all types',
  348.      *   'analyzer'               => '(string) The analyzer to use for the query string',
  349.      *   'analyze_wildcard'       => '(boolean) Specify whether wildcard and prefix queries should be analyzed (default: false)',
  350.      *   'default_operator'       => '(enum) The default operator for query string query (AND or OR) (Options = AND,OR) (Default = OR)',
  351.      *   'df'                     => '(string) The field to use as default where no field prefix is given in the query string',
  352.      *   'from'                   => '(number) Starting offset (default: 0)',
  353.      *   'ignore_unavailable'     => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  354.      *   'allow_no_indices'       => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  355.      *   'conflicts'              => '(enum) What to do when the delete by query hits version conflicts? (Options = abort,proceed) (Default = abort)',
  356.      *   'expand_wildcards'       => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  357.      *   'lenient'                => '(boolean) Specify whether format-based query failures (such as providing text to a numeric field) should be ignored',
  358.      *   'preference'             => '(string) Specify the node or shard the operation should be performed on (default: random)',
  359.      *   'q'                      => '(string) Query in the Lucene query string syntax',
  360.      *   'routing'                => '(list) A comma-separated list of specific routing values',
  361.      *   'scroll'                 => '(time) Specify how long a consistent view of the index should be maintained for scrolled search',
  362.      *   'search_type'            => '(enum) Search operation type (Options = query_then_fetch,dfs_query_then_fetch)',
  363.      *   'search_timeout'         => '(time) Explicit timeout for each search request. Defaults to no timeout.',
  364.      *   'size'                   => '(number) Number of hits to return (default: 10)',
  365.      *   'sort'                   => '(list) A comma-separated list of <field>:<direction> pairs',
  366.      *   '_source'                => '(list) True or false to return the _source field or not, or a list of fields to return',
  367.      *   '_source_excludes'       => '(list) A list of fields to exclude from the returned _source field',
  368.      *   '_source_includes'       => '(list) A list of fields to extract and return from the _source field',
  369.      *   'terminate_after'        => '(number) The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.',
  370.      *   'stats'                  => '(list) Specific 'tag' of the request for logging and statistical purposes',
  371.      *   'version'                => '(boolean) Specify whether to return document version as part of a hit',
  372.      *   'request_cache'          => '(boolean) Specify if request cache should be used for this request or not, defaults to index level setting',
  373.      *   'refresh'                => '(boolean) Should the effected indexes be refreshed?',
  374.      *   'timeout'                => '(time) Time each individual bulk request should wait for shards that are unavailable. (Default = 1m)',
  375.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the delete by query operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  376.      *   'scroll_size'            => '(number) Size on the scroll request powering the delete by query',
  377.      *   'wait_for_completion'    => '(boolean) Should the request should block until the delete by query is complete. (Default = true)',
  378.      *   'requests_per_second'    => '(number) The throttle for this request in sub-requests per second. -1 means no throttle. (Default = 0)',
  379.      *   'slices'                 => '(number) The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. (Default = 1)',
  380.      * ]
  381.      * @return callable|array
  382.      */
  383.     public function deleteByQuery(array $params = [])
  384.     {
  385.         $index $this->extractArgument($params'index');
  386.         $type $this->extractArgument($params'type');
  387.         $body $this->extractArgument($params'body');
  388.         /**
  389.  * @var callable $endpointBuilder
  390. */
  391.         $endpointBuilder $this->endpoints;
  392.         /**
  393.  * @var \Elasticsearch\Endpoints\DeleteByQuery $endpoint
  394. */
  395.         $endpoint $endpointBuilder('DeleteByQuery');
  396.         $endpoint->setIndex($index)
  397.             ->setType($type)
  398.             ->setBody($body);
  399.         $endpoint->setParams($params);
  400.         return $this->performRequest($endpoint);
  401.     }
  402.     /**
  403.      * Endpoint: delete_by_query_rethrottle
  404.      *
  405.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
  406.      *
  407.      * $params[
  408.      *   'task_id'             => '(string) The task id to rethrottle (Required)',
  409.      *   'requests_per_second' => '(number) The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. (Required)',
  410.      * ]
  411.      * @return callable|array
  412.      */
  413.     public function deleteByQueryRethrottle(array $params)
  414.     {
  415.         $taskId $this->extractArgument($params'task_id');
  416.         /**
  417.  * @var callable $endpointBuilder
  418. */
  419.         $endpointBuilder $this->endpoints;
  420.         /**
  421.  * @var \Elasticsearch\Endpoints\DeleteByQueryRethrottle $endpoint
  422. */
  423.         $endpoint $endpointBuilder('DeleteByQueryRethrottle');
  424.         $endpoint->setTaskId($taskId);
  425.         $endpoint->setParams($params);
  426.         return $this->performRequest($endpoint);
  427.     }
  428.     /**
  429.      * Endpoint: count
  430.      *
  431.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html
  432.      *
  433.      * $params[
  434.      *   'body'               => '(string) A query to restrict the results specified with the Query DSL (optional)',
  435.      *   'index'              => '(list) A comma-separated list of indices to restrict the results',
  436.      *   'type'               => '(list) A comma-separated list of types to restrict the results',
  437.      *   'ignore_unavailable' => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  438.      *   'ignore_throttled'   => '(boolean) Whether specified concrete, expanded or aliased indices should be ignored when throttled',
  439.      *   'allow_no_indices'   => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  440.      *   'expand_wildcards'   => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  441.      *   'min_score'          => '(number) Include only documents with a specific `_score` value in the result',
  442.      *   'preference'         => '(string) Specify the node or shard the operation should be performed on (default: random)',
  443.      *   'routing'            => '(list) A comma-separated list of specific routing values',
  444.      *   'q'                  => '(string) Query in the Lucene query string syntax',
  445.      *   'analyzer'           => '(string) The analyzer to use for the query string',
  446.      *   'analyze_wildcard'   => '(boolean) Specify whether wildcard and prefix queries should be analyzed (default: false)',
  447.      *   'default_operator'   => '(enum) The default operator for query string query (AND or OR) (Options = AND,OR) (Default = OR)',
  448.      *   'df'                 => '(string) The field to use as default where no field prefix is given in the query string',
  449.      *   'lenient'            => '(boolean) Specify whether format-based query failures (such as providing text to a numeric field) should be ignored',
  450.      *   'terminate_after'    => '(number) The maximum count for each shard, upon reaching which the query execution will terminate early',
  451.      * ]
  452.      * @return callable|array
  453.      */
  454.     public function count(array $params = [])
  455.     {
  456.         $index $this->extractArgument($params'index');
  457.         $type $this->extractArgument($params'type');
  458.         $body $this->extractArgument($params'body');
  459.         /**
  460.  * @var callable $endpointBuilder
  461. */
  462.         $endpointBuilder $this->endpoints;
  463.         /**
  464.  * @var \Elasticsearch\Endpoints\Count $endpoint
  465. */
  466.         $endpoint $endpointBuilder('Count');
  467.         $endpoint->setIndex($index)
  468.             ->setType($type)
  469.             ->setBody($body);
  470.         $endpoint->setParams($params);
  471.         return $this->performRequest($endpoint);
  472.     }
  473.     /**
  474.      * Endpoint: termvectors
  475.      *
  476.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html
  477.      *
  478.      * $params[
  479.      *   'body'             => '(string) Define parameters and or supply a document to get termvectors for. See documentation.',
  480.      *   'index'            => '(string) The index in which the document resides. (Required)',
  481.      *   'type'             => '(string) The type of the document.',
  482.      *   'id'               => '(string) The id of the document, when not specified a doc param should be supplied.',
  483.      *   'term_statistics'  => '(boolean) Specifies if total term frequency and document frequency should be returned. (Default = false)',
  484.      *   'field_statistics' => '(boolean) Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. (Default = true)',
  485.      *   'fields'           => '(list) A comma-separated list of fields to return.',
  486.      *   'offsets'          => '(boolean) Specifies if term offsets should be returned. (Default = true)',
  487.      *   'positions'        => '(boolean) Specifies if term positions should be returned. (Default = true)',
  488.      *   'payloads'         => '(boolean) Specifies if term payloads should be returned. (Default = true)',
  489.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random).',
  490.      *   'routing'          => '(string) Specific routing value.',
  491.      *   'realtime'         => '(boolean) Specifies if request is real-time as opposed to near-real-time (default: true).',
  492.      *   'version'          => '(number) Explicit version number for concurrency control',
  493.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  494.      * ]
  495.      * @return callable|array
  496.      */
  497.     public function termvectors(array $params = [])
  498.     {
  499.         $index $this->extractArgument($params'index');
  500.         $type  $this->extractArgument($params'type');
  501.         $id    $this->extractArgument($params'id');
  502.         $body  $this->extractArgument($params'body');
  503.         /**
  504.  * @var callable $endpointBuilder
  505. */
  506.         $endpointBuilder $this->endpoints;
  507.         /**
  508.  * @var \Elasticsearch\Endpoints\TermVectors $endpoint
  509. */
  510.         $endpoint $endpointBuilder('TermVectors');
  511.         $endpoint->setIndex($index)
  512.             ->setType($type)
  513.             ->setID($id)
  514.             ->setBody($body);
  515.         $endpoint->setParams($params);
  516.         return $this->performRequest($endpoint);
  517.     }
  518.     /**
  519.      * Endpoint: mtermvectors
  520.      *
  521.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html
  522.      *
  523.      * $params[
  524.      *   'body'             => '(string) Define ids, documents, parameters or a list of parameters per document here. You must at least provide a list of document ids. See documentation.',
  525.      *   'index'            => '(string) The index in which the document resides.',
  526.      *   'type'             => '(string) The type of the document.',
  527.      *   'ids'              => '(list) A comma-separated list of documents ids. You must define ids as parameter or set "ids" or "docs" in the request body',
  528.      *   'term_statistics'  => '(boolean) Specifies if total term frequency and document frequency should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". (Default = false)',
  529.      *   'field_statistics' => '(boolean) Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". (Default = true)',
  530.      *   'fields'           => '(list) A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body "params" or "docs".',
  531.      *   'offsets'          => '(boolean) Specifies if term offsets should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". (Default = true)',
  532.      *   'positions'        => '(boolean) Specifies if term positions should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". (Default = true)',
  533.      *   'payloads'         => '(boolean) Specifies if term payloads should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". (Default = true)',
  534.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random) .Applies to all returned documents unless otherwise specified in body "params" or "docs".',
  535.      *   'routing'          => '(string) Specific routing value. Applies to all returned documents unless otherwise specified in body "params" or "docs".',
  536.      *   'realtime'         => '(boolean) Specifies if requests are real-time as opposed to near-real-time (default: true).',
  537.      *   'version'          => '(number) Explicit version number for concurrency control',
  538.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  539.      * ]
  540.      * @return callable|array
  541.      */
  542.     public function mtermvectors(array $params = [])
  543.     {
  544.         $index $this->extractArgument($params'index');
  545.         $type  $this->extractArgument($params'type');
  546.         $body  $this->extractArgument($params'body');
  547.         /**
  548.  * @var callable $endpointBuilder
  549. */
  550.         $endpointBuilder $this->endpoints;
  551.         /**
  552.  * @var \Elasticsearch\Endpoints\MTermVectors $endpoint
  553. */
  554.         $endpoint $endpointBuilder('MTermVectors');
  555.         $endpoint->setIndex($index)
  556.             ->setType($type)
  557.             ->setBody($body);
  558.         $endpoint->setParams($params);
  559.         return $this->performRequest($endpoint);
  560.     }
  561.     /**
  562.      * Endpoint: exists
  563.      *
  564.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html
  565.      *
  566.      * $params[
  567.      *   'id'               => '(string) The document ID (Required)',
  568.      *   'index'            => '(string) The name of the index (Required)',
  569.      *   'type'             => '(string) The type of the document (use `_all` to fetch the first document matching the ID across all types)',
  570.      *   'stored_fields'    => '(list) A comma-separated list of stored fields to return in the response',
  571.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  572.      *   'realtime'         => '(boolean) Specify whether to perform the operation in realtime or search mode',
  573.      *   'refresh'          => '(boolean) Refresh the shard containing the document before performing the operation',
  574.      *   'routing'          => '(string) Specific routing value',
  575.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  576.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  577.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  578.      *   'version'          => '(number) Explicit version number for concurrency control',
  579.      *   'version_type'     => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  580.      * ]
  581.      */
  582.     public function exists(array $params): bool
  583.     {
  584.         $id $this->extractArgument($params'id');
  585.         $index $this->extractArgument($params'index');
  586.         $type $this->extractArgument($params'type');
  587.         // manually make this verbose so we can check status code
  588.         $params['client']['verbose'] = true;
  589.         /**
  590.  * @var callable $endpointBuilder
  591. */
  592.         $endpointBuilder $this->endpoints;
  593.         /**
  594.  * @var \Elasticsearch\Endpoints\Exists $endpoint
  595. */
  596.         $endpoint $endpointBuilder('Exists');
  597.         $endpoint->setID($id)
  598.             ->setIndex($index)
  599.             ->setType($type);
  600.         $endpoint->setParams($params);
  601.         return BooleanRequestWrapper::performRequest($endpoint$this->transport);
  602.     }
  603.     /**
  604.      * Endpoint: mget
  605.      *
  606.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html
  607.      *
  608.      * $params[
  609.      *   'body'             => '(string) Document identifiers; can be either `docs` (containing full document information) or `ids` (when index and type is provided in the URL. (Required)',
  610.      *   'index'            => '(string) The name of the index',
  611.      *   'type'             => '(string) The type of the document',
  612.      *   'stored_fields'    => '(list) A comma-separated list of stored fields to return in the response',
  613.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  614.      *   'realtime'         => '(boolean) Specify whether to perform the operation in realtime or search mode',
  615.      *   'refresh'          => '(boolean) Refresh the shard containing the document before performing the operation',
  616.      *   'routing'          => '(string) Specific routing value',
  617.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  618.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  619.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  620.      * ]
  621.      * @return callable|array
  622.      */
  623.     public function mget(array $params = [])
  624.     {
  625.         $index $this->extractArgument($params'index');
  626.         $type $this->extractArgument($params'type');
  627.         $body $this->extractArgument($params'body');
  628.         /**
  629.  * @var callable $endpointBuilder
  630. */
  631.         $endpointBuilder $this->endpoints;
  632.         /**
  633.  * @var \Elasticsearch\Endpoints\Mget $endpoint
  634. */
  635.         $endpoint $endpointBuilder('Mget');
  636.         $endpoint->setIndex($index)
  637.             ->setType($type)
  638.             ->setBody($body);
  639.         $endpoint->setParams($params);
  640.         return $this->performRequest($endpoint);
  641.     }
  642.     /**
  643.      * Endpoint: msearch
  644.      *
  645.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html
  646.      *
  647.      * $params[
  648.      *   'body'                          => '(string) The request definitions (metadata-search request definition pairs), separated by newlines (Required)',
  649.      *   'index'                         => '(list) A comma-separated list of index names to use as default',
  650.      *   'type'                          => '(list) A comma-separated list of document types to use as default',
  651.      *   'search_type'                   => '(enum) Search operation type (Options = query_then_fetch,query_and_fetch,dfs_query_then_fetch,dfs_query_and_fetch)',
  652.      *   'max_concurrent_searches'       => '(number) Controls the maximum number of concurrent searches the multi search api will execute',
  653.      *   'typed_keys'                    => '(boolean) Specify whether aggregation and suggester names should be prefixed by their respective types in the response',
  654.      *   'pre_filter_shard_size'         => '(number) A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. (Default = 128)',
  655.      *   'max_concurrent_shard_requests' => '(number) The number of concurrent shard requests each sub search executes concurrently per node. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests (Default = 5)',
  656.      *   'rest_total_hits_as_int'        => '(boolean) Indicates whether hits.total should be rendered as an integer or an object in the rest search response (Default = false)',
  657.      *   'ccs_minimize_roundtrips'       => '(boolean) Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution (Default = true)',
  658.      * ]
  659.      * @return callable|array
  660.      */
  661.     public function msearch(array $params = [])
  662.     {
  663.         $index $this->extractArgument($params'index');
  664.         $type $this->extractArgument($params'type');
  665.         $body $this->extractArgument($params'body');
  666.         /**
  667.  * @var callable $endpointBuilder
  668. */
  669.         $endpointBuilder $this->endpoints;
  670.         /**
  671.  * @var \Elasticsearch\Endpoints\Msearch $endpoint
  672. */
  673.         $endpoint $endpointBuilder('Msearch');
  674.         $endpoint->setIndex($index)
  675.             ->setType($type)
  676.             ->setBody($body);
  677.         $endpoint->setParams($params);
  678.         return $this->performRequest($endpoint);
  679.     }
  680.     /**
  681.      * Endpoint: msearch_template
  682.      *
  683.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html
  684.      *
  685.      * $params[
  686.      *   'body'                    => '(string) The request definitions (metadata-search request definition pairs), separated by newlines (Required)',
  687.      *   'index'                   => '(list) A comma-separated list of index names to use as default',
  688.      *   'type'                    => '(list) A comma-separated list of document types to use as default',
  689.      *   'search_type'             => '(enum) Search operation type (Options = query_then_fetch,query_and_fetch,dfs_query_then_fetch,dfs_query_and_fetch)',
  690.      *   'typed_keys'              => '(boolean) Specify whether aggregation and suggester names should be prefixed by their respective types in the response',
  691.      *   'max_concurrent_searches' => '(number) Controls the maximum number of concurrent searches the multi search api will execute',
  692.      *   'rest_total_hits_as_int'  => '(boolean) Indicates whether hits.total should be rendered as an integer or an object in the rest search response (Default = false)',
  693.      *   'ccs_minimize_roundtrips' => '(boolean) Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution (Default = true)',
  694.      * ]
  695.      * @return callable|array
  696.      */
  697.     public function msearchTemplate(array $params = [])
  698.     {
  699.         $index $this->extractArgument($params'index');
  700.         $type $this->extractArgument($params'type');
  701.         $body $this->extractArgument($params'body');
  702.         /**
  703.  * @var callable $endpointBuilder
  704. */
  705.         $endpointBuilder $this->endpoints;
  706.         /**
  707.  * @var \Elasticsearch\Endpoints\MsearchTemplate $endpoint
  708. */
  709.         $endpoint $endpointBuilder('MsearchTemplate');
  710.         $endpoint->setIndex($index)
  711.             ->setType($type)
  712.             ->setBody($body);
  713.         $endpoint->setParams($params);
  714.         return $this->performRequest($endpoint);
  715.     }
  716.     /**
  717.      * Endpoint: create
  718.      *
  719.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html
  720.      *
  721.      * $params[
  722.      *   'body'                   => '(string) The document (Required)',
  723.      *   'id'                     => '(string) Document ID (Required)',
  724.      *   'index'                  => '(string) The name of the index (Required)',
  725.      *   'type'                   => '(string) The type of the document',
  726.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  727.      *   'refresh'                => '(enum) If `true` 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` (the default) then do nothing with refreshes. (Options = true,false,wait_for)',
  728.      *   'routing'                => '(string) Specific routing value',
  729.      *   'timeout'                => '(time) Explicit operation timeout',
  730.      *   'version'                => '(number) Explicit version number for concurrency control',
  731.      *   'version_type'           => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  732.      *   'pipeline'               => '(string) The pipeline id to preprocess incoming documents with',
  733.      * ]
  734.      * @return callable|array
  735.      */
  736.     public function create(array $params)
  737.     {
  738.         $id $this->extractArgument($params'id');
  739.         $index $this->extractArgument($params'index');
  740.         $type $this->extractArgument($params'type');
  741.         $body $this->extractArgument($params'body');
  742.         /**
  743.  * @var callable $endpointBuilder
  744. */
  745.         $endpointBuilder $this->endpoints;
  746.         /**
  747.  * @var \Elasticsearch\Endpoints\Create $endpoint
  748. */
  749.         $endpoint $endpointBuilder('Create');
  750.         $endpoint->setID($id)
  751.             ->setIndex($index)
  752.             ->setType($type)
  753.             ->setBody($body);
  754.         $endpoint->setParams($params);
  755.         return $this->performRequest($endpoint);
  756.     }
  757.     /**
  758.      * Endpoint: bulk
  759.      *
  760.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html
  761.      *
  762.      * $params[
  763.      *   'body'                   => '(string) The operation definition and data (action-data pairs), separated by newlines (Required)',
  764.      *   'index'                  => '(string) Default index for items which don't provide one',
  765.      *   'type'                   => '(string) Default document type for items which don't provide one',
  766.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the bulk operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  767.      *   'refresh'                => '(enum) If `true` then refresh the effected 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` (the default) then do nothing with refreshes. (Options = true,false,wait_for)',
  768.      *   'routing'                => '(string) Specific routing value',
  769.      *   'timeout'                => '(time) Explicit operation timeout',
  770.      *   'type'                   => '(string) Default document type for items which don't provide one',
  771.      *   '_source'                => '(list) True or false to return the _source field or not, or default list of fields to return, can be overridden on each sub-request',
  772.      *   '_source_excludes'       => '(list) Default list of fields to exclude from the returned _source field, can be overridden on each sub-request',
  773.      *   '_source_includes'       => '(list) Default list of fields to extract and return from the _source field, can be overridden on each sub-request',
  774.      *   'pipeline'               => '(string) The pipeline id to preprocess incoming documents with',
  775.      * ]
  776.      * @return callable|array
  777.      */
  778.     public function bulk(array $params = [])
  779.     {
  780.         $index $this->extractArgument($params'index');
  781.         $type $this->extractArgument($params'type');
  782.         $body $this->extractArgument($params'body');
  783.         /**
  784.  * @var callable $endpointBuilder
  785. */
  786.         $endpointBuilder $this->endpoints;
  787.         /**
  788.  * @var \Elasticsearch\Endpoints\Bulk $endpoint
  789. */
  790.         $endpoint $endpointBuilder('Bulk');
  791.         $endpoint->setIndex($index)
  792.             ->setType($type)
  793.             ->setBody($body);
  794.         $endpoint->setParams($params);
  795.         return $this->performRequest($endpoint);
  796.     }
  797.     /**
  798.      * Endpoint: index
  799.      *
  800.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html
  801.      *
  802.      * $params[
  803.      *   'body'                   => '(string) The document (Required)',
  804.      *   'id'                     => '(string) Document ID',
  805.      *   'index'                  => '(string) The name of the index (Required)',
  806.      *   'type'                   => '(string) The type of the document',
  807.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  808.      *   'op_type'                => '(enum) Explicit operation type (Options = index,create) (Default = index)',
  809.      *   'refresh'                => '(enum) If `true` 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` (the default) then do nothing with refreshes. (Options = true,false,wait_for)',
  810.      *   'routing'                => '(string) Specific routing value',
  811.      *   'timeout'                => '(time) Explicit operation timeout',
  812.      *   'version'                => '(number) Explicit version number for concurrency control',
  813.      *   'version_type'           => '(enum) Specific version type (Options = internal,external,external_gte,force)',
  814.      *   'if_seq_no'              => '(number) only perform the index operation if the last operation that has changed the document has the specified sequence number',
  815.      *   'if_primary_term'        => '(number) only perform the index operation if the last operation that has changed the document has the specified primary term',
  816.      *   'pipeline'               => '(string) The pipeline id to preprocess incoming documents with',
  817.      * ]
  818.      * @return callable|array
  819.      */
  820.     public function index(array $params)
  821.     {
  822.         $id $this->extractArgument($params'id');
  823.         $index $this->extractArgument($params'index');
  824.         $type $this->extractArgument($params'type');
  825.         $body $this->extractArgument($params'body');
  826.         /**
  827.  * @var callable $endpointBuilder
  828. */
  829.         $endpointBuilder $this->endpoints;
  830.         /**
  831.  * @var \Elasticsearch\Endpoints\Index $endpoint
  832. */
  833.         $endpoint $endpointBuilder('Index');
  834.         $endpoint->setID($id)
  835.             ->setIndex($index)
  836.             ->setType($type)
  837.             ->setBody($body);
  838.         $endpoint->setParams($params);
  839.         return $this->performRequest($endpoint);
  840.     }
  841.     /**
  842.      * Endpoint: reindex
  843.      *
  844.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html
  845.      *
  846.      * $params[
  847.      *   'body'                   => '(string) The search definition using the Query DSL and the prototype for the index request. (Required)',
  848.      *   'refresh'                => '(boolean) Should the effected indexes be refreshed?',
  849.      *   'timeout'                => '(time) Time each individual bulk request should wait for shards that are unavailable. (Default = 1m)',
  850.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the reindex operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  851.      *   'wait_for_completion'    => '(boolean) Should the request should block until the reindex is complete. (Default = true)',
  852.      *   'requests_per_second'    => '(number) The throttle to set on this request in sub-requests per second. -1 means no throttle. (Default = 0)',
  853.      *   'scroll'                 => '(time) Control how long to keep the search context alive (Default = 5m)',
  854.      *   'slices'                 => '(number) The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. (Default = 1)',
  855.      * ]
  856.      * @return callable|array
  857.      */
  858.     public function reindex(array $params)
  859.     {
  860.         $body $this->extractArgument($params'body');
  861.         /**
  862.  * @var callable $endpointBuilder
  863. */
  864.         $endpointBuilder $this->endpoints;
  865.         /**
  866.  * @var \Elasticsearch\Endpoints\Reindex $endpoint
  867. */
  868.         $endpoint $endpointBuilder('Reindex');
  869.         $endpoint->setBody($body);
  870.         $endpoint->setParams($params);
  871.         return $this->performRequest($endpoint);
  872.     }
  873.     /**
  874.      * Endpoint: reindex_rethrottle
  875.      *
  876.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html
  877.      *
  878.      * $params[
  879.      *   'task_id'             => '(string) The task id to rethrottle (Required)',
  880.      *   'requests_per_second' => '(number) The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. (Required)',
  881.      * ]
  882.      * @return callable|array
  883.      */
  884.     public function reindexRethrottle(array $params)
  885.     {
  886.         $taskId $this->extractArgument($params'task_id');
  887.         /**
  888.  * @var callable $endpointBuilder
  889. */
  890.         $endpointBuilder $this->endpoints;
  891.         /**
  892.  * @var \Elasticsearch\Endpoints\ReindexRethrottle $endpoint
  893. */
  894.         $endpoint $endpointBuilder('ReindexRethrottle');
  895.         $endpoint->setTaskId($taskId);
  896.         $endpoint->setParams($params);
  897.         return $this->performRequest($endpoint);
  898.     }
  899.     /**
  900.      * Endpoint: explain
  901.      *
  902.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html
  903.      *
  904.      * $params[
  905.      *   'body'             => '(string) The query definition using the Query DSL',
  906.      *   'id'               => '(string) The document ID (Required)',
  907.      *   'index'            => '(string) The name of the index (Required)',
  908.      *   'type'             => '(string) The type of the document',
  909.      *   'analyze_wildcard' => '(boolean) Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false)',
  910.      *   'analyzer'         => '(string) The analyzer for the query string query',
  911.      *   'default_operator' => '(enum) The default operator for query string query (AND or OR) (Options = AND,OR) (Default = OR)',
  912.      *   'df'               => '(string) The default field for query string query (default: _all)',
  913.      *   'stored_fields'    => '(list) A comma-separated list of stored fields to return in the response',
  914.      *   'lenient'          => '(boolean) Specify whether format-based query failures (such as providing text to a numeric field) should be ignored',
  915.      *   'preference'       => '(string) Specify the node or shard the operation should be performed on (default: random)',
  916.      *   'q'                => '(string) Query in the Lucene query string syntax',
  917.      *   'routing'          => '(string) Specific routing value',
  918.      *   '_source'          => '(list) True or false to return the _source field or not, or a list of fields to return',
  919.      *   '_source_excludes' => '(list) A list of fields to exclude from the returned _source field',
  920.      *   '_source_includes' => '(list) A list of fields to extract and return from the _source field',
  921.      * ]
  922.      * @return callable|array
  923.      */
  924.     public function explain(array $params)
  925.     {
  926.         $id $this->extractArgument($params'id');
  927.         $index $this->extractArgument($params'index');
  928.         $type $this->extractArgument($params'type');
  929.         $body $this->extractArgument($params'body');
  930.         /**
  931.  * @var callable $endpointBuilder
  932. */
  933.         $endpointBuilder $this->endpoints;
  934.         /**
  935.  * @var \Elasticsearch\Endpoints\Explain $endpoint
  936. */
  937.         $endpoint $endpointBuilder('Explain');
  938.         $endpoint->setID($id)
  939.             ->setIndex($index)
  940.             ->setType($type)
  941.             ->setBody($body);
  942.         $endpoint->setParams($params);
  943.         return $this->performRequest($endpoint);
  944.     }
  945.     /**
  946.      * Endpoint: search
  947.      *
  948.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html
  949.      *
  950.      * $params[
  951.      *   'body'                          => '(string) The search definition using the Query DSL',
  952.      *   'index'                         => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices',
  953.      *   'type'                          => '(list) A comma-separated list of document types to search; leave empty to perform the operation on all types',
  954.      *   'analyzer'                      => '(string) The analyzer to use for the query string',
  955.      *   'analyze_wildcard'              => '(boolean) Specify whether wildcard and prefix queries should be analyzed (default: false)',
  956.      *   'ccs_minimize_roundtrips'       => '(boolean) Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution (Default = true)',
  957.      *   'default_operator'              => '(enum) The default operator for query string query (AND or OR) (Options = AND,OR) (Default = OR)',
  958.      *   'df'                            => '(string) The field to use as default where no field prefix is given in the query string',
  959.      *   'explain'                       => '(boolean) Specify whether to return detailed information about score computation as part of a hit',
  960.      *   'stored_fields'                 => '(list) A comma-separated list of stored fields to return as part of a hit',
  961.      *   'docvalue_fields'               => '(list) A comma-separated list of fields to return as the docvalue representation of a field for each hit',
  962.      *   'from'                          => '(number) Starting offset (default: 0)',
  963.      *   'ignore_unavailable'            => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  964.      *   'ignore_throttled'              => '(boolean) Whether specified concrete, expanded or aliased indices should be ignored when throttled',
  965.      *   'allow_no_indices'              => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  966.      *   'expand_wildcards'              => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  967.      *   'lenient'                       => '(boolean) Specify whether format-based query failures (such as providing text to a numeric field) should be ignored',
  968.      *   'preference'                    => '(string) Specify the node or shard the operation should be performed on (default: random)',
  969.      *   'q'                             => '(string) Query in the Lucene query string syntax',
  970.      *   'routing'                       => '(list) A comma-separated list of specific routing values',
  971.      *   'scroll'                        => '(time) Specify how long a consistent view of the index should be maintained for scrolled search',
  972.      *   'search_type'                   => '(enum) Search operation type (Options = query_then_fetch,dfs_query_then_fetch)',
  973.      *   'size'                          => '(number) Number of hits to return (default: 10)',
  974.      *   'sort'                          => '(list) A comma-separated list of <field>:<direction> pairs',
  975.      *   '_source'                       => '(list) True or false to return the _source field or not, or a list of fields to return',
  976.      *   '_source_excludes'              => '(list) A list of fields to exclude from the returned _source field',
  977.      *   '_source_includes'              => '(list) A list of fields to extract and return from the _source field',
  978.      *   'terminate_after'               => '(number) The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.',
  979.      *   'stats'                         => '(list) Specific 'tag' of the request for logging and statistical purposes',
  980.      *   'suggest_field'                 => '(string) Specify which field to use for suggestions',
  981.      *   'suggest_mode'                  => '(enum) Specify suggest mode (Options = missing,popular,always) (Default = missing)',
  982.      *   'suggest_size'                  => '(number) How many suggestions to return in response',
  983.      *   'suggest_text'                  => '(string) The source text for which the suggestions should be returned',
  984.      *   'timeout'                       => '(time) Explicit operation timeout',
  985.      *   'track_scores'                  => '(boolean) Whether to calculate and return scores even if they are not used for sorting',
  986.      *   'track_total_hits'              => '(boolean) Indicate if the number of documents that match the query should be tracked',
  987.      *   'allow_partial_search_results'  => '(boolean) Indicate if an error should be returned if there is a partial search failure or timeout (Default = true)',
  988.      *   'typed_keys'                    => '(boolean) Specify whether aggregation and suggester names should be prefixed by their respective types in the response',
  989.      *   'version'                       => '(boolean) Specify whether to return document version as part of a hit',
  990.      *   'seq_no_primary_term'           => '(boolean) Specify whether to return sequence number and primary term of the last modification of each hit',
  991.      *   'request_cache'                 => '(boolean) Specify if request cache should be used for this request or not, defaults to index level setting',
  992.      *   'batched_reduce_size'           => '(number) The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. (Default = 512)',
  993.      *   'max_concurrent_shard_requests' => '(number) The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests (Default = 5)',
  994.      *   'pre_filter_shard_size'         => '(number) A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. (Default = 128)',
  995.      *   'rest_total_hits_as_int'        => '(boolean) Indicates whether hits.total should be rendered as an integer or an object in the rest search response (Default = false)',
  996.      * ]
  997.      * @return callable|array
  998.      */
  999.     public function search(array $params = [])
  1000.     {
  1001.         $index $this->extractArgument($params'index');
  1002.         $type $this->extractArgument($params'type');
  1003.         $body $this->extractArgument($params'body');
  1004.         /**
  1005.  * @var callable $endpointBuilder
  1006. */
  1007.         $endpointBuilder $this->endpoints;
  1008.         /**
  1009.  * @var \Elasticsearch\Endpoints\Search $endpoint
  1010. */
  1011.         $endpoint $endpointBuilder('Search');
  1012.         $endpoint->setIndex($index)
  1013.             ->setType($type)
  1014.             ->setBody($body);
  1015.         $endpoint->setParams($params);
  1016.         return $this->performRequest($endpoint);
  1017.     }
  1018.     /**
  1019.      * Endpoint: search_shards
  1020.      *
  1021.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html
  1022.      *
  1023.      * $params[
  1024.      *   'index'              => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices',
  1025.      *   'preference'         => '(string) Specify the node or shard the operation should be performed on (default: random)',
  1026.      *   'routing'            => '(string) Specific routing value',
  1027.      *   'local'              => '(boolean) Return local information, do not retrieve the state from master node (default: false)',
  1028.      *   'ignore_unavailable' => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  1029.      *   'allow_no_indices'   => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  1030.      *   'expand_wildcards'   => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  1031.      * ]
  1032.      * @return callable|array
  1033.      */
  1034.     public function searchShards(array $params = [])
  1035.     {
  1036.         $index $this->extractArgument($params'index');
  1037.         $type $this->extractArgument($params'type');
  1038.         /**
  1039.  * @var callable $endpointBuilder
  1040. */
  1041.         $endpointBuilder $this->endpoints;
  1042.         /**
  1043.  * @var \Elasticsearch\Endpoints\SearchShards $endpoint
  1044. */
  1045.         $endpoint $endpointBuilder('SearchShards');
  1046.         $endpoint->setIndex($index)
  1047.             ->setType($type);
  1048.         $endpoint->setParams($params);
  1049.         return $this->performRequest($endpoint);
  1050.     }
  1051.     /**
  1052.      * Endpoint: search_template
  1053.      *
  1054.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html
  1055.      *
  1056.      * $params[
  1057.      *   'body'                    => '(string) The search definition template and its params (Required)',
  1058.      *   'index'                   => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices',
  1059.      *   'type'                    => '(list) A comma-separated list of document types to search; leave empty to perform the operation on all types',
  1060.      *   'ignore_unavailable'      => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  1061.      *   'ignore_throttled'        => '(boolean) Whether specified concrete, expanded or aliased indices should be ignored when throttled',
  1062.      *   'allow_no_indices'        => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  1063.      *   'expand_wildcards'        => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  1064.      *   'preference'              => '(string) Specify the node or shard the operation should be performed on (default: random)',
  1065.      *   'routing'                 => '(list) A comma-separated list of specific routing values',
  1066.      *   'scroll'                  => '(time) Specify how long a consistent view of the index should be maintained for scrolled search',
  1067.      *   'search_type'             => '(enum) Search operation type (Options = query_then_fetch,query_and_fetch,dfs_query_then_fetch,dfs_query_and_fetch)',
  1068.      *   'explain'                 => '(boolean) Specify whether to return detailed information about score computation as part of a hit',
  1069.      *   'profile'                 => '(boolean) Specify whether to profile the query execution',
  1070.      *   'typed_keys'              => '(boolean) Specify whether aggregation and suggester names should be prefixed by their respective types in the response',
  1071.      *   'rest_total_hits_as_int'  => '(boolean) Indicates whether hits.total should be rendered as an integer or an object in the rest search response (Default = false)',
  1072.      *   'ccs_minimize_roundtrips' => '(boolean) Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution (Default = true)',
  1073.      * ]
  1074.      * @return callable|array
  1075.      */
  1076.     public function searchTemplate(array $params = [])
  1077.     {
  1078.         $index $this->extractArgument($params'index');
  1079.         $type $this->extractArgument($params'type');
  1080.         $body $this->extractArgument($params'body');
  1081.         /**
  1082.  * @var callable $endpointBuilder
  1083. */
  1084.         $endpointBuilder $this->endpoints;
  1085.         /**
  1086.  * @var \Elasticsearch\Endpoints\Search $endpoint
  1087. */
  1088.         $endpoint $endpointBuilder('SearchTemplate');
  1089.         $endpoint->setIndex($index)
  1090.             ->setType($type)
  1091.             ->setBody($body);
  1092.         $endpoint->setParams($params);
  1093.         return $this->performRequest($endpoint);
  1094.     }
  1095.     /**
  1096.      * Endpoint: scroll
  1097.      *
  1098.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html
  1099.      *
  1100.      * $params[
  1101.      *   'body'                   => '(string) The scroll ID if not passed by URL or query parameter.',
  1102.      *   'scroll_id'              => '(string) The scroll ID',
  1103.      *   'scroll'                 => '(time) Specify how long a consistent view of the index should be maintained for scrolled search',
  1104.      *   'scroll_id'              => '(string) The scroll ID for scrolled search',
  1105.      *   'rest_total_hits_as_int' => '(boolean) Indicates whether hits.total should be rendered as an integer or an object in the rest search response (Default = false)',
  1106.      * ]
  1107.      * @return callable|array
  1108.      */
  1109.     public function scroll(array $params = [])
  1110.     {
  1111.         $scrollID $this->extractArgument($params'scroll_id');
  1112.         $body $this->extractArgument($params'body');
  1113.         /**
  1114.  * @var callable $endpointBuilder
  1115. */
  1116.         $endpointBuilder $this->endpoints;
  1117.         /**
  1118.  * @var \Elasticsearch\Endpoints\Scroll $endpoint
  1119. */
  1120.         $endpoint $endpointBuilder('Scroll');
  1121.         $endpoint->setScrollId($scrollID)
  1122.             ->setBody($body)
  1123.             ->setParams($params);
  1124.         return $this->performRequest($endpoint);
  1125.     }
  1126.     /**
  1127.      * $params['body'] = (string) The script to execute
  1128.      *
  1129.      * @return callable|array
  1130.      */
  1131.     public function scriptsPainlessExecute(array $params = [])
  1132.     {
  1133.         $body $this->extractArgument($params'body');
  1134.         /**
  1135.  * @var callable $endpointBuilder
  1136. */
  1137.         $endpointBuilder $this->endpoints;
  1138.         /**
  1139.  * @var \Elasticsearch\Endpoints\ScriptsPainlessExecute $endpoint
  1140. */
  1141.         $endpoint $endpointBuilder('ScriptsPainlessExecute');
  1142.         $endpoint->setBody($body);
  1143.         $endpoint->setParams($params);
  1144.         return $this->performRequest($endpoint);
  1145.     }
  1146.     /**
  1147.      * Endpoint: clear_scroll
  1148.      *
  1149.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html
  1150.      *
  1151.      * $params[
  1152.      *   'body'      => '(string) A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter',
  1153.      *   'scroll_id' => '(list) A comma-separated list of scroll IDs to clear',
  1154.      * ]
  1155.      * @return callable|array
  1156.      */
  1157.     public function clearScroll(array $params = [])
  1158.     {
  1159.         $scrollID $this->extractArgument($params'scroll_id');
  1160.         $body $this->extractArgument($params'body');
  1161.         /**
  1162.  * @var callable $endpointBuilder
  1163. */
  1164.         $endpointBuilder $this->endpoints;
  1165.         /**
  1166.  * @var \Elasticsearch\Endpoints\ClearScroll $endpoint
  1167. */
  1168.         $endpoint $endpointBuilder('ClearScroll');
  1169.         $endpoint->setScrollId($scrollID)
  1170.             ->setBody($body);
  1171.         $endpoint->setParams($params);
  1172.         return $this->performRequest($endpoint);
  1173.     }
  1174.     /**
  1175.      * Endpoint: update
  1176.      *
  1177.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html
  1178.      *
  1179.      * $params[
  1180.      *   'body'                   => '(string) The request definition requires either `script` or partial `doc` (Required)',
  1181.      *   'id'                     => '(string) Document ID (Required)',
  1182.      *   'index'                  => '(string) The name of the index (Required)',
  1183.      *   'type'                   => '(string) The type of the document',
  1184.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the update operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  1185.      *   '_source'                => '(list) True or false to return the _source field or not, or a list of fields to return',
  1186.      *   '_source_excludes'       => '(list) A list of fields to exclude from the returned _source field',
  1187.      *   '_source_includes'       => '(list) A list of fields to extract and return from the _source field',
  1188.      *   'lang'                   => '(string) The script language (default: painless)',
  1189.      *   'refresh'                => '(enum) If `true` then refresh the effected 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` (the default) then do nothing with refreshes. (Options = true,false,wait_for)',
  1190.      *   'retry_on_conflict'      => '(number) Specify how many times should the operation be retried when a conflict occurs (default: 0)',
  1191.      *   'routing'                => '(string) Specific routing value',
  1192.      *   'timeout'                => '(time) Explicit operation timeout',
  1193.      *   'if_seq_no'              => '(number) only perform the update operation if the last operation that has changed the document has the specified sequence number',
  1194.      *   'if_primary_term'        => '(number) only perform the update operation if the last operation that has changed the document has the specified primary term',
  1195.      * ]
  1196.      * @return callable|array
  1197.      */
  1198.     public function update(array $params)
  1199.     {
  1200.         $id $this->extractArgument($params'id');
  1201.         $index $this->extractArgument($params'index');
  1202.         $type $this->extractArgument($params'type');
  1203.         $body $this->extractArgument($params'body');
  1204.         /**
  1205.  * @var callable $endpointBuilder
  1206. */
  1207.         $endpointBuilder $this->endpoints;
  1208.         /**
  1209.  * @var \Elasticsearch\Endpoints\Update $endpoint
  1210. */
  1211.         $endpoint $endpointBuilder('Update');
  1212.         $endpoint->setID($id)
  1213.             ->setIndex($index)
  1214.             ->setType($type)
  1215.             ->setBody($body);
  1216.         $endpoint->setParams($params);
  1217.         return $this->performRequest($endpoint);
  1218.     }
  1219.     /**
  1220.      * Endpoint: update_by_query
  1221.      *
  1222.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html
  1223.      *
  1224.      * $params[
  1225.      *   'body'                   => '(string) The search definition using the Query DSL',
  1226.      *   'index'                  => '(list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices (Required)',
  1227.      *   'type'                   => '(list) A comma-separated list of document types to search; leave empty to perform the operation on all types',
  1228.      *   'analyzer'               => '(string) The analyzer to use for the query string',
  1229.      *   'analyze_wildcard'       => '(boolean) Specify whether wildcard and prefix queries should be analyzed (default: false)',
  1230.      *   'default_operator'       => '(enum) The default operator for query string query (AND or OR) (Options = AND,OR) (Default = OR)',
  1231.      *   'df'                     => '(string) The field to use as default where no field prefix is given in the query string',
  1232.      *   'from'                   => '(number) Starting offset (default: 0)',
  1233.      *   'ignore_unavailable'     => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  1234.      *   'allow_no_indices'       => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  1235.      *   'conflicts'              => '(enum) What to do when the update by query hits version conflicts? (Options = abort,proceed) (Default = abort)',
  1236.      *   'expand_wildcards'       => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  1237.      *   'lenient'                => '(boolean) Specify whether format-based query failures (such as providing text to a numeric field) should be ignored',
  1238.      *   'pipeline'               => '(string) Ingest pipeline to set on index requests made by this action. (default: none)',
  1239.      *   'preference'             => '(string) Specify the node or shard the operation should be performed on (default: random)',
  1240.      *   'q'                      => '(string) Query in the Lucene query string syntax',
  1241.      *   'routing'                => '(list) A comma-separated list of specific routing values',
  1242.      *   'scroll'                 => '(time) Specify how long a consistent view of the index should be maintained for scrolled search',
  1243.      *   'search_type'            => '(enum) Search operation type (Options = query_then_fetch,dfs_query_then_fetch)',
  1244.      *   'search_timeout'         => '(time) Explicit timeout for each search request. Defaults to no timeout.',
  1245.      *   'size'                   => '(number) Number of hits to return (default: 10)',
  1246.      *   'sort'                   => '(list) A comma-separated list of <field>:<direction> pairs',
  1247.      *   '_source'                => '(list) True or false to return the _source field or not, or a list of fields to return',
  1248.      *   '_source_excludes'       => '(list) A list of fields to exclude from the returned _source field',
  1249.      *   '_source_includes'       => '(list) A list of fields to extract and return from the _source field',
  1250.      *   'terminate_after'        => '(number) The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.',
  1251.      *   'stats'                  => '(list) Specific 'tag' of the request for logging and statistical purposes',
  1252.      *   'version'                => '(boolean) Specify whether to return document version as part of a hit',
  1253.      *   'version_type'           => '(boolean) Should the document increment the version number (internal) on hit or not (reindex)',
  1254.      *   'request_cache'          => '(boolean) Specify if request cache should be used for this request or not, defaults to index level setting',
  1255.      *   'refresh'                => '(boolean) Should the effected indexes be refreshed?',
  1256.      *   'timeout'                => '(time) Time each individual bulk request should wait for shards that are unavailable. (Default = 1m)',
  1257.      *   'wait_for_active_shards' => '(string) Sets the number of shard copies that must be active before proceeding with the update by query operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)',
  1258.      *   'scroll_size'            => '(number) Size on the scroll request powering the update by query',
  1259.      *   'wait_for_completion'    => '(boolean) Should the request should block until the update by query operation is complete. (Default = true)',
  1260.      *   'requests_per_second'    => '(number) The throttle to set on this request in sub-requests per second. -1 means no throttle. (Default = 0)',
  1261.      *   'slices'                 => '(number) The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks. (Default = 1)',
  1262.      * ]
  1263.      * @return callable|array
  1264.      */
  1265.     public function updateByQuery(array $params = [])
  1266.     {
  1267.         $index $this->extractArgument($params'index');
  1268.         $body $this->extractArgument($params'body');
  1269.         $type $this->extractArgument($params'type');
  1270.         /**
  1271.  * @var callable $endpointBuilder
  1272. */
  1273.         $endpointBuilder $this->endpoints;
  1274.         /**
  1275.  * @var \Elasticsearch\Endpoints\UpdateByQuery $endpoint
  1276. */
  1277.         $endpoint $endpointBuilder('UpdateByQuery');
  1278.         $endpoint->setIndex($index)
  1279.             ->setType($type)
  1280.             ->setBody($body);
  1281.         $endpoint->setParams($params);
  1282.         return $this->performRequest($endpoint);
  1283.     }
  1284.     /**
  1285.      * Endpoint: update_by_query_rethrottle
  1286.      *
  1287.      * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html
  1288.      *
  1289.      * $params[
  1290.      *   'task_id'             => '(string) The task id to rethrottle (Required)',
  1291.      *   'requests_per_second' => '(number) The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. (Required)',
  1292.      * ]
  1293.      * @return callable|array
  1294.      */
  1295.     public function updateByQueryRethrottle(array $params = [])
  1296.     {
  1297.         $taskId $this->extractArgument($params'task_id');
  1298.         /**
  1299.  * @var callable $endpointBuilder
  1300. */
  1301.         $endpointBuilder $this->endpoints;
  1302.         /**
  1303.  * @var \Elasticsearch\Endpoints\UpdateByQueryRethrottle $endpoint
  1304. */
  1305.         $endpoint $endpointBuilder('UpdateByQueryRethrottle');
  1306.         $endpoint->setTaskId($taskId);
  1307.         $endpoint->setParams($params);
  1308.         return $this->performRequest($endpoint);
  1309.     }
  1310.     /**
  1311.      * Endpoint: get_script
  1312.      *
  1313.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html
  1314.      *
  1315.      * $params[
  1316.      *   'id'             => '(string) Script ID (Required)',
  1317.      *   'master_timeout' => '(time) Specify timeout for connection to master',
  1318.      * ]
  1319.      * @return callable|array
  1320.      */
  1321.     public function getScript(array $params)
  1322.     {
  1323.         $id $this->extractArgument($params'id');
  1324.         /**
  1325.  * @var callable $endpointBuilder
  1326. */
  1327.         $endpointBuilder $this->endpoints;
  1328.         /**
  1329.  * @var \Elasticsearch\Endpoints\Script\Get $endpoint
  1330. */
  1331.         $endpoint $endpointBuilder('Script\Get');
  1332.         $endpoint->setID($id);
  1333.         $endpoint->setParams($params);
  1334.         return $this->performRequest($endpoint);
  1335.     }
  1336.     /**
  1337.      * Endpoint: delete_script
  1338.      *
  1339.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html
  1340.      *
  1341.      * $params[
  1342.      *   'id'             => '(string) Script ID (Required)',
  1343.      *   'timeout'        => '(time) Explicit operation timeout',
  1344.      *   'master_timeout' => '(time) Specify timeout for connection to master',
  1345.      * ]
  1346.      * @return callable|array
  1347.      */
  1348.     public function deleteScript(array $params)
  1349.     {
  1350.         $id $this->extractArgument($params'id');
  1351.         /**
  1352.  * @var callable $endpointBuilder
  1353. */
  1354.         $endpointBuilder $this->endpoints;
  1355.         /**
  1356.  * @var \Elasticsearch\Endpoints\Script\Delete $endpoint
  1357. */
  1358.         $endpoint $endpointBuilder('Script\Delete');
  1359.         $endpoint->setID($id);
  1360.         $endpoint->setParams($params);
  1361.         return $this->performRequest($endpoint);
  1362.     }
  1363.     /**
  1364.      * Endpoint: put_script
  1365.      *
  1366.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html
  1367.      *
  1368.      * $params[
  1369.      *   'body'           => '(string) The document (Required)',
  1370.      *   'id'             => '(string) Script ID (Required)',
  1371.      *   'context'        => '(string) Script context',
  1372.      *   'timeout'        => '(time) Explicit operation timeout',
  1373.      *   'master_timeout' => '(time) Specify timeout for connection to master',
  1374.      *   'context'        => '(string) Context name to compile script against',
  1375.      * ]
  1376.      * @return callable|array
  1377.      */
  1378.     public function putScript(array $params)
  1379.     {
  1380.         $id   $this->extractArgument($params'id');
  1381.         $body $this->extractArgument($params'body');
  1382.         /**
  1383.  * @var callable $endpointBuilder
  1384. */
  1385.         $endpointBuilder $this->endpoints;
  1386.         /**
  1387.  * @var \Elasticsearch\Endpoints\Script\Put $endpoint
  1388. */
  1389.         $endpoint $endpointBuilder('Script\Put');
  1390.         $endpoint->setID($id)
  1391.             ->setBody($body);
  1392.         $endpoint->setParams($params);
  1393.         return $this->performRequest($endpoint);
  1394.     }
  1395.     /**
  1396.      * $params['id']   = (string) The search template ID (Required)
  1397.      *
  1398.      * @return callable|array
  1399.      */
  1400.     public function getTemplate(array $params)
  1401.     {
  1402.         $id $this->extractArgument($params'id');
  1403.         /**
  1404.  * @var callable $endpointBuilder
  1405. */
  1406.         $endpointBuilder $this->endpoints;
  1407.         /**
  1408.  * @var \Elasticsearch\Endpoints\Template\Get $endpoint
  1409. */
  1410.         $endpoint $endpointBuilder('Template\Get');
  1411.         $endpoint->setID($id);
  1412.         $endpoint->setParams($params);
  1413.         return $this->performRequest($endpoint);
  1414.     }
  1415.     /**
  1416.      * $params['id']   = (string) The search template ID (Required)
  1417.      *
  1418.      * @return callable|array
  1419.      */
  1420.     public function deleteTemplate(array $params)
  1421.     {
  1422.         $id $this->extractArgument($params'id');
  1423.         /**
  1424.  * @var callable $endpointBuilder
  1425. */
  1426.         $endpointBuilder $this->endpoints;
  1427.         /**
  1428.  * @var \Elasticsearch\Endpoints\Template\Delete $endpoint
  1429. */
  1430.         $endpoint $endpointBuilder('Template\Delete');
  1431.         $endpoint->setID($id);
  1432.         $endpoint->setParams($params);
  1433.         return $this->performRequest($endpoint);
  1434.     }
  1435.     /**
  1436.      * Endpoint: field_caps
  1437.      *
  1438.      * @see http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.html
  1439.      *
  1440.      * $params[
  1441.      *   'index'              => '(list) A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices',
  1442.      *   'fields'             => '(list) A comma-separated list of field names',
  1443.      *   'ignore_unavailable' => '(boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)',
  1444.      *   'allow_no_indices'   => '(boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)',
  1445.      *   'expand_wildcards'   => '(enum) Whether to expand wildcard expression to concrete indices that are open, closed or both. (Options = open,closed,none,all) (Default = open)',
  1446.      *   'include_unmapped'   => '(boolean) Indicates whether unmapped fields should be included in the response. (Default = false)',
  1447.      * ]
  1448.      * @return callable|array
  1449.      */
  1450.     public function fieldCaps(array $params = [])
  1451.     {
  1452.         $index $this->extractArgument($params'index');
  1453.         /**
  1454.  * @var callable $endpointBuilder
  1455. */
  1456.         $endpointBuilder $this->endpoints;
  1457.         /**
  1458.  * @var \Elasticsearch\Endpoints\FieldCaps $endpoint
  1459. */
  1460.         $endpoint $endpointBuilder('FieldCaps');
  1461.         $endpoint->setIndex($index)
  1462.             ->setParams($params);
  1463.         return $this->performRequest($endpoint);
  1464.     }
  1465.     /**
  1466.      * Endpoint: render_search_template
  1467.      *
  1468.      * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html
  1469.      *
  1470.      * $params[
  1471.      *   'body' => '(string) The search definition template and its params',
  1472.      *   'id'   => '(string) The id of the stored search template',
  1473.      * ]
  1474.      * @return callable|array
  1475.      */
  1476.     public function renderSearchTemplate(array $params = [])
  1477.     {
  1478.         $body $this->extractArgument($params'body');
  1479.         $id   $this->extractArgument($params'id');
  1480.         /**
  1481.  * @var callable $endpointBuilder
  1482. */
  1483.         $endpointBuilder $this->endpoints;
  1484.         /**
  1485.  * @var \Elasticsearch\Endpoints\RenderSearchTemplate $endpoint
  1486. */
  1487.         $endpoint $endpointBuilder('RenderSearchTemplate');
  1488.         $endpoint->setBody($body)
  1489.             ->setID($id);
  1490.         $endpoint->setParams($params);
  1491.         return $this->performRequest($endpoint);
  1492.     }
  1493.     /**
  1494.      * Operate on the Indices Namespace of commands
  1495.      */
  1496.     public function indices(): IndicesNamespace
  1497.     {
  1498.         return $this->indices;
  1499.     }
  1500.     /**
  1501.      * Operate on the Cluster namespace of commands
  1502.      */
  1503.     public function cluster(): ClusterNamespace
  1504.     {
  1505.         return $this->cluster;
  1506.     }
  1507.     /**
  1508.      * Operate on the Nodes namespace of commands
  1509.      */
  1510.     public function nodes(): NodesNamespace
  1511.     {
  1512.         return $this->nodes;
  1513.     }
  1514.     /**
  1515.      * Operate on the Snapshot namespace of commands
  1516.      */
  1517.     public function snapshot(): SnapshotNamespace
  1518.     {
  1519.         return $this->snapshot;
  1520.     }
  1521.     /**
  1522.      * Operate on the Cat namespace of commands
  1523.      */
  1524.     public function cat(): CatNamespace
  1525.     {
  1526.         return $this->cat;
  1527.     }
  1528.     /**
  1529.      * Operate on the Ingest namespace of commands
  1530.      */
  1531.     public function ingest(): IngestNamespace
  1532.     {
  1533.         return $this->ingest;
  1534.     }
  1535.     /**
  1536.      * Operate on the Tasks namespace of commands
  1537.      */
  1538.     public function tasks(): TasksNamespace
  1539.     {
  1540.         return $this->tasks;
  1541.     }
  1542.     /**
  1543.      * Catchall for registered namespaces
  1544.      *
  1545.      * @return object
  1546.      * @throws BadMethodCallException if the namespace cannot be found
  1547.      */
  1548.     public function __call(string $name, array $arguments)
  1549.     {
  1550.         if (isset($this->registeredNamespaces[$name])) {
  1551.             return $this->registeredNamespaces[$name];
  1552.         }
  1553.         throw new BadMethodCallException("Namespace [$name] not found");
  1554.     }
  1555.     /**
  1556.      * @return null|mixed
  1557.      */
  1558.     public function extractArgument(array &$paramsstring $arg)
  1559.     {
  1560.         if (array_key_exists($arg$params) === true) {
  1561.             $value $params[$arg];
  1562.             $value is_object($value) ? (array) $value $value;
  1563.             unset($params[$arg]);
  1564.             return $value;
  1565.         } else {
  1566.             return null;
  1567.         }
  1568.     }
  1569.     private function verifyNotNullOrEmpty(string $name$var)
  1570.     {
  1571.         if ($var === null) {
  1572.             throw new InvalidArgumentException("$name cannot be null.");
  1573.         }
  1574.         if (is_string($var)) {
  1575.             if (strlen($var) === 0) {
  1576.                 throw new InvalidArgumentException("$name cannot be an empty string");
  1577.             }
  1578.         }
  1579.         if (is_array($var)) {
  1580.             if (strlen(implode(""$var)) === 0) {
  1581.                 throw new InvalidArgumentException("$name cannot be an array of empty strings");
  1582.             }
  1583.         }
  1584.     }
  1585.     /**
  1586.      * @return callable|array
  1587.      */
  1588.     private function performRequest(AbstractEndpoint $endpoint)
  1589.     {
  1590.         $promise =  $this->transport->performRequest(
  1591.             $endpoint->getMethod(),
  1592.             $endpoint->getURI(),
  1593.             $endpoint->getParams(),
  1594.             $endpoint->getBody(),
  1595.             $endpoint->getOptions()
  1596.         );
  1597.         return $this->transport->resultOrFuture($promise$endpoint->getOptions());
  1598.     }
  1599. }