Elasticsearch cannot query WKT


(Ash Chamari) #1

Elasticsearch cannot query KWT

I'm retrieving geometry data from MS sql server 2012 via jdbc connection and pushing it to elasticsearch. Data table consist of: objectid & shape.
In Kibana data looks like following.

  "objectid": 8,
     "untitled": "POLYGON ((16131003.104400001 -4962095.885400001, 16131161.300499998 -4962011.5243000016, 16130990.071999997 -4961961.9569999985, 16131003.104400001 -4962095.885400001))",

The "Shape" field here apperes as "untitled" and on the mapping it shows data type as text,

 "untitled": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }

I am quering the data from Kibana with following query and it prompts me the below error.

GET geo/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_polygon" : {
                    "untitled" : {
                        "polygon" : [
                        {"lat" : 16131003.104400001, "lon" : -4962095.885400001},
                        {"lat" : 16131161.300499998, "lon" : -4962011.5243000016},
                        {"lat" : 16130990.071999997, "lon" : -4961961.9569999985},
                        {"lat" : 16131003.104400001, "lon" : -4962095.885400001}
                        ]
                    }
                }
            }
        }
    }
}



 "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[geo_polygon] query does not support [polygon]",
        "line": 10,
        "col": 37
      }
    ],

Would be really appreciate if any one could help me out with this.

ps. I'm super new to elasticsearch and sorry for any stupid question :frowning:

Cheers


(David Pilato) #2

You need to change the mapping of your field untitled to be a geo shape. See https://www.elastic.co/guide/en/elasticsearch/reference/6.3/geo-shape.html

Then you should be able to use a geo shape query: https://www.elastic.co/guide/en/elasticsearch/reference/6.3/query-dsl-geo-shape-query.html


(Ash Chamari) #3

Thanks for your reply @dadoonet

It seems like elastic 6.3 support WKT.
Is there anyway I can mutate the type or convert the WKT to geo_shape?

How could I change the mapping? (I managed to change the field name untitled to shape)
I queried,

"filter" : {
"geo_shape" : {
"shape" : {
"points" : [
{"lat" : 16131003.104400001, "lon" : -4962095.885400001},
{"lat" : 16131161.300499998, "lon" : -4962011.5243000016},
{"lat" : 16130990.071999997, "lon" : -4961961.9569999985},
{"lat" : 16131003.104400001, "lon" : -4962095.885400001}
]
}
}
}

and it still complains,,

"type": "parsing_exception",
"reason": "[geo_shape] query does not support [points]",


(David Pilato) #4

The documentation shows how to query this:

GET /example/_search
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "envelope",
                            "coordinates" : [[13.0, 53.0], [14.0, 52.0]]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}

(system) #5

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