Search in sources :

Example 21 with SearchQuery

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());
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) JsonObject(com.google.gson.JsonObject) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 22 with SearchQuery

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);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) JsonObject(com.google.gson.JsonObject) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with SearchQuery

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);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 24 with SearchQuery

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);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) JsonPrimitive(com.google.gson.JsonPrimitive) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 25 with SearchQuery

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);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) JsonObject(com.google.gson.JsonObject) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Aggregations

SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)229 Test (org.junit.Test)222 Rule (org.junit.Rule)197 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)186 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)185 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)185 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)179 Before (org.junit.Before)177 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)164 List (java.util.List)158 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)153 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)151 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)135 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)129 Projectable (org.hibernate.search.engine.backend.types.Projectable)127 SearchException (org.hibernate.search.util.common.SearchException)119 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)113 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)110 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)102 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)102