Skip to content

Commit 4ba0136

Browse files
committed
Fix OpenSearch mapping field types
1 parent ec42237 commit 4ba0136

3 files changed

Lines changed: 153 additions & 15 deletions

File tree

src/Indices/Mapping.php

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function date(string $name, array $parameters = []): self
163163
/**
164164
* Add a date nanos field definition.
165165
*
166-
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/date/
166+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/date-nanos/
167167
*
168168
* @param array<string, mixed> $parameters
169169
*/
@@ -189,15 +189,29 @@ public function dateRange(string $name, array $parameters = []): self
189189
}
190190

191191
/**
192-
* Add a dense vector field definition.
192+
* Add a k-NN vector field definition.
193+
*
194+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/knn-vector/
195+
*
196+
* @param array<string, mixed> $parameters
197+
*/
198+
public function knnVector(string $name, array $parameters = []): self
199+
{
200+
$this->properties->knnVector($name, $parameters);
201+
202+
return $this;
203+
}
204+
205+
/**
206+
* Add a k-NN vector field definition.
193207
*
194208
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/knn-vector/
195209
*
196210
* @param array<string, mixed> $parameters
197211
*/
198212
public function denseVector(string $name, array $parameters = []): self
199213
{
200-
$this->properties->denseVector($name, $parameters);
214+
$this->properties->knnVector($name, $parameters);
201215

202216
return $this;
203217
}
@@ -231,15 +245,29 @@ public function doubleRange(string $name, array $parameters = []): self
231245
}
232246

233247
/**
234-
* Add a flattened field definition.
248+
* Add a flat object field definition.
249+
*
250+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/flat-object/
251+
*
252+
* @param array<string, mixed> $parameters
253+
*/
254+
public function flatObject(string $name, array $parameters = []): self
255+
{
256+
$this->properties->flatObject($name, $parameters);
257+
258+
return $this;
259+
}
260+
261+
/**
262+
* Add a flat object field definition.
235263
*
236264
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/flat-object/
237265
*
238266
* @param array<string, mixed> $parameters
239267
*/
240268
public function flattened(string $name, array $parameters = []): self
241269
{
242-
$this->properties->flattened($name, $parameters);
270+
$this->properties->flatObject($name, $parameters);
243271

244272
return $this;
245273
}
@@ -275,7 +303,7 @@ public function floatRange(string $name, array $parameters = []): self
275303
/**
276304
* Add a geo point field definition.
277305
*
278-
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/geopoint/
306+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/geo-point/
279307
*
280308
* @param array<string, mixed> $parameters
281309
*/
@@ -289,7 +317,7 @@ public function geoPoint(string $name, array $parameters = []): self
289317
/**
290318
* Add a geo shape field definition.
291319
*
292-
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/geoshape/
320+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/geo-shape/
293321
*
294322
* @param array<string, mixed> $parameters
295323
*/
@@ -539,15 +567,29 @@ public function searchAsYouType(string $name, array $parameters = []): self
539567
}
540568

541569
/**
542-
* Add a shape field definition.
570+
* Add an xy shape field definition.
571+
*
572+
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/xy-shape/
573+
*
574+
* @param array<string, mixed> $parameters
575+
*/
576+
public function xyShape(string $name, array $parameters = []): self
577+
{
578+
$this->properties->xyShape($name, $parameters);
579+
580+
return $this;
581+
}
582+
583+
/**
584+
* Add an xy shape field definition.
543585
*
544586
* @see https://docs.opensearch.org/latest/mappings/supported-field-types/xy-shape/
545587
*
546588
* @param array<string, mixed> $parameters
547589
*/
548590
public function shape(string $name, array $parameters = []): self
549591
{
550-
$this->properties->shape($name, $parameters);
592+
$this->properties->xyShape($name, $parameters);
551593

552594
return $this;
553595
}

src/Indices/MappingProperties.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,23 @@ public function dateRange(string $name, array $parameters = []): self
120120
}
121121

