# Accessing Points in Order of Insertion in Elasticsearch

**URL:** <https://discuss.elastic.co/t/accessing-points-in-order-of-insertion-in-elasticsearch/371089>\
**Category:** Elastic Search\
**Tags:** painless\
**Created:** [November 26, 2024, 4:26pm UTC](https://discuss.elastic.co/t/accessing-points-in-order-of-insertion-in-elasticsearch/371089 "2024-11-26T16:26:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cecile\_d](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@cecile\_d](https://discuss.elastic.co/u/cecile_d)\
**Post date:** [November 26, 2024, 4:26pm UTC](https://discuss.elastic.co/t/accessing-points-in-order-of-insertion-in-elasticsearch/371089/1 "2024-11-26T16:26:47Z")

</div>

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.

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

---

<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:** [December 24, 2024, 4:26pm UTC](https://discuss.elastic.co/t/accessing-points-in-order-of-insertion-in-elasticsearch/371089/2 "2024-12-24T16:26:56Z")

</div>

Closed on December 24, 2024, 4:26pm UTC

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