Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 20:30
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 anonymous/4348293 to your computer and use it in GitHub Desktop.
Save anonymous/4348293 to your computer and use it in GitHub Desktop.
@Test
public void thisShouldWork() throws Exception {
Node node = NodeBuilder.nodeBuilder().local(true).node();
client = node.client();
// delete the index
try {
client.admin().indices().delete(new DeleteIndexRequest("test-index")).actionGet();
} catch (Exception e) {
}
String works = "{ \"stringValue\" : \"World Demo\", \"_id\" : { \"$oid\" : \"12345\"} }";
String doesntWork = "{ \"_id\" : { \"$oid\" : \"12345\"}, \"stringValue\" : \"World Demo\"}";
client.prepareIndex("test-index", "test-type", "12345").setSource(works).execute().actionGet();
client.admin().indices().flush(new FlushRequest("test-index").refresh(true)).actionGet();
SearchResponse response = client.prepareSearch("test-index").setSearchType(SearchType.DFS_QUERY_AND_FETCH).execute().actionGet();
assertEquals(1, response.getHits().getTotalHits());
response = client.prepareSearch("test-index").setSearchType(SearchType.DFS_QUERY_AND_FETCH).setQuery(termQuery("stringValue", "world")).execute().actionGet();
assertEquals(1, response.getHits().getTotalHits());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment