Skip to content

Commit

Permalink
HSEARCH-3496 Test projection to the JSON hit in the Elasticsearch bac…
Browse files Browse the repository at this point in the history
…kend
  • Loading branch information
yrodiere committed Nov 14, 2019
1 parent 69d5072 commit 9c8a8a5
Showing 1 changed file with 22 additions and 0 deletions.
Expand Up @@ -66,6 +66,7 @@
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.json.JSONException;
import org.skyscreamer.jsonassert.JSONCompareMode;

public class ElasticsearchExtensionIT {

Expand Down Expand Up @@ -855,6 +856,27 @@ public void projection_explanation() {
.contains( "\"details\":" );
}

@Test
public void projection_jsonHit() {
StubMappingScope scope = indexManager.createScope();

SearchQuery<JsonObject> query = scope.query()
.asProjection( f -> f.extension( ElasticsearchExtension.get() ).jsonHit() )
.predicate( f -> f.id().matching( FIRST_ID ) )
.toQuery();

List<JsonObject> result = query.fetchAll().getHits();
Assertions.assertThat( result ).hasSize( 1 );
assertJsonEquals(
"{"
+ "'_id': '" + FIRST_ID + "',"
+ "'_index': '" + ElasticsearchIndexNameNormalizer.normalize( INDEX_NAME ) + "'"
+ "}",
result.get( 0 ).toString(),
JSONCompareMode.LENIENT
);
}

@Test
public void aggregation_nativeField() {
StubMappingScope scope = indexManager.createScope();
Expand Down

0 comments on commit 9c8a8a5

Please sign in to comment.