I am trying to execute a query for a geo_point
value with a runtime mapping, which according to the docs should work, but it is failing. keywords
and long
values work fine. For example...
Where src.city.name
is a keyword
...
"city": {
"type": "object",
"properties": {
"name": {
"type": "keyword"
}
}
},
the following works...
{
"runtime_mappings": {
"city.name": {
"type": "keyword",
"script": {
"source": "if (doc.containsKey('src.city.name') && !doc['src.city.name'].empty) {emit(doc['src.city.name'].value)}"
}
}
},
"fields": [
"city.name"
],
"size": 1,
"query": {
"match": {
"server.ipaddr": "192.0.2.11"
}
}
}
Result...
"fields": {
"city.name": [
"Macroom"
]
}
However, using the same method for a geo_point
fails.
Where src.loc.coord
is a geo_point
...
"loc": {
"type": "object",
"properties": {
"coord": {
"type": "geo_point"
}
}
},
the following query fails...
{
"runtime_mappings": {
"loc.coord": {
"type": "geo_point",
"script": {
"source": "if (doc.containsKey('src.loc.coord') && !doc['src.loc.coord'].empty) {emit(doc['src.loc.coord'].value)}"
}
}
},
"fields": [
"loc.coord"
],
"size": 1,
"query": {
"match": {
"server.ipaddr": "192.0.2.11"
}
}
}
The error given is...
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... src.loc.coord'].empty) {emit(doc['src.loc.coord ...",
" ^---- HERE"
],
"script": "if (doc.containsKey('src.loc.coord') && !doc['src.loc.coord'].empty) {emit(doc['src.loc.coord'].value)}",
"lang": "painless",
"position": {
"offset": 88,
"start": 63,
"end": 113
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test_index-2021.w17",
"node": "mDbh3hqhPRi8x0WMRhf-fB",
"reason": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... src.loc.coord'].empty) {emit(doc['src.loc.coord ...",
" ^---- HERE"
],
"script": "if (doc.containsKey('src.loc.coord') && !doc['src.loc.coord'].empty) {emit(doc['src.loc.coord'].value)}",
"lang": "painless",
"position": {
"offset": 88,
"start": 63,
"end": 113
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unknown call [emit] with [[org.elasticsearch.painless.node.EDot@356bd657]] arguments."
}
}
}
]
},
"status": 400
}
How must this query be modified to work with geo_point
fields?