Skip to content

Commit e60e61b

Browse files
Update termsQuery
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent 3f806a1 commit e60e61b

File tree

5 files changed

+349
-6
lines changed

5 files changed

+349
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
8484
- Added `AwarenessAttributeStats` to `/_cluster/health` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
8585
- Added `cache_reserved_in_bytes` to `ClusterFileSystem` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
8686
- Added `cluster_manager` to `ClusterNodeCount` ([#534](https://github.com/opensearch-project/opensearch-api-specification/pull/534))
87+
- Added schema for `Terms` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)).
88+
- Add unit tests for `TermsQuery` and `TermsSetQuery` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)).
89+
8790

8891
### Changed
8992

@@ -98,6 +101,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
98101
- Replace nullable with null type ([#436](https://github.com/opensearch-project/opensearch-api-specification/pull/436))
99102
- Split test suite ([#472])(https://github.com/opensearch-project/opensearch-api-specification/pull/472)
100103
- Changed `WriteResponseBase`'s `_primary_term`, `_seq_no` & `_version` to have `int64` format ([#530](https://github.com/opensearch-project/opensearch-api-specification/pull/530))
104+
- Updated TermsQuery and TermsSetQuery to use the Terms schema ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)).
101105

102106
### Deprecated
103107

@@ -133,6 +137,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
133137
- 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))
134138
- Fixed `knn` query specification ([#538](https://github.com/opensearch-project/opensearch-api-specification/pull/538))
135139
- Fixed content-type for `/hot_threads` ([#543](https://github.com/opensearch-project/opensearch-api-specification/pull/543))
140+
- Fixed `TermsQuery` missing properties ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)).
136141

137142
### Security
138143

spec/schemas/_common.query_dsl.yaml

+20-6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,23 @@ components:
280280
type: number
281281
_name:
282282
type: string
283+
Terms:
284+
oneOf:
285+
- type: array
286+
items:
287+
type: string
288+
- type: object
289+
properties:
290+
index:
291+
$ref: '_common.yaml#/components/schemas/IndexName'
292+
id:
293+
$ref: '_common.yaml#/components/schemas/Id'
294+
path:
295+
$ref: '_common.yaml#/components/schemas/Field'
296+
routing:
297+
$ref: '_common.yaml#/components/schemas/Routing'
298+
additionalProperties: true
299+
description: Object for fetching terms.
283300
BoostingQuery:
284301
allOf:
285302
- $ref: '#/components/schemas/QueryBase'
@@ -1857,9 +1874,9 @@ components:
18571874
required:
18581875
- value
18591876
TermsQuery:
1860-
allOf:
1877+
anyOf:
18611878
- $ref: '#/components/schemas/QueryBase'
1862-
- type: object
1879+
- $ref: '#/components/schemas/Terms'
18631880
TermsSetQuery:
18641881
allOf:
18651882
- $ref: '#/components/schemas/QueryBase'
@@ -1870,10 +1887,7 @@ components:
18701887
minimum_should_match_script:
18711888
$ref: '_common.yaml#/components/schemas/Script'
18721889
terms:
1873-
description: Array of terms you wish to find in the provided field.
1874-
type: array
1875-
items:
1876-
type: string
1890+
$ref: '#/components/schemas/Terms'
18771891
required:
18781892
- terms
18791893
TextExpansionQuery:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
$schema: ../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Comprehensive test for TermsQuery, covering term lookup, boost, and array of terms, including nested fields.
4+
version: '>= 1.2'
5+
6+
prologues:
7+
- path: /directors
8+
method: PUT
9+
request:
10+
payload:
11+
mappings:
12+
properties:
13+
name:
14+
type: text
15+
favorite_genre:
16+
type: keyword
17+
status: [200]
18+
19+
- path: /directors/_doc/1
20+
method: POST
21+
request:
22+
payload:
23+
name: John Doe
24+
favorite_genre: Animation
25+
status: [201]
26+
27+
- path: /movies
28+
method: PUT
29+
request:
30+
payload:
31+
mappings:
32+
properties:
33+
title:
34+
type: text
35+
genre:
36+
type: keyword
37+
director_id:
38+
type: keyword
39+
status: [200]
40+
41+
- path: /movies/_doc
42+
method: POST
43+
parameters:
44+
refresh: true
45+
request:
46+
payload:
47+
title: Beauty and the Beast
48+
genre: Animation
49+
director_id: '1'
50+
status: [201]
51+
52+
- path: /movies/_doc
53+
method: POST
54+
parameters:
55+
refresh: true
56+
request:
57+
payload:
58+
title: The Lion King
59+
genre: Animation
60+
director_id: '1'
61+
status: [201]
62+
63+
- path: /classes
64+
method: PUT
65+
request:
66+
payload:
67+
mappings:
68+
properties:
69+
name:
70+
type: text
71+
enrolled_students:
72+
properties:
73+
id_list:
74+
type: keyword
75+
status: [200]
76+
77+
- path: /classes/_doc/102
78+
method: POST
79+
request:
80+
payload:
81+
name: CS102
82+
enrolled_students:
83+
id_list:
84+
- '111'
85+
- '333'
86+
status: [201]
87+
88+
- path: /students
89+
method: PUT
90+
request:
91+
payload:
92+
mappings:
93+
properties:
94+
name:
95+
type: text
96+
student_id:
97+
type: keyword
98+
status: [200]
99+
100+
- path: /students/_doc/1
101+
method: POST
102+
parameters:
103+
refresh: true
104+
request:
105+
payload:
106+
name: Jane Doe
107+
student_id: '111'
108+
status: [201]
109+
110+
- path: /students/_doc/3
111+
method: POST
112+
parameters:
113+
refresh: true
114+
request:
115+
payload:
116+
name: John Doe
117+
student_id: '333'
118+
status: [201]
119+
120+
epilogues:
121+
- path: /movies
122+
method: DELETE
123+
status: [200, 404]
124+
125+
- path: /directors
126+
method: DELETE
127+
status: [200, 404]
128+
129+
- path: /classes
130+
method: DELETE
131+
status: [200, 404]
132+
133+
- path: /students
134+
method: DELETE
135+
status: [200, 404]
136+
137+
chapters:
138+
- synopsis: Search using TermsQuery with an object for term lookup in nested fields.
139+
path: /{index}/_search
140+
parameters:
141+
index: students
142+
method: GET
143+
request:
144+
payload:
145+
query:
146+
terms:
147+
student_id:
148+
index: classes
149+
id: '102'
150+
path: enrolled_students.id_list
151+
response:
152+
status: 200
153+
payload:
154+
timed_out: false
155+
hits:
156+
total:
157+
value: 2
158+
relation: eq
159+
hits:
160+
- _index: students
161+
_id: '1'
162+
_score: 1
163+
_source:
164+
name: Jane Doe
165+
student_id: '111'
166+
- _index: students
167+
_id: '3'
168+
_score: 1
169+
_source:
170+
name: John Doe
171+
student_id: '333'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
$schema: ../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test TermsQuery with an array of terms.
4+
version: '>= 1.2'
5+
prologues:
6+
- path: /movies
7+
method: PUT
8+
request:
9+
payload:
10+
mappings:
11+
properties:
12+
title:
13+
type: text
14+
genre:
15+
type: keyword
16+
- path: /movies/_doc
17+
method: POST
18+
parameters:
19+
refresh: true
20+
request:
21+
payload:
22+
title: The Lion King
23+
genre: Animation
24+
status: [201]
25+
- path: /movies/_doc
26+
method: POST
27+
parameters:
28+
refresh: true
29+
request:
30+
payload:
31+
title: Beauty and the Beast
32+
genre: Adventure
33+
status: [201]
34+
epilogues:
35+
- path: /movies
36+
method: DELETE
37+
status: [200, 404]
38+
chapters:
39+
- synopsis: Search using TermsQuery with an array of terms.
40+
path: /{index}/_search
41+
parameters:
42+
index: movies
43+
method: GET
44+
request:
45+
payload:
46+
query:
47+
terms:
48+
genre: [Adventure,Animation]
49+
response:
50+
status: 200
51+
payload:
52+
timed_out: false
53+
hits:
54+
total:
55+
value: 2
56+
relation: eq
57+
hits:
58+
- _index: movies
59+
_score: 1
60+
_source:
61+
title: The Lion King
62+
genre: Animation
63+
- _index: movies
64+
_score: 1
65+
_source:
66+
title: Beauty and the Beast
67+
genre: Adventure

0 commit comments

Comments
 (0)