Skip to content

Commit 4ac4c58

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

File tree

4 files changed

+237
-6
lines changed

4 files changed

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