use of org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilder in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesInSourceFieldsAndSourceFilters.
// #1778
@Test
@DisplayName("should map names in source fields and SourceFilters")
void shouldMapNamesInSourceFieldsAndSourceFilters() {
Query query = Query.findAll();
// Note: we don't care if these filters make sense here, this test is only about name mapping
query.addFields("firstName", "lastName");
query.addSourceFilter(new FetchSourceFilterBuilder().withIncludes("firstName").withExcludes("lastName").build());
mappingElasticsearchConverter.updateQuery(query, Person.class);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(query.getFields()).containsExactly("first-name", "last-name");
SourceFilter sourceFilter = query.getSourceFilter();
softly.assertThat(sourceFilter).isNotNull();
softly.assertThat(sourceFilter.getIncludes()).containsExactly("first-name");
softly.assertThat(sourceFilter.getExcludes()).containsExactly("last-name");
softly.assertAll();
}
use of org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilder in project spring-data-elasticsearch by spring-projects.
the class SourceFilterIntegrationTests method shouldOnlyReturnRequestedFieldsOnGMultiGet.
// #1659, #1678
@Test
@DisplayName("should only return requested fields on multiget")
void shouldOnlyReturnRequestedFieldsOnGMultiGet() {
// multiget has no fields, need sourcefilter here
Query query = Query.multiGetQuery(Collections.singleton("42"));
//
query.addSourceFilter(new FetchSourceFilterBuilder().withIncludes("field2").build());
List<MultiGetItem<Entity>> entities = operations.multiGet(query, Entity.class);
assertThat(entities).hasSize(1);
Entity entity = entities.get(0).getItem();
assertThat(entity.getField1()).isNull();
assertThat(entity.getField2()).isEqualTo("two");
assertThat(entity.getField3()).isNull();
}
Aggregations