Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues for termsQuery #570

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading