MPercolate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Serializers\SerializerInterface;
  4. use Elasticsearch\Transport;
  5. /**
  6. * Class MPercolate
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints
  10. * @author Zachary Tong <zach@elastic.co>
  11. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  12. * @link http://elastic.co
  13. */
  14. class MPercolate extends AbstractEndpoint implements BulkEndpointInterface
  15. {
  16. /**
  17. * @param SerializerInterface $serializer
  18. */
  19. public function __construct(SerializerInterface $serializer)
  20. {
  21. $this->serializer = $serializer;
  22. }
  23. /**
  24. * @param string|array $body
  25. *
  26. * @return $this
  27. */
  28. public function setBody($body)
  29. {
  30. if (isset($body) !== true) {
  31. return $this;
  32. }
  33. if (is_array($body) === true) {
  34. $bulkBody = "";
  35. foreach ($body as $item) {
  36. $bulkBody .= $this->serializer->serialize($item)."\n";
  37. }
  38. $body = $bulkBody;
  39. }
  40. $this->body = $body;
  41. return $this;
  42. }
  43. /**
  44. * @return string
  45. */
  46. public function getURI()
  47. {
  48. return $this->getOptionalURI('_mpercolate');
  49. }
  50. /**
  51. * @return string[]
  52. */
  53. public function getParamWhitelist()
  54. {
  55. return array(
  56. 'ignore_unavailable',
  57. 'allow_no_indices',
  58. 'expand_wildcards',
  59. );
  60. }
  61. /**
  62. * @return string
  63. */
  64. public function getMethod()
  65. {
  66. return 'POST';
  67. }
  68. }