Skip to content

Commit

Permalink
Update termsQuery
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Sep 3, 2024
1 parent 30f1846 commit ad3a608
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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)).

### Changed

Expand Down
26 changes: 20 additions & 6 deletions spec/schemas/_common.query_dsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,23 @@ components:
type: number
_name:
type: string
Terms:
oneOf:
- type: array
items:
type: string
- 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'
additionalProperties: true
description: Object for fetching terms.
BoostingQuery:
allOf:
- $ref: '#/components/schemas/QueryBase'
Expand Down Expand Up @@ -1857,9 +1874,9 @@ components:
required:
- value
TermsQuery:
allOf:
anyOf:
- $ref: '#/components/schemas/QueryBase'
- type: object
- $ref: '#/components/schemas/Terms'
TermsSetQuery:
allOf:
- $ref: '#/components/schemas/QueryBase'
Expand All @@ -1870,10 +1887,7 @@ components:
minimum_should_match_script:
$ref: '_common.yaml#/components/schemas/Script'
terms:
description: Array of terms you wish to find in the provided field.
type: array
items:
type: string
$ref: '#/components/schemas/Terms'
required:
- terms
TextExpansionQuery:
Expand Down
150 changes: 150 additions & 0 deletions tests/default/_core/search/query/terms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

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

prologues:
# Setup for movies index with all necessary fields
- 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]

# Setup for games index with all necessary fields
- path: /games
method: PUT
request:
payload:
mappings:
properties:
title:
type: text
genre:
type: keyword
developer_id:
type: keyword
status: [200]

- path: /games/_doc
method: POST
parameters:
refresh: true
request:
payload:
title: The Witcher 3

Check failure on line 63 in tests/default/_core/search/query/terms.yaml

View workflow job for this annotation

GitHub Actions / lint

Unknown word: "Witcher"
genre: RPG
status: [201]

- path: /games/_doc
method: POST
parameters:
refresh: true
request:
payload:
title: Cyberpunk 2077
genre: RPG
status: [201]

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

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

chapters:
# Test for TermsQuery with an array of terms
- synopsis: Search using TermsQuery with an array of terms.
path: /{index}/_search
parameters:
index: movies
method: GET
request:
payload:
query:
terms:
genre:
- Adventure
- Animation
response:
status: 200
payload:
timed_out: false
hits:
total:
value: 2
relation: eq
hits:
- _index: movies
_score: 1
_source:
title: The Lion King
genre: Animation
- _index: movies
_score: 1
_source:
title: Beauty and the Beast
genre: Adventure

# Test for TermsQuery with an array of terms in games index
- synopsis: Search using TermsQuery with an array of terms in the games index.
path: /{index}/_search
parameters:
index: games
method: GET
request:
payload:
query:
terms:
genre:
- RPG
response:
status: 200
payload:
timed_out: false
hits:
total:
value: 2
relation: eq
hits:
- _index: games
_score: 1
_source:
title: The Witcher 3

Check failure on line 144 in tests/default/_core/search/query/terms.yaml

View workflow job for this annotation

GitHub Actions / lint

Unknown word: "Witcher"
genre: RPG
- _index: games
_score: 1
_source:
title: Cyberpunk 2077
genre: RPG
86 changes: 86 additions & 0 deletions tests/default/_core/search/query/terms_set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
$schema: ../../../../../json_schemas/test_story.schema.yaml

description: Test TermsSetQuery functionality with complex example using movies.
version: '>= 1.2'

prologues:
- path: /movies
method: PUT
request:
payload:
mappings:
properties:
title:
type: keyword
genres:
type: keyword
min_required_genres:
type: integer

- path: /movies/_doc/1
method: POST
parameters:
refresh: true
request:
payload:
title: The Lion King
genres: [Animation, Adventure, Family]

Check failure on line 27 in tests/default/_core/search/query/terms_set.yaml

View workflow job for this annotation

GitHub Actions / lint

Expected sequence values to be in ascending order. 'Adventure' should be before 'Animation'
min_required_genres: 2
status: [201]

- path: /movies/_doc/2
method: POST
parameters:
refresh: true
request:
payload:
title: Beauty and the Beast
genres: [Animation, Musical, Family]

Check failure on line 38 in tests/default/_core/search/query/terms_set.yaml

View workflow job for this annotation

GitHub Actions / lint

Expected sequence values to be in ascending order. 'Family' should be before 'Musical'
min_required_genres: 2
status: [201]

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

chapters:
- synopsis: Search using TermsSetQuery with terms array and minimum_should_match_field.
path: /{index}/_search
parameters:
index: movies
method: POST
request:
payload:
query:
terms_set:
genres:
terms: [Animation, Adventure, Family]

Check failure on line 58 in tests/default/_core/search/query/terms_set.yaml

View workflow job for this annotation

GitHub Actions / lint

Expected sequence values to be in ascending order. 'Adventure' should be before 'Animation'
minimum_should_match_field: min_required_genres
response:
status: 200
payload:
timed_out: false
hits:
total:
value: 2
relation: eq
hits:
- _index: movies
_score: 1.4544616
_source:
title: The Lion King
genres:
- Animation
- Adventure

Check failure on line 75 in tests/default/_core/search/query/terms_set.yaml

View workflow job for this annotation

GitHub Actions / lint

Expected sequence values to be in ascending order. 'Adventure' should be before 'Animation'
- Family
min_required_genres: 2
- _index: movies
_score: 0.5013843
_source:
title: Beauty and the Beast
genres:
- Animation
- Musical
- Family

Check failure on line 85 in tests/default/_core/search/query/terms_set.yaml

View workflow job for this annotation

GitHub Actions / lint

Expected sequence values to be in ascending order. 'Family' should be before 'Musical'
min_required_genres: 2

0 comments on commit ad3a608

Please sign in to comment.