Skip to content

Commit

Permalink
fix issues for termsQuery (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
amberzsy committed Sep 16, 2024
1 parent f167e0d commit 811a5c9
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added `AwarenessAttributeStats` to `/_cluster/health` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
- Added `cache_reserved_in_bytes` to `ClusterFileSystem` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
- Added `cluster_manager` to `ClusterNodeCount` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
- Added support for `query` with `terms` in `_search` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546))([#564](https://github.com/opensearch-project/opensearch-api-specification/pull/564))
- Added support for `query` with `terms` in `_search` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546))([#564](https://github.com/opensearch-project/opensearch-api-specification/pull/564))([#570](https://github.com/opensearch-project/opensearch-api-specification/pull/570))
- Added `h`, `bytes`, `time` parameters to cat API tests ([#551](https://github.com/opensearch-project/opensearch-api-specification/pull/551))
- Added `terminated_early` to `count@200` ([#547](https://github.com/opensearch-project/opensearch-api-specification/pull/547))
- Added request and response schemas for `/_cluster/routing/awareness/{attribute}/weights` ([#524](https://github.com/opensearch-project/opensearch-api-specification/pull/524))
Expand Down
53 changes: 31 additions & 22 deletions spec/schemas/_common.query_dsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,9 @@ components:
minProperties: 1
maxProperties: 1
terms:
type: object
additionalProperties:
anyOf:
- $ref: '#/components/schemas/TermsQuery'
- type: array
items:
type: string
minProperties: 1
maxProperties: 1
description: |-
Returns documents that contain one or more exact terms in a provided field.
$ref: '#/components/schemas/TermsQueryField'
terms_set:
description: |-
Returns documents that contain a minimum number of exact terms in a provided field.
Expand Down Expand Up @@ -1877,19 +1871,34 @@ components:
type: boolean
required:
- value
TermsQuery:
anyOf:
- $ref: '#/components/schemas/QueryBase'
- type: object
properties:
index:
$ref: '_common.yaml#/components/schemas/IndexName'
id:
$ref: '_common.yaml#/components/schemas/Id'
path:
$ref: '_common.yaml#/components/schemas/Field'
routing:
$ref: '_common.yaml#/components/schemas/Routing'
TermsQueryField:
type: object
properties:
boost:
description:
|-
A floating-point value that specifies the weight of this field toward the relevance score.
Values above 1.0 increase the field’s relevance. Values between 0.0 and 1.0 decrease the field’s relevance.
Default is 1.0.
type: number
format: float
additionalProperties:
oneOf:
- $ref: '#/components/schemas/TermsLookupField'
- type: array
items:
type: string
TermsLookupField:
type: object
properties:
index:
$ref: '_common.yaml#/components/schemas/IndexName'
id:
$ref: '_common.yaml#/components/schemas/Id'
path:
$ref: '_common.yaml#/components/schemas/Field'
routing:
$ref: '_common.yaml#/components/schemas/Routing'
TermsSetQuery:
allOf:
- $ref: '#/components/schemas/QueryBase'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml
$schema: ../../../../../../json_schemas/test_story.schema.yaml

description: Comprehensive test suite for TermsQuery, including array of terms and term lookup.
description: Comprehensive test suite for TermsQuery, including array of terms.
version: '>= 1.2'

prologues:
Expand Down Expand Up @@ -143,4 +143,4 @@ chapters:
_score: 1
_source:
title: Cyberpunk 2077
genre: RPG
genre: RPG
62 changes: 62 additions & 0 deletions tests/default/_core/search/query/terms/array_terms_with_boost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
$schema: ../../../../../../json_schemas/test_story.schema.yaml

description: Comprehensive test suite for TermsQuery, including array of terms with boost top level parameter.
version: '>= 1.2'

prologues:
- path: /movies
method: PUT
request:
payload:
mappings:
properties:
title:
type: text
genre:
type: keyword
director_id:
type: keyword
status: [200]

- path: /movies/_doc
method: POST
parameters:
refresh: true
request:
payload:
title: Beauty and the Beast
genre: adventure
status: [201]

epilogues:
- path: /movies
method: DELETE
status: [200, 404]

chapters:
- synopsis: Search using TermsQuery with an array of terms with boost.
path: /{index}/_search
parameters:
index: movies
method: GET
request:
payload:
query:
terms:
boost: 1.6
genre:
- adventure
response:
status: 200
payload:
timed_out: false
hits:
total:
value: 1
relation: eq
hits:
- _index: movies
_score: 1.6
_source:
title: Beauty and the Beast
genre: adventure
99 changes: 99 additions & 0 deletions tests/default/_core/search/query/terms/terms_lookup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
$schema: ../../../../../../json_schemas/test_story.schema.yaml

description: Comprehensive test suite for TermsQuery, including term lookup.
version: '>= 1.2'

prologues:
- path: /movies
method: PUT
request:
payload:
mappings:
properties:
title:
type: text
genre:
type: keyword
director_id:
type: keyword
status: [200]

- path: /movies/_doc
method: POST
parameters:
refresh: true
request:
payload:
title: The Lion King
genre: animation
status: [201]

- path: /movies/_doc
method: POST
parameters:
refresh: true
request:
payload:
title: Beauty and the Beast
genre: adventure
status: [201]

- path: /theater
method: PUT
request:
payload:
mappings:
properties:
name:
type: text
genre:
type: keyword
status: [200]

- path: /theater/_doc/101
method: POST
parameters:
refresh: true
request:
payload:
name: AMC
genre: [adventure]
status: [201]

epilogues:
- path: /movies
method: DELETE
status: [200, 404]

- path: /theater
method: DELETE
status: [200, 404]

chapters:
- synopsis: Search using terms lookup.
path: /{index}/_search
parameters:
index: movies
method: GET
request:
payload:
query:
terms:
genre:
index: theater
id: '101'
path: genre
response:
status: 200
payload:
timed_out: false
hits:
total:
value: 1
relation: eq
hits:
- _index: movies
_score: 1
_source:
title: Beauty and the Beast
genre: adventure

0 comments on commit 811a5c9

Please sign in to comment.