Skip to content

Commit e683594

Browse files
committed
add REST testcase to cover context, weight and geofield searches
1 parent 0770db9 commit e683594

File tree

3 files changed

+305
-46
lines changed

3 files changed

+305
-46
lines changed
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
2+
---
3+
"Search by suggestion and by keyword sub-field should work":
4+
5+
- do:
6+
indices.create:
7+
index: completion_with_sub_keyword
8+
body:
9+
mappings:
10+
test:
11+
"properties":
12+
"suggest_1":
13+
"type" : "completion"
14+
"fields":
15+
"text_raw":
16+
"type" : "keyword"
17+
18+
- do:
19+
index:
20+
index: completion_with_sub_keyword
21+
type: test
22+
id: 1
23+
body:
24+
suggest_1: "bar"
25+
26+
- do:
27+
index:
28+
index: completion_with_sub_keyword
29+
type: test
30+
id: 2
31+
body:
32+
suggest_1: "baz"
33+
34+
- do:
35+
indices.refresh: {}
36+
37+
- do:
38+
search:
39+
index: completion_with_sub_keyword
40+
body:
41+
suggest:
42+
result:
43+
text: "b"
44+
completion:
45+
field: suggest_1
46+
47+
- length: { suggest.result: 1 }
48+
- length: { suggest.result.0.options: 2 }
49+
50+
51+
- do:
52+
search:
53+
index: completion_with_sub_keyword
54+
body:
55+
query: { term: { suggest_1.text_raw: "bar" }}
56+
57+
- match: { hits.total: 1 }
58+
59+
60+
61+
---
62+
"Search by suggestion on sub field should work":
63+
64+
- do:
65+
indices.create:
66+
index: completion_with_sub_completion
67+
body:
68+
mappings:
69+
test:
70+
"properties":
71+
"suggest_1":
72+
"type": "completion"
73+
"fields":
74+
"suggest_2":
75+
"type": "completion"
76+
77+
- do:
78+
index:
79+
index: completion_with_sub_completion
80+
type: test
81+
id: 1
82+
body:
83+
suggest_1: "bar"
84+
85+
- do:
86+
index:
87+
index: completion_with_sub_completion
88+
type: test
89+
id: 2
90+
body:
91+
suggest_1: "baz"
92+
93+
- do:
94+
indices.refresh: {}
95+
96+
- do:
97+
search:
98+
index: completion_with_sub_completion
99+
body:
100+
suggest:
101+
result:
102+
text: "b"
103+
completion:
104+
field: suggest_1.suggest_2
105+
106+
- length: { suggest.result: 1 }
107+
- length: { suggest.result.0.options: 2 }
108+
109+
---
110+
"Search by suggestion on sub field with context should work":
111+
112+
- do:
113+
indices.create:
114+
index: completion_with_context
115+
body:
116+
mappings:
117+
test:
118+
"properties":
119+
"suggest_1":
120+
"type": "completion"
121+
"contexts":
122+
-
123+
"name": "color"
124+
"type": "category"
125+
"fields":
126+
"suggest_2":
127+
"type": "completion"
128+
"contexts":
129+
-
130+
"name": "color"
131+
"type": "category"
132+
133+
134+
- do:
135+
index:
136+
index: completion_with_context
137+
type: test
138+
id: 1
139+
body:
140+
suggest_1:
141+
input: "foo red"
142+
contexts:
143+
color: "red"
144+
145+
- do:
146+
index:
147+
index: completion_with_context
148+
type: test
149+
id: 2
150+
body:
151+
suggest_1:
152+
input: "foo blue"
153+
contexts:
154+
color: "blue"
155+
156+
- do:
157+
indices.refresh: {}
158+
159+
- do:
160+
search:
161+
index: completion_with_context
162+
body:
163+
suggest:
164+
result:
165+
prefix: "foo"
166+
completion:
167+
field: suggest_1.suggest_2
168+
contexts:
169+
color: "red"
170+
171+
- length: { suggest.result: 1 }
172+
- length: { suggest.result.0.options: 1 }
173+
- match: { suggest.result.0.options.0.text: "foo red" }
174+
175+
176+
---
177+
"Search by suggestion on sub field with weight should work":
178+
179+
- do:
180+
indices.create:
181+
index: completion_with_weight
182+
body:
183+
mappings:
184+
test:
185+
"properties":
186+
"suggest_1":
187+
"type": "completion"
188+
"fields":
189+
"suggest_2":
190+
"type": "completion"
191+
192+
- do:
193+
index:
194+
index: completion_with_weight
195+
type: test
196+
id: 1
197+
body:
198+
suggest_1:
199+
input: "bar"
200+
weight: 2
201+
202+
- do:
203+
index:
204+
index: completion_with_weight
205+
type: test
206+
id: 2
207+
body:
208+
suggest_1:
209+
input: "baz"
210+
weight: 3
211+
212+
- do:
213+
indices.refresh: {}
214+
215+
- do:
216+
search:
217+
index: completion_with_weight
218+
body:
219+
suggest:
220+
result:
221+
text: "b"
222+
completion:
223+
field: suggest_1.suggest_2
224+
225+
- length: { suggest.result: 1 }
226+
- length: { suggest.result.0.options: 2 }
227+
- match: { suggest.result.0.options.0.text: "baz" }
228+
- match: { suggest.result.0.options.1.text: "bar" }
229+
230+
---
231+
"Search by suggestion on geofield-hash on sub field should work":
232+
233+
- do:
234+
indices.create:
235+
index: geofield_with_completion
236+
body:
237+
mappings:
238+
test:
239+
"properties":
240+
"geofield":
241+
"type": "geo_point"
242+
"fields":
243+
"suggest_1":
244+
"type": "completion"
245+
246+
- do:
247+
index:
248+
index: geofield_with_completion
249+
type: test
250+
id: 1
251+
body:
252+
geofield: "hgjhrwysvqw7"
253+
#41.12,-72.34,12
254+
255+
- do:
256+
index:
257+
index: geofield_with_completion
258+
type: test
259+
id: 1
260+
body:
261+
geofield: "hgm4psywmkn7"
262+
#41.12,-71.34,12
263+
264+
- do:
265+
indices.refresh: {}
266+
267+
- do:
268+
search:
269+
index: geofield_with_completion
270+
body:
271+
suggest:
272+
result:
273+
prefix: "hgm"
274+
completion:
275+
field: geofield.suggest_1
276+
277+
278+
- length: { suggest.result: 1 }
279+
- length: { suggest.result.0.options: 1 }

server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ private boolean isExternalValueOfClass(ParseContext context, Class<?> clazz) {
501501
return context.externalValue().getClass().equals(clazz);
502502
}
503503

504-
505504
/**
506505
* Acceptable inputs:
507506
* "STRING" - interpreted as the field value (input)

0 commit comments

Comments
 (0)