Geo Polygon Query retuns nothing

1. Сreat new using the following request:

PUT /test?pretty
{
    "mappings": {
        "tst": {
        "properties": {
            "nm":{
                "type":"text"
                },
            "loc": {
                "type": "geo_point"
                }
            }  
        }
    }
}

2. Geting index Information using get /test . The result is:

{
  "test" : {
    "aliases" : { },
    "mappings" : {
      "tst" : {
        "properties" : {
          "loc" : {
            "type" : "geo_point"
          },
          "nm" : {
            "type" : "text"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1554110780623",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "M8_x6t7iSKa0Xpm_lDbAcQ",
        "version" : {
          "created" : "6070099"
        },
        "provided_name" : "test"
      }
    }
  }
}

3. Adding new document using then following request:

post /test/tst
{
  "nm":"Test1",
  "loc":"37,55"
}

4. And now I perform a query using a polygon that exactly contains the point 37,55:

GET /test/tst/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_polygon" : {
                    "loc" : {
                        "points" : [[36,54],
                                    [36,56],
                                    [38,56],
                                    [38,54],
                                    [36,54]]
                    }
                }
            }
        }
    }
}

The result is:

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

What am i doing wrong?

As you can see in the geo_point documentation:

https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html#geo-point

There is a warning about the points expressed as arrays or string. The order is defined by [lat, lon].

On the other hand, in the geo_polygon query, the polygon is expressed as [lon, lat].

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html#_lat_long_as_array

You need to order your data and query following those conventions.

sorry, did not pay attention to the comments, thanks for the tip

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.