use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method aggregation_nativeField_fromJson_string.
@Test
public void aggregation_nativeField_fromJson_string() {
StubMappingScope scope = mainIndex.createScope();
AggregationKey<JsonObject> documentCountPerValue = AggregationKey.of("documentCountPerValue");
SearchQuery<DocumentReference> query = scope.query().extension(ElasticsearchExtension.get()).where(f -> f.matchAll()).aggregation(documentCountPerValue, f -> f.fromJson("{" + "'value_count' : {" + "'field' : 'nativeField_aggregation'" + " }" + "}")).toQuery();
JsonObject aggregationResult = query.fetchAll().aggregation(documentCountPerValue);
assertJsonEquals("{" + "'value': 3" + "}", aggregationResult.toString());
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method projection_documentAndField.
/**
* Check that the projection on source includes all fields,
* even if there is a field projection, which would usually trigger source filtering.
*/
@Test
public void projection_documentAndField() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<List<?>> query = scope.query().select(f -> f.composite(f.extension(ElasticsearchExtension.get()).source(), f.field("nativeField_string"))).where(f -> f.id().matching(FIFTH_ID)).toQuery();
List<JsonObject> result = query.fetchAll().hits().stream().map(list -> (JsonObject) list.get(0)).collect(Collectors.toList());
assertThat(result).hasSize(1);
assertJsonEquals("{" + "'string': 'text 5'," + "'nativeField_string': 'text 2'," + "'nativeField_integer': 1," + "'nativeField_geoPoint': {'lat': 45.12, 'lon': -75.34}," + "'nativeField_dateWithColons': '2018:01:25'," + "'nativeField_unsupportedType': 'foobar'," + "'nativeField_sort5': 'z'" + "}", result.get(0).toString(), JSONCompareMode.LENIENT);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method sort_filter_fromJson.
@Test
public void sort_filter_fromJson() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().extension(ElasticsearchExtension.get()).where(f -> f.matchAll()).sort(f -> f.field(mainIndex.binding().nestedObject.relativeFieldName + ".sort1").filter(pf -> pf.fromJson("{'match': {'" + mainIndex.binding().nestedObject.relativeFieldName + ".discriminator" + "': 'included'}}"))).toQuery();
assertThatQuery(query).hasDocRefHitsExactOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID, FOURTH_ID, FIFTH_ID, EMPTY_ID);
// Check descending order, just in case the above order was reached by chance.
query = scope.query().extension(ElasticsearchExtension.get()).where(f -> f.matchAll()).sort(f -> f.field(mainIndex.binding().nestedObject.relativeFieldName + ".sort1").desc().filter(pf -> pf.fromJson("{'match': {'" + mainIndex.binding().nestedObject.relativeFieldName + ".discriminator" + "': 'included'}}"))).toQuery();
assertThatQuery(query).hasDocRefHitsExactOrder(mainIndex.typeName(), FIFTH_ID, FOURTH_ID, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method predicate_nativeField.
@Test
public void predicate_nativeField() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field("nativeField_dateWithColons").matching(new JsonPrimitive("2018:01:12"))).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), FOURTH_ID).hasTotalHitCount(1);
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class ElasticsearchExtensionIT method predicate_nativeField_fromJson_jsonObject.
@Test
public void predicate_nativeField_fromJson_jsonObject() {
StubMappingScope scope = mainIndex.createScope();
SearchQuery<DocumentReference> query = scope.query().where(f -> f.bool().should(f.extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'match': {'nativeField_string': 'text 1'}}", JsonObject.class))).should(f.extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{'match': {'nativeField_integer': 2}}", JsonObject.class))).should(f.extension(ElasticsearchExtension.get()).fromJson(gson.fromJson("{" + "'geo_distance': {" + "'distance': '200km'," + "'nativeField_geoPoint': {" + "'lat': 40," + "'lon': -70" + "}" + "}" + "}", JsonObject.class)))).toQuery();
assertThatQuery(query).hasDocRefHitsAnyOrder(mainIndex.typeName(), FIRST_ID, SECOND_ID, THIRD_ID).hasTotalHitCount(3);
}
Aggregations