@@ -171,6 +171,106 @@ public void testHighlightingWithWildcardName() throws IOException {
171171 }
172172 }
173173
174+ public void testFieldAlias () throws IOException {
175+ XContentBuilder mappings = jsonBuilder ()
176+ .startObject ()
177+ .startObject ("type" )
178+ .startObject ("properties" )
179+ .startObject ("text" )
180+ .field ("type" , "text" )
181+ .field ("store" , true )
182+ .field ("term_vector" , "with_positions_offsets" )
183+ .endObject ()
184+ .startObject ("alias" )
185+ .field ("type" , "alias" )
186+ .field ("path" , "text" )
187+ .endObject ()
188+ .endObject ()
189+ .endObject ()
190+ .endObject ();
191+ assertAcked (prepareCreate ("test" ).addMapping ("type" , mappings ));
192+
193+ client ().prepareIndex ("test" , "type" , "1" ).setSource ("text" , "foo" ).get ();
194+ refresh ();
195+
196+ for (String type : ALL_TYPES ) {
197+ HighlightBuilder builder = new HighlightBuilder ()
198+ .field (new Field ("alias" ).highlighterType (type ))
199+ .requireFieldMatch (randomBoolean ());
200+ SearchResponse search = client ().prepareSearch ()
201+ .setQuery (matchQuery ("alias" , "foo" ))
202+ .highlighter (builder )
203+ .get ();
204+ assertHighlight (search , 0 , "alias" , 0 , equalTo ("<em>foo</em>" ));
205+ }
206+ }
207+
208+ public void testFieldAliasWithSourceLookup () throws IOException {
209+ XContentBuilder mappings = jsonBuilder ()
210+ .startObject ()
211+ .startObject ("type" )
212+ .startObject ("properties" )
213+ .startObject ("text" )
214+ .field ("type" , "text" )
215+ .field ("analyzer" , "whitespace" )
216+ .field ("store" , false )
217+ .field ("term_vector" , "with_positions_offsets" )
218+ .endObject ()
219+ .startObject ("alias" )
220+ .field ("type" , "alias" )
221+ .field ("path" , "text" )
222+ .endObject ()
223+ .endObject ()
224+ .endObject ()
225+ .endObject ();
226+ assertAcked (prepareCreate ("test" ).addMapping ("type" , mappings ));
227+
228+ client ().prepareIndex ("test" , "type" , "1" ).setSource ("text" , "foo bar" ).get ();
229+ refresh ();
230+
231+ for (String type : ALL_TYPES ) {
232+ HighlightBuilder builder = new HighlightBuilder ()
233+ .field (new Field ("alias" ).highlighterType (type ))
234+ .requireFieldMatch (randomBoolean ());
235+ SearchResponse search = client ().prepareSearch ()
236+ .setQuery (matchQuery ("alias" , "bar" ))
237+ .highlighter (builder )
238+ .get ();
239+ assertHighlight (search , 0 , "alias" , 0 , equalTo ("foo <em>bar</em>" ));
240+ }
241+ }
242+
243+ public void testFieldAliasWithWildcardField () throws IOException {
244+ XContentBuilder mappings = jsonBuilder ()
245+ .startObject ()
246+ .startObject ("type" )
247+ .startObject ("properties" )
248+ .startObject ("keyword" )
249+ .field ("type" , "keyword" )
250+ .endObject ()
251+ .startObject ("alias" )
252+ .field ("type" , "alias" )
253+ .field ("path" , "keyword" )
254+ .endObject ()
255+ .endObject ()
256+ .endObject ()
257+ .endObject ();
258+ assertAcked (prepareCreate ("test" ).addMapping ("type" , mappings ));
259+
260+ client ().prepareIndex ("test" , "type" , "1" ).setSource ("keyword" , "foo" ).get ();
261+ refresh ();
262+
263+ HighlightBuilder builder = new HighlightBuilder ()
264+ .field (new Field ("al*" ))
265+ .requireFieldMatch (false );
266+ SearchResponse search = client ().prepareSearch ()
267+ .setQuery (matchQuery ("alias" , "foo" ))
268+ .highlighter (builder )
269+ .get ();
270+ assertHighlight (search , 0 , "alias" , 0 , equalTo ("<em>foo</em>" ));
271+ }
272+
273+
174274 public void testHighlightingWhenFieldsAreNotStoredThereIsNoSource () throws IOException {
175275 XContentBuilder mappings = jsonBuilder ();
176276 mappings .startObject ();
0 commit comments