# Shards are failing becuase of script field painless

**URL:** <https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092>\
**Category:** Kibana\
**Created:** [March 20, 2019, 7:42am UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092 "2019-03-20T07:42:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRUDHVI\_CHOWDHARY\_NE](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@PRUDHVI\_CHOWDHARY\_NE](https://discuss.elastic.co/u/PRUDHVI_CHOWDHARY_NE)\
**Post date:** [March 20, 2019, 7:42am UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092/1 "2019-03-20T07:42:49Z")

</div>

mappings used

```
PUT kpal
{
  "mappings": {
    "_doc": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

PUT kpal/_doc/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" : "Smith"
    },
    {
      "first" : "Alice",
      "last" : "White"
    }
  ]
}

PUT kpal/_doc/2
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" : "Smith"
    }
]
}

PUT kpal/_doc/3
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" : "Smith"
    },
    {
      "first" : "Alice",
      "last" : "White"
    },
    {
      "first" : "Akbar",
      "last" : "Jyothi"
    }
  ]
}

```

In my kibana dashboard version 6.6.0

 ![1kp](https://us1.discourse-cdn.com/elastic/original/3X/6/f/6fb8e1cd153f4dc420835ebf6be77c7bef10dbce.png)  
 ![12sb](https://us1.discourse-cdn.com/elastic/original/3X/e/c/ec4e897b49163c8251bbb7fdcbac2a65efbeca4c.png)

Now i want to create a new field using script field called "firstname"

**my script field:**

> doc["user.first].value[1]

**getting shards are failed**

also tried  
doc['user.first'][0] ,  
params['\_source']['user.first'][0] but same error

reference used:

> **[Nested field type | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html)**

1. here can we treat user.first behaves like array for each document ?

2. how can i access array of objects in the documents of an index ?

3. In saved search its showing objects in arrays are not well suported,how to resolve this issue ?

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [March 20, 2019, 2:50pm UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092/2 "2019-03-20T14:50:51Z")

</div>

If you'd just like to have a scripted field that gets only the first first name for each document, you can do so like this:

```auto
params._source.user[0].first

```

If you'd like to have a scripted field that gets all of the first names for each user in each document, you can do something like this:

```auto
def firstnames = [];
for (item in params._source.user) {
  firstnames.add(item.first);
}
return firstnames;

```

In general, having objects in arrays is not something that plays well with Kibana. If you can figure out a way to structure your data so that each document has a "group", "first", and "last" instead of an array of objects, it will be easier to use Kibana to visualize your data.

---

<div class="post-metadata">

**Author:** ![PRUDHVI\_CHOWDHARY\_NE](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@PRUDHVI\_CHOWDHARY\_NE](https://discuss.elastic.co/u/PRUDHVI_CHOWDHARY_NE)\
**Post date:** [March 21, 2019, 8:50am UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092/3 "2019-03-21T08:50:23Z")

</div>

hello,

how to sort values of objects in an array in scripted field in kibana and get the lowesr one or greates one

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [March 22, 2019, 8:09pm UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092/4 "2019-03-22T20:09:43Z")

</div>

You can see an example here: [Sorting comblex Array elements with Painless script](https://discuss.elastic.co/t/sorting-comblex-array-elements-with-painless-script/118472)

---

<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:** [April 19, 2019, 8:09pm UTC](https://discuss.elastic.co/t/shards-are-failing-becuase-of-script-field-painless/173092/5 "2019-04-19T20:09:52Z")

</div>

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