Search in sources :

Example 1 with OpenSearchAssertions.assertSearchResponse

use of org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse in project OpenSearch by opensearch-project.

the class MoreExpressionIT method testSparseField.

public void testSparseField() throws Exception {
    OpenSearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "x", "type=long", "y", "type=long"));
    ensureGreen("test");
    indexRandom(true, client().prepareIndex("test").setId("1").setSource("id", 1, "x", 4), client().prepareIndex("test").setId("2").setSource("id", 2, "y", 2));
    SearchResponse rsp = buildRequest("doc['x'] + 1").get();
    OpenSearchAssertions.assertSearchResponse(rsp);
    SearchHits hits = rsp.getHits();
    assertEquals(2, rsp.getHits().getTotalHits().value);
    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.opensearch.search.SearchHits) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

SearchResponse (org.opensearch.action.search.SearchResponse)1 SearchHits (org.opensearch.search.SearchHits)1 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)1