Hello ,
I'm facing an issue with accessing points in a geo_point
field called path
in Elasticsearch. When using doc['path'][index]
, the points are not returned in the order of insertion, which leads to incorrect results.
I need a solution to access any point in path
in query script while maintaining the order of insertion.
PUT _index_template/my-index_template
{"index_patterns": [
"my-index*"
],
"template": {
"settings": {
"index": {
"number_of_shards": "1",
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_hot,data_warm"
}
}
},
"final_pipeline": "update_modified_time",
"lifecycle": {
"name": "my-index*"
}
}
},
"mappings": {
"_source": {
"excludes": [
"cr_update"
]
},
"properties": {
"path": {
"type": "geo_point"
}
}
}}
}
PUT /my-index-0001/_doc/my_doc_0001
{
"path":[ [3, 10],[4,20],[-2, 50]]
}
GET my-index-0001/_search
{"runtime_mappings": {
"path_0": {
"type": "geo_point",
"script": {
"source": "emit(doc['path'][0].lon,doc['path'][0].lat)"
}
},
"path_0_with_doc": {
"type": "geo_point",
"script": {
"source": "emit(params._source.path[0][0],params._source.path[0][1])"
}
}
},
"fields":["path_0","path_1","path_0_with_doc"],
"query":{"bool":{"filter": [
{"script":
{"script": "doc['path_0_with_doc'].lon >5.0"}
}
]}}}
Have you got an elegant/ efficient solution ?
Thank you