# How to access and sort many documents using scripting fields?

**URL:** <https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310>\
**Category:** Kibana\
**Created:** [December 3, 2019, 8:52am UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310 "2019-12-03T08:52:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![white\_rabbit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/white_rabbit/32/46888_2.png) [@white\_rabbit](https://discuss.elastic.co/u/white_rabbit)\
**Post date:** [December 3, 2019, 8:52am UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310/1 "2019-12-03T08:52:53Z")

</div>

In my Elasticsearch index I store multiple documents with fields like date, sequence etc. It looks like shown below. My goal is to find reordering. It means that I should sort all documents by date and check whether all sequence numbers are ordered by date. If some of them are reordered I write in chosen document field packet\_reordered and the number of documents for which the package has been reordered based on the date. If document is ordered in a correct way I write the value 0 in the packet\_reordered field. I tried to use scripted field however I have some problems when it comes to do operations on multiple documents using Painless.  
Is it possible to use for example python instead of painless in scripted fields using Elasticsearch 7.4.2?

```
{
  "took": 4632,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 130,
      "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
      {
        "_index": "logs",
        "_type": "log",
        "_id": "yrsas24BmxPy23WAM2TeeQ",
        "_score": 1.0,
        "_source": {
          "name": "something23",
          "date": "2019-11-26T01:30:40",
          "sequence": 34
        }
      },
      {
        "_index": "logs",
        "_type": "log",
        "_id": "y7sas24BmxPy23WAM2TeeQ",
        "_score": 1.0,
        "_source": {
          "name": "something",
          "date": "2019-11-26T01:32:23",
          "sequence": 23
        }
      },
...
```

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [December 6, 2019, 12:51pm UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310/2 "2019-12-06T12:51:13Z")

</div>

Using python for scripted fields was deprecated in 5.0 and is not longer supported from Kibana, [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html).

Script fields only have access to the current document and can not access multiple documents [https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-script-fields](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-script-fields).

---

<div class="post-metadata">

**Author:** ![white\_rabbit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/white_rabbit/32/46888_2.png) [@white\_rabbit](https://discuss.elastic.co/u/white_rabbit)\
**Post date:** [December 13, 2019, 9:37am UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310/3 "2019-12-13T09:37:33Z")

</div>

@Nathan_Reese Thank you very much for you reply. Can you recommend any other alternative solution to this problem?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [December 13, 2019, 3:05pm UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310/4 "2019-12-13T15:05:55Z")

</div>

You can run Elasticsearch queries with simple REST requests. What you are trying to do is not possible in Kibana and needs to be done with a script in your favorite programming language.

---

<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:** [January 10, 2020, 3:05pm UTC](https://discuss.elastic.co/t/how-to-access-and-sort-many-documents-using-scripting-fields/210310/5 "2020-01-10T15:05:59Z")

</div>

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