Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEO: intersects search for geo_shape return wrong result #49017

Closed
happyjoblzp opened this issue Nov 13, 2019 · 6 comments
Closed

GEO: intersects search for geo_shape return wrong result #49017

happyjoblzp opened this issue Nov 13, 2019 · 6 comments
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v7.6.0 v8.0.0-alpha1

Comments

@happyjoblzp
Copy link

Linestring intersect with polygon return wrong results!

Bug reappear method:

1、Create index use restful API like this, add insert two data:

curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/example' -d '
{
   "mappings": {
       "properties": {
           "location": {
               "type": "geo_shape"
           }
       }
   }
}
'

curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/example/_doc?refresh' -d '
{
    "name": "mytest1",
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ [5, 5], [10, 6], [10, 10], [5, 10], [5, 5] ]
        ]
    }
}
'

curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/example/_doc?refresh' -d '
{
    "name": "qingdao",
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ [6, 6], [9, 6], [9, 9], [6, 9], [6, 6] ]
        ]
    }
}
'

2、Use intersects to search, It returns only one piece of data(In fact, both data meet the spatial intersect with the linestring)

curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/example/_search' -d '
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "linestring",
                            "coordinates" : [ [0, 0], [5, 5], [7, 7] ]
                        },
                        "relation": "intersects"
                    }
                }
            }
        }
    }
}
'

{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"example","_id":"4zx-Y24BTFMtLEcLyvV6","_score":1.0,"_source":
{
    "name": "mytest1",
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ [5, 5], [10, 6], [10, 10], [5, 10], [5, 5] ]
        ]
    }
}
}]}}

I don't know why miss polygon [ [6, 6], [9, 6], [9, 9], [6, 9], [6, 6] ]?

@happyjoblzp happyjoblzp changed the title GEO: intersects search for geo_shape return error result GEO: intersects search for geo_shape return wrong result Nov 13, 2019
@iverase iverase added the :Analytics/Geo Indexing, search aggregations of geo points and shapes label Nov 13, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Geo)

@iverase iverase added the >bug label Nov 13, 2019
@happyjoblzp
Copy link
Author

If use linestring [ [0, 0], [5, 5], [7, 7.000001] ], not use [ [0, 0], [5, 5], [7, 7] ], it can return right results.

curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/example/_search' -d '
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "linestring",
                            "coordinates" : [ [0, 0], [5, 5], [7, 7.000001] ]
                        },
                        "relation": "intersects"
                    }
                }
            }
        }
    }
}
'
{"took":5,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"example","_id":"4zx-Y24BTFMtLEcLyvV6","_score":1.0,"_source":
{
    "name": "mytest1",
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ [5, 5], [10, 6], [10, 10], [5, 10], [5, 5] ]
        ]
    }
}
},{"_index":"example","_id":"5DyBY24BTFMtLEcL7fWC","_score":1.0,"_source":
{
    "name": "qingdao",
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ [6, 6], [9, 6], [9, 9], [6, 9], [6, 6] ]
        ]
    }
}
}]}}

@iverase
Copy link
Contributor

iverase commented Nov 13, 2019

Thanks @happyjoblzp,

I had a look into this and it seems a real bug in the Lucene implementation. Basically the line is not detecting the intersection of the polygon because it must goes through the intersection between two edge polygons.

I will open a Lucene issue soon and post the link here.

@happyjoblzp
Copy link
Author

@iverase thanks,
In the traffic research , linestring intersects with polygons may be common scenarios.
I have seen the relevant discuss of #40085 , and expect a good solution

@iverase
Copy link
Contributor

iverase commented Nov 20, 2019

@iverase
Copy link
Contributor

iverase commented Jan 16, 2020

Lucene 8.4 contains the fix for this issue so the issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v7.6.0 v8.0.0-alpha1
Projects
None yet
Development

No branches or pull requests

4 participants