Shards are failing becuase of script field painless

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


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:

  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 ?

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:

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:

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.

hello,

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

You can see an example here: Sorting comblex Array elements with Painless script

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