Skip to content

Commit 762db01

Browse files
Update termsQuery
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent 30f1846 commit 762db01

File tree

4 files changed

+236
-6
lines changed

4 files changed

+236
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ 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 support for `query` with `terms` in `_search` ([#546](https://github.com/opensearch-project/opensearch-api-specification/pull/546)).
8788

8889
### Changed
8990

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:
+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
$schema: ../../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Comprehensive test suite for TermsQuery, including array of terms and term lookup.
4+
version: '>= 1.2'
5+
6+
prologues:
7+
- path: /movies
8+
method: PUT
9+
request:
10+
payload:
11+
mappings:
12+
properties:
13+
title:
14+
type: text
15+
genre:
16+
type: keyword
17+
director_id:
18+
type: keyword
19+
status: [200]
20+
21+
- path: /movies/_doc
22+
method: POST
23+
parameters:
24+
refresh: true
25+
request:
26+
payload:
27+
title: The Lion King
28+
genre: animation
29+
status: [201]
30+
31+
- path: /movies/_doc
32+
method: POST
33+
parameters:
34+
refresh: true
35+
request:
36+
payload:
37+
title: Beauty and the Beast
38+
genre: adventure
39+
status: [201]
40+
41+
# Setup for games index with all necessary fields
42+
- path: /games
43+
method: PUT
44+
request:
45+
payload:
46+
mappings:
47+
properties:
48+
title:
49+
type: text
50+
genre:
51+
type: keyword
52+
developer_id:
53+
type: keyword
54+
status: [200]
55+
56+
- path: /games/_doc
57+
method: POST
58+
parameters:
59+
refresh: true
60+
request:
61+
payload:
62+
title: Monopoly
63+
genre: RPG
64+
status: [201]
65+
66+
- path: /games/_doc
67+
method: POST
68+
parameters:
69+
refresh: true
70+
request:
71+
payload:
72+
title: Cyberpunk 2077
73+
genre: RPG
74+
status: [201]
75+
76+
epilogues:
77+
- path: /movies
78+
method: DELETE
79+
status: [200, 404]
80+
81+
- path: /games
82+
method: DELETE
83+
status: [200, 404]
84+
85+
chapters:
86+
# Test for TermsQuery with an array of terms
87+
- synopsis: Search using TermsQuery with an array of terms.
88+
path: /{index}/_search
89+
parameters:
90+
index: movies
91+
method: GET
92+
request:
93+
payload:
94+
query:
95+
terms:
96+
genre:
97+
- adventure
98+
- animation
99+
response:
100+
status: 200
101+
payload:
102+
timed_out: false
103+
hits:
104+
total:
105+
value: 2
106+
relation: eq
107+
hits:
108+
- _index: movies
109+
_score: 1
110+
_source:
111+
title: The Lion King
112+
genre: animation
113+
- _index: movies
114+
_score: 1
115+
_source:
116+
title: Beauty and the Beast
117+
genre: adventure
118+
119+
# Test for TermsQuery with an array of terms in games index
120+
- synopsis: Search using TermsQuery with an array of terms in the games index.
121+
path: /{index}/_search
122+
parameters:
123+
index: games
124+
method: GET
125+
request:
126+
payload:
127+
query:
128+
terms:
129+
genre:
130+
- RPG
131+
response:
132+
status: 200
133+
payload:
134+
timed_out: false
135+
hits:
136+
total:
137+
value: 2
138+
relation: eq
139+
hits:
140+
- _index: games
141+
_score: 1
142+
_source:
143+
title: Monopoly
144+
genre: RPG
145+
- _index: games
146+
_score: 1
147+
_source:
148+
title: Cyberpunk 2077
149+
genre: RPG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
$schema: ../../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test TermsSetQuery functionality with complex example using movies.
4+
version: '>= 1.2'
5+
6+
prologues:
7+
- path: /movies
8+
method: PUT
9+
request:
10+
payload:
11+
mappings:
12+
properties:
13+
title:
14+
type: keyword
15+
genres:
16+
type: keyword
17+
min_required_genres:
18+
type: integer
19+
20+
- path: /movies/_doc/1
21+
method: POST
22+
parameters:
23+
refresh: true
24+
request:
25+
payload:
26+
title: The Lion King
27+
genres: [Adventure, Animation, Family]
28+
min_required_genres: 2
29+
status: [201]
30+
31+
- path: /movies/_doc/2
32+
method: POST
33+
parameters:
34+
refresh: true
35+
request:
36+
payload:
37+
title: Beauty and the Beast
38+
genres: [Animation, Family, Musical]
39+
min_required_genres: 2
40+
status: [201]
41+
42+
epilogues:
43+
- path: /movies
44+
method: DELETE
45+
status: [200, 404]
46+
47+
chapters:
48+
- synopsis: Search using TermsSetQuery with terms array and minimum_should_match_field.
49+
path: /{index}/_search
50+
parameters:
51+
index: movies
52+
method: POST
53+
request:
54+
payload:
55+
query:
56+
terms_set:
57+
genres:
58+
terms: [Adventure, Animation, Family]
59+
minimum_should_match_field: min_required_genres
60+
response:
61+
status: 200
62+
payload:
63+
timed_out: false
64+
hits:
65+
total:
66+
value: 2

0 commit comments

Comments
 (0)