1<?php
2
3namespace Elastica\Query;
4
5/**
6 * geo_shape query for pre-indexed shapes.
7 *
8 * Query pre-indexed shape definitions
9 *
10 * @author Bennie Krijger <benniekrijger@gmail.com>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
13 */
14class GeoShapePreIndexed extends AbstractGeoShape
15{
16    /**
17     * elasticsearch id of the pre-indexed shape.
18     *
19     * @var string
20     */
21    protected $_indexedId;
22
23    /**
24     * elasticsearch type of the pre-indexed shape.
25     *
26     * @var string
27     */
28    protected $_indexedType;
29
30    /**
31     *  elasticsearch index of the pre-indexed shape.
32     *
33     * @var string
34     */
35    protected $_indexedIndex;
36
37    /**
38     *  elasticsearch path/field name of the pre-indexed shape.
39     *
40     * @var string
41     */
42    protected $_indexedPath;
43
44    /**
45     * Construct geo_shape query with a pre-indexed shape.
46     *
47     * @param string $path         The path/field of the shape searched
48     * @param string $indexedId    Id of the pre-indexed shape
49     * @param string $indexedType  Type of the pre-indexed shape
50     * @param string $indexedIndex Index of the pre-indexed shape
51     * @param string $indexedPath  Path of the pre-indexed shape
52     */
53    public function __construct(
54        string $path,
55        string $indexedId,
56        string $indexedType,
57        string $indexedIndex,
58        string $indexedPath
59    ) {
60        $this->_path = $path;
61        $this->_indexedId = $indexedId;
62        $this->_indexedType = $indexedType;
63        $this->_indexedIndex = $indexedIndex;
64        $this->_indexedPath = $indexedPath;
65    }
66
67    /**
68     * {@inheritdoc}
69     */
70    public function toArray(): array
71    {
72        return [
73            'geo_shape' => [
74                $this->_path => [
75                    'indexed_shape' => [
76                        'id' => $this->_indexedId,
77                        'type' => $this->_indexedType,
78                        'index' => $this->_indexedIndex,
79                        'path' => $this->_indexedPath,
80                    ],
81                    'relation' => $this->_relation,
82                ],
83            ],
84        ];
85    }
86}
87