From 42b9674d0c1cc91bffb664da5f1adac5994a47ed Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Apr 2013 13:53:49 +0200 Subject: [PATCH] added simple test for numeric match query --- .../search/query/SimpleQueryTests.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java index 7c742bf7c1d..e9bc9518da9 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/query/SimpleQueryTests.java @@ -46,6 +46,7 @@ import static org.elasticsearch.index.query.FilterBuilders.*; import static org.elasticsearch.index.query.QueryBuilders.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.equalTo; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -505,6 +506,35 @@ public class SimpleQueryTests extends AbstractNodesTests { assertThat("Failures " + Arrays.toString(searchResponse.getShardFailures()), searchResponse.getShardFailures().length, equalTo(0)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); } + + @Test + public void testMatchQueryNumeric() throws Exception { + try { + client.admin().indices().prepareDelete("test").execute().actionGet(); + } catch (Exception e) { + // ignore + } + + client.admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); + + client.prepareIndex("test", "type1", "1").setSource("long", 1l, "double", 1.0d).execute().actionGet(); + client.prepareIndex("test", "type1", "2").setSource("long", 2l, "double", 2.0d).execute().actionGet(); + client.prepareIndex("test", "type1", "3").setSource("long", 3l, "double", 3.0d).execute().actionGet(); + client.admin().indices().prepareRefresh("test").execute().actionGet(); + SearchResponse searchResponse = client.prepareSearch().setQuery(matchQuery("long", "1")).execute().actionGet(); + assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); + assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1")); + + searchResponse = client.prepareSearch().setQuery(matchQuery("double", "2")).execute().actionGet(); + assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); + assertThat(searchResponse.getHits().getAt(0).id(), equalTo("2")); + try { + searchResponse = client.prepareSearch().setQuery(matchQuery("double", "2 3 4")).execute().actionGet(); + assert false; + } catch (SearchPhaseExecutionException ex) { + // number format exception + } + } @Test public void testMultiMatchQuery() throws Exception {