# Elasticsearch cannot query WKT

**URL:** https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442
**Category:** Elasticsearch
**Created:** [July 18, 2018, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442 "2018-07-18T05:24:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ash\_Chamari](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Ash\_Chamari](https://discuss.elastic.co/u/Ash_Chamari)
#### Post date: [July 18, 2018, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442/1 "2018-07-18T05:24:38Z")

</div>

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 ☹

Cheers

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 18, 2018, 6:22am UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442/2 "2018-07-18T06:22:35Z")

</div>

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](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](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/query-dsl-geo-shape-query.html)

---

<div class="post-metadata">

### Author: ![Ash\_Chamari](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Ash\_Chamari](https://discuss.elastic.co/u/Ash_Chamari)
#### Post date: [July 18, 2018, 11:02pm UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442/3 "2018-07-18T23:02:19Z")

</div>

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]",

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 19, 2018, 7:15am UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442/4 "2018-07-19T07:15:01Z")

</div>

The documentation shows how to query this:

```auto
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"
                    }
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 16, 2018, 7:25am UTC](https://discuss.elastic.co/t/elasticsearch-cannot-query-wkt/140442/5 "2018-08-16T07:25:11Z")

</div>

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