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_polygon does not return any result #35741

Closed
leobispo opened this issue Nov 20, 2018 · 5 comments
Closed

geo_polygon does not return any result #35741

leobispo opened this issue Nov 20, 2018 · 5 comments
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes feedback_needed

Comments

@leobispo
Copy link

Describe the feature:

Bug on geo_polygon/geo_boundingbox filter

Elasticsearch version (bin/elasticsearch --version):

5.1.2

JVM version (java -version):

1.8

OS version (uname -a if on a Unix-like system):

Linux app 4.15.0-1021-gcp #22~16.04.1-Ubuntu SMP Wed Sep 26 06:08:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:

Should return a document with geo_point, but getting no points

Steps to reproduce:

Mapping

  "geo_country" : {
    "properties" : {
      "bottom_right_location" : {
        "type" : "geo_point"
      },
      "location" : {
        "type" : "geo_point"
      },
      "name" : {
        "type" : "text"
      },
      "top_left_location" : {
        "type" : "geo_point"
      }
    }
  }

Document:

      {
        "_index" : "wespline",
        "_type" : "geo_country",
        "_id" : "US",
        "_score" : 1.0,
        "_source" : {
          "name" : "United States of America",
          "location" : [
            38.89037,
            -77.03196
          ]
        }
      }

Query:

curl -XGET 'http://search.wespline.com:9200/wespline/geo_country/_search?pretty' -d '
{
 "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_polygon": {
            "location" : {
                "points": [
                    {"lat": -77, "lon": -39},
                    {"lat": -77, "lon": -38},
                    {"lat": -78, "lon": -38},
                    {"lat": -78, "lon": -39}
                ]
            }
        }
      }
    }   
  }
}
'

Result:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
@polyfractal
Copy link
Contributor

I think the issue is the longitude's in your query are negative, when they should be positive to match the longitudes in the document. E.g. this works for me:

GET /wespline/geo_country/_search?pretty
{
 "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_polygon": {
            "location" : {
                "points": [
                    {"lat": -77, "lon": 39},
                    {"lat": -77, "lon": 38},
                    {"lat": -78, "lon": 38},
                    {"lat": -78, "lon": 39}
                ]
            }
        }
      }
    }   
  }
}

@polyfractal polyfractal added feedback_needed :Analytics/Geo Indexing, search aggregations of geo points and shapes labels Nov 20, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@leobispo
Copy link
Author

leobispo commented Nov 20, 2018

Sorry My bad, this example is wrong. An example where this is happening:

Document:

      {
        "_index" : "wespline",
        "_type" : "geo_country",
        "_id" : "BR",
        "_score" : 1.0,
        "_source" : {
          "name" : "Brazil",
          "location" : [
            -15.77843,
            -47.92866
          ]
        }
      },

Search:

curl -XGET 'http://search.wespline.com:9200/wespline/geo_country/_search?pretty' -d '
{
    "query": {
        "bool": {
            "filter": [
                {
                    "geo_polygon": {
                        "location": {
                            "points": [
                                {
                                    "lon": -123.75,
                                    "lat": 13.923403897723347
                                },
                                {
                                    "lon": -1.93359375,
                                    "lat": 13.923403897723347
                                },
                                {
                                    "lon": -1.93359375,
                                    "lat": -35.74651225991851
                                },
                                {
                                    "lon": -123.75,
                                    "lat": -35.74651225991851
                                }
                            ]
                        }
                    }
                }
            ],
            "must": [
                {
                    "match_all": {}
                }
            ]
        }
    }
}
'

Result:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

@imotov
Copy link
Contributor

imotov commented Nov 20, 2018

@leobispo I don't really see anything wrong with your example. The southmost point of the polygon in your example has latitude of -35.74651225991851, while your point is south of it with latitude of -47.92866

The geo_point type can be sometimes confusing. For example, when a geo_point is represented as an array, it has [lon, lat] format, but when it is represented as a string it had "lat,lon" format. I think it might help if you represent your points using {"lat": ..., "lon": ...} notation.

@leobispo
Copy link
Author

@imotov

Ok, I figured out my mistake... It was in the insertion... I was doing [lat,lon] for inserting... instead of [lon,lat].

I will close the Issue! Tnx a lot

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 feedback_needed
Projects
None yet
Development

No branches or pull requests

4 participants