# Search template can not parser data in geoshape search

**URL:** <https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446>\
**Category:** Elasticsearch\
**Created:** [May 11, 2022, 9:58am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446 "2022-05-11T09:58:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)\
**Post date:** [May 11, 2022, 9:58am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/1 "2022-05-11T09:58:37Z")

</div>

Hi everyone.

I just set a search template like:

> POST \_scripts/geoshape\_search  
> {  
> "script": {  
> "lang": "mustache",  
> "source": {  
> "query": {  
> "geo\_shape": {  
> "geo\_json": {  
> "shape": {  
> "type": "point",  
> "coordinates": [  
> "{{longitude}}",  
> "{{latitude}}"  
> ]  
> },  
> "relation": "intersects"  
> }  
> }  
> }  
> }  
> }  
> }

But when I use template like:

> GET \_search/template  
> {  
> "id": "geoshape\_search",  
> "params": {  
> "longitude": -121.77777,  
> "latitude": 37.33333  
> }  
> }

It fails:

> {  
> "error": {  
> "root\_cause": [  
> {  
> "type": "parse\_exception",  
> "reason": "geo coordinates must be numbers"  
> }  
> ],  
> "type": "parse\_exception",  
> "reason": "geo coordinates must be numbers"  
> },  
> "status": 400  
> }

Any suggestion would be helpful!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 11, 2022, 1:43pm UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/2 "2022-05-11T13:43:17Z")

</div>

Not nice, but may help you:

```auto
POST _render/template
{
  "source": "{ \"coordinates\": [{{longitude}}, {{latitude}}]}",
  "params": {
    "longitude": 1,
    "latitude":2
  }
}

```

---

<div class="post-metadata">

**Author:** ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)\
**Post date:** [May 12, 2022, 1:41am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/3 "2022-05-12T01:41:24Z")

</div>

it doesnt works ☹

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [May 12, 2022, 1:50am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/4 "2022-05-12T01:50:21Z")

</div>

Ok I will take a swing

How about without the `"` around the lat / lon

```auto
"coordinates": [
{{longitude}},
{{latitude}}

```

NOPE that does not work ☹

RE-EDITING... Strange Results

---

<div class="post-metadata">

**Author:** ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)\
**Post date:** [May 12, 2022, 8:14am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/5 "2022-05-12T08:14:12Z")

</div>

yeah, I removed the " too.  
☹

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 12, 2022, 9:00am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/6 "2022-05-12T09:00:15Z")

</div>

can you share what you tried instead of writing 'does not work'? thanks

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [May 12, 2022, 11:30am UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/7 "2022-05-12T11:30:16Z")

</div>

Have you tried to define your shape using WKT?

```auto
POST _scripts/geoshape_search
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "geo_shape": {
          "geo_json" : {
            "shape": "POINT({{longitude}} {{latitude}})",
            "relation": "intersects"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [May 12, 2022, 2:42pm UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/8 "2022-05-12T14:42:51Z")

</div>

> [@Ignacio\_Vera](#):
>
> ```auto
> POST _scripts/geoshape_search
> {
> "script": {
> "lang": "mustache",
> "source": {
> "query": {
> "geo_shape": {
> "geo_json" : {
> "shape": "POINT({{longitude}} {{latitude}})",
> "relation": "intersects"
> }
> }
> }
> }
> }
> }
> 
> ```

```auto
GET _render/template
{
  "id": "geoshape_search",
  "params": {
    "longitude": -121.77777,
    "latitude": 37.33333
  }
}

{
  "template_output" : {
    "query" : {
      "geo_shape" : {
        "geo_json" : {
          "shape" : "POINT(-121.77777 37.33333)",
          "relation" : "intersects"
        }
      }
    }
  }
}

```

That seems to work I tried with `{{#toJson}}` and could not get it to work...

---

<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:** [June 9, 2022, 2:42pm UTC](https://discuss.elastic.co/t/search-template-can-not-parser-data-in-geoshape-search/304446/9 "2022-06-09T14:42:56Z")

</div>

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