122122
/**
123-
* Add a dense vector field definition.
123+
* Add a k-NN vector field definition.
124+
*
125+
* @param array<string, mixed> $parameters
126+
*/
127+
public function knnVector(string $name, array $parameters = []): self
128+
{
129+
return $this->field($name, 'knn_vector', $parameters);
130+
}
131+
132+
/**
133+
* Add a k-NN vector field definition.
124134
*
125135
* @param array<string, mixed> $parameters
126136
*/
127137
public function denseVector(string $name, array $parameters = []): self
128138
{
129-
return $this->field($name, 'dense_vector', $parameters);
139+
return $this->knnVector($name, $parameters);
130140
}
131141

132142
/**
@@ -150,13 +160,23 @@ public function doubleRange(string $name, array $parameters = []): self
150160
}
151161

152162
/**
153-
* Add a flattened field definition.
163+
* Add a flat object field definition.
164+
*
165+
* @param array<string, mixed> $parameters
166+
*/
167+
public function flatObject(string $name, array $parameters = []): self
168+
{
169+
return $this->field($name, 'flat_object', $parameters);
170+
}
171+
172+
/**
173+
* Add a flat object field definition.
154174
*
155175
* @param array<string, mixed> $parameters
156176
*/
157177
public function flattened(string $name, array $parameters = []): self
158178
{
159-
return $this->field($name, 'flattened', $parameters);
179+
return $this->flatObject($name, $parameters);
160180
}
161181

162182
/**
@@ -382,13 +402,23 @@ public function searchAsYouType(string $name, array $parameters = []): self
382402
}
383403

384404
/**
385-
* Add a shape field definition.
405+
* Add an xy shape field definition.
406+
*
407+
* @param array<string, mixed> $parameters
408+
*/
409+
public function xyShape(string $name, array $parameters = []): self
410+
{
411+
return $this->field($name, 'xy_shape', $parameters);
412+
}
413+
414+
/**
415+
* Add an xy shape field definition.
386416
*
387417
* @param array<string, mixed> $parameters
388418
*/
389419
public function shape(string $name, array $parameters = []): self
390420
{
391-
return $this->field($name, 'shape', $parameters);
421+
return $this->xyShape($name, $parameters);
392422
}
393423

394424
/**

tests/Unit/Indices/MappingPropertiesTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,72 @@
4141
],
4242
],
4343
],
44+
[
45+
'type' => 'flatObject',
46+
'name' => 'metadata',
47+
'parameters' => [],
48+
'expected' => [
49+
'metadata' => [
50+
'type' => 'flat_object',
51+
],
52+
],
53+
],
54+
[
55+
'type' => 'flattened',
56+
'name' => 'metadata',
57+
'parameters' => [],
58+
'expected' => [
59+
'metadata' => [
60+
'type' => 'flat_object',
61+
],
62+
],
63+
],
64+
[
65+
'type' => 'knnVector',
66+
'name' => 'embedding',
67+
'parameters' => [
68+
'dimension' => 1536,
69+
],
70+
'expected' => [
71+
'embedding' => [
72+
'type' => 'knn_vector',
73+
'dimension' => 1536,
74+
],
75+
],
76+
],
77+
[
78+
'type' => 'denseVector',
79+
'name' => 'embedding',
80+
'parameters' => [
81+
'dimension' => 1536,
82+
],
83+
'expected' => [
84+
'embedding' => [
85+
'type' => 'knn_vector',
86+
'dimension' => 1536,
87+
],
88+
],
89+
],
90+
[
91+
'type' => 'xyShape',
92+
'name' => 'bounds',
93+
'parameters' => [],
94+
'expected' => [
95+
'bounds' => [
96+
'type' => 'xy_shape',
97+
],
98+
],
99+
],
100+
[
101+
'type' => 'shape',
102+
'name' => 'bounds',
103+
'parameters' => [],
104+
'expected' => [
105+
'bounds' => [
106+
'type' => 'xy_shape',
107+
],
108+
],
109+
],
44110
[
45111
'type' => 'object',
46112
'name' => 'user',

0 commit comments

Comments
 (0)