Skip to content

Commit fa02743

Browse files
committed
add yml tests for partial updates and get API
1 parent ba65346 commit fa02743

File tree

4 files changed

+151
-12
lines changed

4 files changed

+151
-12
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/get.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
"type":"list",
6969
"description":"A list of fields to extract and return from the _source field"
7070
},
71+
"_source_exclude_vectors":{
72+
"type":"boolean",
73+
"description":"Whether vectors should be excluded from _source"
74+
},
7175
"version":{
7276
"type":"number",
7377
"description":"Explicit version number for concurrency control"

rest-api-spec/src/main/resources/rest-api-spec/api/search.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
"type":"list",
156156
"description":"A list of fields to extract and return from the _source field"
157157
},
158+
"_source_exclude_vectors":{
159+
"type":"boolean",
160+
"description":"Whether vectors should be excluded from _source"
161+
},
158162
"terminate_after":{
159163
"type":"number",
160164
"description":"The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early."

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/240_source_synthetic_vectors.yml

Lines changed: 139 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setup:
2121
type: keyword
2222
vector:
2323
type: dense_vector
24-
dims: 5
24+
dims: 3
2525
similarity: l2_norm
2626

2727
nested:
@@ -31,7 +31,7 @@ setup:
3131
type: keyword
3232
vector:
3333
type: dense_vector
34-
dims: 5
34+
dims: 3
3535
similarity: l2_norm
3636

3737
- do:
@@ -40,7 +40,7 @@ setup:
4040
id: "1"
4141
body:
4242
name: cow.jpg
43-
vector: [36, 267, -311, 12, -202]
43+
vector: [1, 2, 3]
4444

4545
- do:
4646
index:
@@ -50,19 +50,19 @@ setup:
5050
name: moose.jpg
5151
nested:
5252
- paragraph_id: 0
53-
vector: [-0.5, 100.0, -13, 14.8, -156.0]
53+
vector: [1, 2, 3]
5454
- paragraph_id: 2
55-
vector: [0, 100.0, 0, 14.8, -156.0]
55+
vector: [4, 5, 6]
5656
- paragraph_id: 3
57-
vector: [0, 1.0, 0, 1.8, -15.0]
57+
vector: [7, 8, 9]
5858

5959
- do:
6060
index:
6161
index: test
6262
id: "3"
6363
body:
6464
name: rabbit.jpg
65-
vector: [-0.5, 100.0, -13, 14.8, -156.0]
65+
vector: [10, 11, 12]
6666

6767
- do:
6868
index:
@@ -72,11 +72,10 @@ setup:
7272
name: zoolander.jpg
7373
nested:
7474
- paragraph_id: 0
75-
vector: [ -0.5, 100.0, -13, 14.8, -156.0 ]
75+
vector: [ 13, 14, 15 ]
7676
- paragraph_id: 1
7777
- paragraph_id: 2
78-
vector: [ -9.8, 109, 32, 14.8, 23 ]
79-
78+
vector: [ 16, 17, 18 ]
8079

8180
- do:
8281
indices.refresh: {}
@@ -148,4 +147,134 @@ setup:
148147
- match: { hits.hits.3._source.name: "zoolander.jpg" }
149148
- length: { hits.hits.3._source.nested: 3 }
150149
- exists: hits.hits.3._source.nested.0.vector
150+
- length: { hits.hits.3._source.nested.0.vector: 3 }
151151
- match: { hits.hits.3._source.nested.0.paragraph_id: 0 }
152+
153+
---
154+
"Bulk partial update with synthetic vectors":
155+
- do:
156+
headers:
157+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
158+
Content-Type: application/json
159+
bulk:
160+
index: test
161+
_source: true
162+
body:
163+
- '{"update": {"_id": "4"}}'
164+
- >
165+
{
166+
"doc": {
167+
"name": "zoolander2.jpg",
168+
"vector": [1, 2, 4]
169+
}
170+
}
171+
172+
- match: { items.0.update.get._source.vector: [1, 2, 4] }
173+
- exists: items.0.update.get._source.nested
174+
- length: { items.0.update.get._source.nested: 3}
175+
- exists: items.0.update.get._source.nested.0.vector
176+
- match: { items.0.update.get._source.nested.0.paragraph_id: 0 }
177+
- length: { items.0.update.get._source.nested.0.vector: 3 }
178+
- not_exists: items.0.update.get._source.nested.1.vector
179+
- match: { items.0.update.get._source.nested.1.paragraph_id: 1 }
180+
- exists: items.0.update.get._source.nested.2.vector
181+
- length: { items.0.update.get._source.nested.2.vector: 3 }
182+
- match: { items.0.update.get._source.nested.2.paragraph_id: 2 }
183+
- set: { items.0.update.get._source.nested: original_nested }
184+
185+
- do:
186+
headers:
187+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
188+
Content-Type: application/json
189+
get:
190+
_source_exclude_vectors: false
191+
index: test
192+
id: "4"
193+
194+
- match: { _source.vector: [1.0, 2.0, 4.0] }
195+
- match: { _source.name: zoolander2.jpg }
196+
- match: { _source.nested: $original_nested }
197+
198+
- do:
199+
indices.refresh: {}
200+
201+
- do:
202+
headers:
203+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
204+
Content-Type: application/json
205+
search:
206+
index: test
207+
body:
208+
_source:
209+
"exclude_vectors": false
210+
query:
211+
term:
212+
_id: 4
213+
214+
- match: { hits.total.value: 1 }
215+
- match: { hits.total.relation: eq }
216+
- match: { hits.hits.0._source.name: zoolander2.jpg }
217+
- match: { hits.hits.0._source.nested: $original_nested }
218+
219+
---
220+
"Partial update with synthetic vectors":
221+
- do:
222+
headers:
223+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
224+
Content-Type: application/json
225+
update:
226+
index: test
227+
id: "4"
228+
body:
229+
_source: true
230+
doc: {
231+
"name": "zoolander3.jpg",
232+
"vector": [6, 8, 9]
233+
}
234+
235+
- match: { get._source.vector: [6, 8, 9] }
236+
- exists: get._source.nested
237+
- length: { get._source.nested: 3}
238+
- exists: get._source.nested.0.vector
239+
- match: { get._source.nested.0.paragraph_id: 0 }
240+
- length: { get._source.nested.0.vector: 3 }
241+
- not_exists: get._source.nested.1.vector
242+
- match: { get._source.nested.1.paragraph_id: 1 }
243+
- exists: get._source.nested.2.vector
244+
- length: { get._source.nested.2.vector: 3 }
245+
- match: { get._source.nested.2.paragraph_id: 2 }
246+
- set: { get._source.nested: original_nested }
247+
248+
- do:
249+
headers:
250+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
251+
Content-Type: application/json
252+
get:
253+
_source_exclude_vectors: false
254+
index: test
255+
id: "4"
256+
257+
- match: { _source.vector: [6.0, 8.0, 9.0] }
258+
- match: { _source.name: zoolander3.jpg }
259+
- match: { _source.nested: $original_nested }
260+
261+
- do:
262+
indices.refresh: {}
263+
264+
- do:
265+
headers:
266+
# Force JSON content type so that we use a parser that interprets the embeddings as doubles
267+
Content-Type: application/json
268+
search:
269+
index: test
270+
body:
271+
_source:
272+
"exclude_vectors": false
273+
query:
274+
term:
275+
_id: 4
276+
277+
- match: { hits.total.value: 1 }
278+
- match: { hits.total.relation: eq }
279+
- match: { hits.hits.0._source.name: zoolander3.jpg }
280+
- match: { hits.hits.0._source.nested: $original_nested }

server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ public static FetchSourceContext parseFromRestRequest(RestRequest request) {
157157
sourceExcludes = Strings.splitStringByCommaToArray(sExcludes);
158158
}
159159

160-
if (fetchSource != null || sourceIncludes != null || sourceExcludes != null) {
161-
return FetchSourceContext.of(fetchSource == null || fetchSource, sourceIncludes, sourceExcludes);
160+
Boolean excludeVectors = request.paramAsBoolean("_source_exclude_vectors", null);
161+
162+
if (excludeVectors != null || fetchSource != null || sourceIncludes != null || sourceExcludes != null) {
163+
return FetchSourceContext.of(fetchSource == null || fetchSource, excludeVectors, sourceIncludes, sourceExcludes);
162164
}
163165
return null;
164166
}

0 commit comments

Comments
 (0)