1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchDSL\Query\Compound; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\BuilderInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Represents Elasticsearch "indices" query. |
18
|
|
|
* |
19
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-query.html |
20
|
|
|
*/ |
21
|
|
|
class IndicesQuery implements BuilderInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string[] |
25
|
|
|
*/ |
26
|
|
|
private $indices; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var BuilderInterface |
30
|
|
|
*/ |
31
|
|
|
private $query; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string|BuilderInterface |
35
|
|
|
*/ |
36
|
|
|
private $noMatchQuery; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string[] $indices |
40
|
|
|
* @param BuilderInterface $query |
41
|
|
|
* @param BuilderInterface $noMatchQuery |
42
|
|
|
*/ |
43
|
|
|
public function __construct($indices, $query, $noMatchQuery = null) |
44
|
|
|
{ |
45
|
|
|
$this->indices = $indices; |
46
|
|
|
$this->query = $query; |
47
|
|
|
$this->noMatchQuery = $noMatchQuery; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getType() |
54
|
|
|
{ |
55
|
|
|
return 'indices'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function toArray() |
62
|
|
|
{ |
63
|
|
|
if (count($this->indices) > 1) { |
64
|
|
|
$output = ['indices' => $this->indices]; |
65
|
|
|
} else { |
66
|
|
|
$output = ['index' => $this->indices[0]]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$output['query'] = $this->query->toArray(); |
70
|
|
|
|
71
|
|
|
if ($this->noMatchQuery !== null) { |
72
|
|
|
if (is_a($this->noMatchQuery, 'ONGR\ElasticsearchDSL\BuilderInterface')) { |
73
|
|
|
$output['no_match_query'] = $this->noMatchQuery->toArray(); |
74
|
|
|
} else { |
75
|
|
|
$output['no_match_query'] = $this->noMatchQuery; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return [$this->getType() => $output]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|