Skip to content

Commit

Permalink
Fix: _update_by_query with a term. (opensearch-project#451)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Jul 29, 2024
1 parent aec3145 commit 7cae0b8
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed `/_mapping` with `index` in query ([#385](https://github.com/opensearch-project/opensearch-api-specification/pull/385))
- Fixed duplicate `/_nodes/{node_id}` path ([#416](https://github.com/opensearch-project/opensearch-api-specification/pull/416))
- Fixed `_source` accepting an array of fields in `/_search` ([#430](https://github.com/opensearch-project/opensearch-api-specification/pull/430))
- Fixed `_update_by_query` with a simple term ([451](https://github.com/opensearch-project/opensearch-api-specification/pull/451))

### Security

Expand Down
4 changes: 3 additions & 1 deletion spec/schemas/_common.query_dsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ components:
To return a document, the query term must exactly match the queried field's value, including whitespace and capitalization.
type: object
additionalProperties:
$ref: '#/components/schemas/TermQuery'
anyOf:
- $ref: '#/components/schemas/TermQuery'
- $ref: '_common.yaml#/components/schemas/FieldValue'
minProperties: 1
maxProperties: 1
terms:
Expand Down
3 changes: 1 addition & 2 deletions spec/schemas/_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ components:
Specifies any named parameters that are passed into the script as variables.
Use parameters instead of hard-coded values to decrease compile time.
type: object
additionalProperties:
type: object
additionalProperties: true
StoredScriptId:
allOf:
- $ref: '#/components/schemas/ScriptBase'
Expand Down
71 changes: 0 additions & 71 deletions tests/_core/reindex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,7 @@ epilogues:
- path: /videos
method: DELETE
status: [200, 404]
- path: /_ingest/pipeline/transform-and-count
method: DELETE
status: [200, 404]
prologues:
- path: /_ingest/pipeline/transform-and-count
method: PUT
request_body:
payload:
description: |
Splits the `title`` field into a `words` list.
Computes the length of the title field and stores it in a new `length` field.
Removes the `year` field.
processors:
- split:
field: title
separator: '\s+'
target_field: words
- script:
lang: painless
source: ctx.length = ctx.words.length
- remove:
field: year
- path: /{index}/_doc
method: POST
parameters:
Expand Down Expand Up @@ -135,56 +114,6 @@ chapters:
status: 200
payload:
total: 1
- synopsis: Transform documents using a pipeline.
path: /_reindex
method: POST
request_body:
payload:
source:
index: movies
dest:
index: videos
pipeline: transform-and-count
response:
status: 200
- synopsis: Refresh the index.
path: /{index}/_refresh
method: POST
parameters:
index: videos
- synopsis: Get all videos.
path: /{index}/_search
method: POST
parameters:
index: videos
request_body:
payload:
query:
match_all: {}
response:
status: 200
payload:
hits:
hits:
- _index: videos
_source:
words:
- Beauty
- and
- the
# eslint-disable-next-line yml/sort-sequence-values
- Beast
length: 4
title: Beauty and the Beast
- synopsis: Update documents in the current index.
path: /{index}/_update_by_query
method: POST
parameters:
index: videos
response:
status: 200
payload:
updated: 1
- synopsis: Reindex from movies to films with all options.
path: /_reindex
method: POST
Expand Down
84 changes: 84 additions & 0 deletions tests/_core/reindex/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test reindex with a Search pipeline.
epilogues:
- path: /movies
method: DELETE
status: [200, 404]
- path: /videos
method: DELETE
status: [200, 404]
- path: /_ingest/pipeline/transform-and-count
method: DELETE
status: [200, 404]
prologues:
- path: /_ingest/pipeline/transform-and-count
method: PUT
request_body:
payload:
description: |
Splits the `title`` field into a `words` list.
Computes the length of the title field and stores it in a new `length` field.
Removes the `year` field.
processors:
- split:
field: title
separator: '\s+'
target_field: words
- script:
lang: painless
source: ctx.length = ctx.words.length
- remove:
field: year
- path: /{index}/_doc
method: POST
parameters:
index: movies
refresh: true
request_body:
payload:
title: Beauty and the Beast
year: 91
status: [201]
chapters:
- synopsis: Transform documents using a pipeline.
path: /_reindex
method: POST
request_body:
payload:
source:
index: movies
dest:
index: videos
pipeline: transform-and-count
response:
status: 200
- synopsis: Refresh the index.
path: /{index}/_refresh
method: POST
parameters:
index: videos
- synopsis: Get all videos.
path: /{index}/_search
method: POST
parameters:
index: videos
request_body:
payload:
query:
match_all: {}
response:
status: 200
payload:
hits:
hits:
- _index: videos
_source:
words:
- Beauty
- and
- the
# eslint-disable-next-line yml/sort-sequence-values
- Beast
length: 4
title: Beauty and the Beast
72 changes: 72 additions & 0 deletions tests/indices/update_by_query.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test reindex.
epilogues:
- path: /books
method: DELETE
status: [200, 404]
prologues:
- path: /_bulk
method: POST
parameters:
refresh: true
request_body:
content_type: application/x-ndjson
payload:
- {create: {_index: books, _id: book_1392214}}
- {author: Harper Lee, title: To Kill a Mockingbird, year: 60}
- {create: {_index: books, _id: book_1392215}}
- {author: Elizabeth Rudnick, title: Beauty and the Beast, year: 91}
chapters:
- synopsis: Update documents in the index.
path: /{index}/_update_by_query
method: POST
parameters:
index: books
refresh: true
response:
status: 200
payload:
updated: 2
- synopsis: Update documents in the index (full query term, script).
path: /{index}/_update_by_query
method: POST
parameters:
index: books
request_body:
payload:
query:
term:
title:
_name: title
value: beauty
case_insensitive: true
boost: 1
script:
source: ctx._source.year += params.century
lang: painless
params:
century: 1900
response:
status: 200
payload:
updated: 1
- synopsis: Update documents in the index (simple term, script).
path: /{index}/_update_by_query
method: POST
parameters:
index: books
request_body:
payload:
query:
term:
year: 60
script:
source: ctx._source.year += params.century
lang: painless
params:
century: 1900
response:
status: 200
payload:
updated: 1

0 comments on commit 7cae0b8

Please sign in to comment.