Skip to content

Mixing NativeQuery with CriteriaQuery and a Criteria with GeoLocation fails #2840

Closed
@bernhardkern

Description

@bernhardkern

Mixing a NativeQuery and a CriteriaQuery fails, when using Criteria with geoLocation.

Version: Spring Data ElasticSearch 5.2.2
Spring Boot Version: 3.2.2
ElasticSearch Version: 8.12.0

Github, Service demonstrating the issue

Github, Test demonstrating the issue

 val nativeGeoDistance = GeoDistanceQuery.Builder().field("location").distance("10km")            
 .location(GeoLocation.Builder().latlon(LatLonGeoLocation.Builder().lat(pointWeAreLookingFor.lat).lon(pointWeAreLookingFor.lon).build()).build()).build()
        val nq = NativeQueryBuilder().withQuery { q -> q.geoDistance(nativeGeoDistance) }.build()

        return operations.search(nq, WithGeoLocation::class.java)

delivers the expected result -> only one document is found

val cq = CriteriaQuery(Criteria("location").within(pointWeAreLookingFor, "10km"))
        val nq = NativeQueryBuilder().withQuery(cq).build()

        return operations.search(nq, WithGeoLocation::class.java)

fails, both documents are found. It also fails with bounding box queries. Everything that is geo-related.

If I run the critieriaQuery directly, without nesting it in NativeQuery, it works. Sometimes this nesting is necessary, e.g. when using Aggregations, but in general we write the Queries in CriteriaQuery.

Issue: Using a CriteriaQuery as base for the NativeQueryBuilder fails when using a geo based query. Other critiera work (e.g. Term).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions