Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created November 27, 2012 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadoonet/4154982 to your computer and use it in GitHub Desktop.
Save dadoonet/4154982 to your computer and use it in GitHub Desktop.
Test case for must clause
/**
* @throws Exception
*/
@Test
public void createSuggest() throws Exception {
node.client().prepareIndex("es1index", "type1").setSource("{\"email\" : \"abc@otherdomain.com\", \"firstname\" : \"abc\"}").execute().actionGet();
node.client().prepareIndex("es1index", "type1").setSource("{\"email\" : \"abc@gmail.com\", \"firstname\" : \"abc\"}").execute().actionGet();
node.client().prepareIndex("es1index", "type1").setSource("{\"email\" : \"xyz@gmail.com\", \"firstname\" : \"xyz\"}").execute().actionGet();
node.client().admin().indices().prepareRefresh().execute().actionGet();
QueryBuilder qb = QueryBuilders
.boolQuery()
.must(QueryBuilders.wildcardQuery("email", "*gmail.com*"))
.must(QueryBuilders.termQuery("firstname","abc"));
logger.info("Your query is : {}", qb);
SearchResponse sr = node.client().prepareSearch().setQuery(qb)
.execute().actionGet();
logger.info("Result is {}", sr.toString());
Assert.assertNotNull(sr);
Assert.assertNotNull(sr.getHits());
Assert.assertEquals(1, sr.getHits().getTotalHits());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment