@@ -28,21 +28,11 @@ public class VersionStringFieldMapperTests extends ESSingleNodeTestCase {
2828
2929 @ Override
3030 protected Collection <Class <? extends Plugin >> getPlugins () {
31- // return pluginList(VersionFieldPlugin.class, LocalStateCompositeXPackPlugin.class, PainlessPlugin.class);
32- // TODO PainlessPlugin loading doesn't work when test is run through "gradle check"
3331 return pluginList (VersionFieldPlugin .class , LocalStateCompositeXPackPlugin .class );
3432 }
3533
3634 public String setUpIndex (String indexName ) throws IOException {
37- createIndex (
38- indexName ,
39- Settings .builder ().put ("index.number_of_shards" , 1 ).build (),
40- "_doc" ,
41- "version" ,
42- "type=version" ,
43- "foo" ,
44- "type=keyword"
45- );
35+ createIndex (indexName , Settings .builder ().put ("index.number_of_shards" , 1 ).build (), "_doc" , "version" , "type=version" );
4636 ensureGreen (indexName );
4737
4838 client ().prepareIndex (indexName ).setId ("1" ).setSource (jsonBuilder ().startObject ().field ("version" , "11.1.0" ).endObject ()).get ();
@@ -186,6 +176,44 @@ public void testSort() throws IOException {
186176 assertEquals ("21.11.0" , hits [5 ].getSortValues ()[0 ]);
187177 }
188178
179+ public void testRegexQuery () throws Exception {
180+ String indexName = "test_regex" ;
181+ createIndex (indexName , Settings .builder ().put ("index.number_of_shards" , 1 ).build (), "_doc" , "version" , "type=version" );
182+ ensureGreen (indexName );
183+
184+ client ().prepareIndex (indexName )
185+ .setId ("1" )
186+ .setSource (jsonBuilder ().startObject ().field ("version" , "1.0.0-alpha.2.1.0-rc.1" ).endObject ())
187+ .get ();
188+ client ().prepareIndex (indexName )
189+ .setId ("2" )
190+ .setSource (jsonBuilder ().startObject ().field ("version" , "1.3.0+build.1234567" ).endObject ())
191+ .get ();
192+ client ().prepareIndex (indexName )
193+ .setId ("3" )
194+ .setSource (jsonBuilder ().startObject ().field ("version" , "2.1.0-alpha.beta" ).endObject ())
195+ .get ();
196+ client ().prepareIndex (indexName ).setId ("4" ).setSource (jsonBuilder ().startObject ().field ("version" , "2.1.0" ).endObject ()).get ();
197+ client ().prepareIndex (indexName ).setId ("5" ).setSource (jsonBuilder ().startObject ().field ("version" , "2.33.0" ).endObject ()).get ();
198+ client ().admin ().indices ().prepareRefresh (indexName ).get ();
199+
200+ // regex
201+ SearchResponse response = client ().prepareSearch (indexName ).setQuery (QueryBuilders .regexpQuery ("version" , "2.*0" )).get ();
202+ assertEquals (2 , response .getHits ().getTotalHits ().value );
203+ assertEquals ("2.1.0" , response .getHits ().getHits ()[0 ].getSourceAsMap ().get ("version" ));
204+ assertEquals ("2.33.0" , response .getHits ().getHits ()[1 ].getSourceAsMap ().get ("version" ));
205+
206+ response = client ().prepareSearch (indexName ).setQuery (QueryBuilders .regexpQuery ("version" , "<0-10>.<0-10>.*al.*" )).get ();
207+ assertEquals (2 , response .getHits ().getTotalHits ().value );
208+ assertEquals ("1.0.0-alpha.2.1.0-rc.1" , response .getHits ().getHits ()[0 ].getSourceAsMap ().get ("version" ));
209+ assertEquals ("2.1.0-alpha.beta" , response .getHits ().getHits ()[1 ].getSourceAsMap ().get ("version" ));
210+
211+ response = client ().prepareSearch (indexName ).setQuery (QueryBuilders .regexpQuery ("version" , "1.[0-9].[0-9].*" )).get ();
212+ assertEquals (2 , response .getHits ().getTotalHits ().value );
213+ assertEquals ("1.0.0-alpha.2.1.0-rc.1" , response .getHits ().getHits ()[0 ].getSourceAsMap ().get ("version" ));
214+ assertEquals ("1.3.0+build.1234567" , response .getHits ().getHits ()[1 ].getSourceAsMap ().get ("version" ));
215+ }
216+
189217 public void testWildcardQuery () throws Exception {
190218 String indexName = "test_wildcard" ;
191219 createIndex (
0 commit comments