diff --git a/CHANGELOG.md b/CHANGELOG.md index 32325010b..9a91d71bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,9 @@ 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 schema for `Terms` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)). +- Add unit tests for `TermsQuery` and `TermsSetQuery` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)). + ### Changed @@ -98,6 +101,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Replace nullable with null type ([#436](https://github.com/opensearch-project/opensearch-api-specification/pull/436)) - Split test suite ([#472])(https://github.com/opensearch-project/opensearch-api-specification/pull/472) - Changed `WriteResponseBase`'s `_primary_term`, `_seq_no` & `_version` to have `int64` format ([#530](https://github.com/opensearch-project/opensearch-api-specification/pull/530)) +- Updated TermsQuery and TermsSetQuery to use the Terms schema ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)). ### Deprecated @@ -133,6 +137,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed query DSL `neural` field `query_image` set `contentEncoding` and `model_id` as optional ([#512](https://github.com/opensearch-project/opensearch-api-specification/pull/512)) - Fixed `knn` query specification ([#538](https://github.com/opensearch-project/opensearch-api-specification/pull/538)) - Fixed content-type for `/hot_threads` ([#543](https://github.com/opensearch-project/opensearch-api-specification/pull/543)) +- Fixed `TermsQuery` missing properties ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)). ### Security diff --git a/spec/schemas/_common.query_dsl.yaml b/spec/schemas/_common.query_dsl.yaml index 6633c043c..bb2c44c7d 100644 --- a/spec/schemas/_common.query_dsl.yaml +++ b/spec/schemas/_common.query_dsl.yaml @@ -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' @@ -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' @@ -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: diff --git a/tests/default/_core/search/terms_query_field.yaml b/tests/default/_core/search/terms_query_field.yaml new file mode 100644 index 000000000..88654f4cd --- /dev/null +++ b/tests/default/_core/search/terms_query_field.yaml @@ -0,0 +1,171 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Comprehensive test for TermsQuery, covering term lookup, boost, and array of terms, including nested fields. +version: '>= 1.2' + +prologues: + - path: /directors + method: PUT + request: + payload: + mappings: + properties: + name: + type: text + favorite_genre: + type: keyword + status: [200] + + - path: /directors/_doc/1 + method: POST + request: + payload: + name: John Doe + favorite_genre: Animation + status: [201] + + - 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: Animation + director_id: '1' + status: [201] + + - path: /movies/_doc + method: POST + parameters: + refresh: true + request: + payload: + title: The Lion King + genre: Animation + director_id: '1' + status: [201] + + - path: /classes + method: PUT + request: + payload: + mappings: + properties: + name: + type: text + enrolled_students: + properties: + id_list: + type: keyword + status: [200] + + - path: /classes/_doc/102 + method: POST + request: + payload: + name: CS102 + enrolled_students: + id_list: + - '111' + - '333' + status: [201] + + - path: /students + method: PUT + request: + payload: + mappings: + properties: + name: + type: text + student_id: + type: keyword + status: [200] + + - path: /students/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + name: Jane Doe + student_id: '111' + status: [201] + + - path: /students/_doc/3 + method: POST + parameters: + refresh: true + request: + payload: + name: John Doe + student_id: '333' + status: [201] + +epilogues: + - path: /movies + method: DELETE + status: [200, 404] + + - path: /directors + method: DELETE + status: [200, 404] + + - path: /classes + method: DELETE + status: [200, 404] + + - path: /students + method: DELETE + status: [200, 404] + +chapters: + - synopsis: Search using TermsQuery with an object for term lookup in nested fields. + path: /{index}/_search + parameters: + index: students + method: GET + request: + payload: + query: + terms: + student_id: + index: classes + id: '102' + path: enrolled_students.id_list + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 2 + relation: eq + hits: + - _index: students + _id: '1' + _score: 1 + _source: + name: Jane Doe + student_id: '111' + - _index: students + _id: '3' + _score: 1 + _source: + name: John Doe + student_id: '333' diff --git a/tests/default/_core/search/terms_query_multiple.yaml b/tests/default/_core/search/terms_query_multiple.yaml new file mode 100644 index 000000000..ca3f6275c --- /dev/null +++ b/tests/default/_core/search/terms_query_multiple.yaml @@ -0,0 +1,67 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test TermsQuery with an array of terms. +version: '>= 1.2' +prologues: + - path: /movies + method: PUT + request: + payload: + mappings: + properties: + title: + type: text + genre: + type: keyword + - 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] +epilogues: + - path: /movies + method: DELETE + status: [200, 404] +chapters: + - 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 \ No newline at end of file diff --git a/tests/default/_core/search/terms_set_query.yaml b/tests/default/_core/search/terms_set_query.yaml new file mode 100644 index 000000000..8fd3fe1fd --- /dev/null +++ b/tests/default/_core/search/terms_set_query.yaml @@ -0,0 +1,86 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test TermsSetQuery functionality with complex example. +version: '>= 1.2' + +prologues: + - path: /students + method: PUT + request: + payload: + mappings: + properties: + name: + type: keyword + classes: + type: keyword + min_required: + type: integer + + - path: /students/_doc/1 + method: POST + parameters: + refresh: true + request: + payload: + name: Mary Major + classes: [CS101, CS102, MATH101] + min_required: 2 + status: [201] + + - path: /students/_doc/2 + method: POST + parameters: + refresh: true + request: + payload: + name: John Doe + classes: [CS101, ENG101, MATH101] + min_required: 2 + status: [201] + +epilogues: + - path: /students + method: DELETE + status: [200, 404] + +chapters: + - synopsis: Search using TermsSetQuery with terms array and minimum_should_match_field. + path: /{index}/_search + parameters: + index: students + method: POST + request: + payload: + query: + terms_set: + classes: + terms: [CS101, CS102, MATH101] + minimum_should_match_field: min_required + response: + status: 200 + payload: + timed_out: false + hits: + total: + value: 2 + relation: eq + hits: + - _index: students + _score: 1.4544616 + _source: + name: Mary Major + classes: + - CS101 + - CS102 + - MATH101 + min_required: 2 + - _index: students + _score: 0.5013843 + _source: + name: John Doe + classes: + - CS101 + - ENG101 + - MATH101 + min_required: 2