Search template can not parser data in geoshape search

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!

Not nice, but may help you:

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

it doesnt works :frowning:

Ok I will take a swing

How about without the " around the lat / lon

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

NOPE that does not work :frowning:

RE-EDITING... Strange Results

yeah, I removed the " too.
:frowning:

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

Have you tried to define your shape using WKT?

POST _scripts/geoshape_search
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "geo_shape": {
          "geo_json" : {
            "shape": "POINT({{longitude}} {{latitude}})",
            "relation": "intersects"
          }
        }
      }
    }
  }
}
1 Like
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...