Search in sources :

Example 1 with ElasticsearchAssertions.assertSearchResponse

use of org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse in project elasticsearch by elastic.

the class MoreExpressionTests method testSparseField.

public void testSparseField() throws Exception {
    ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "x", "type=long", "y", "type=long"));
    ensureGreen("test");
    indexRandom(true, client().prepareIndex("test", "doc", "1").setSource("x", 4), client().prepareIndex("test", "doc", "2").setSource("y", 2));
    SearchResponse rsp = buildRequest("doc['x'] + 1").get();
    ElasticsearchAssertions.assertSearchResponse(rsp);
    SearchHits hits = rsp.getHits();
    assertEquals(2, rsp.getHits().getTotalHits());
    assertEquals(5.0, hits.getAt(0).field("foo").getValue(), 0.0D);
    assertEquals(1.0, hits.getAt(1).field("foo").getValue(), 0.0D);
}
Also used : SearchHits(org.elasticsearch.search.SearchHits) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchHits (org.elasticsearch.search.SearchHits)1 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)1