Script field .. shards failed

Hi,
I create a script field and i have a lot of shards failed.

my script field is just :

doc['evenement.@timestamp'].value.getMillis() - doc['debutSejour'].value.getMillis()

shards failed exist too fort :

if(doc['evenement.categorieMouvement'].value.contains("Exit") && !doc['evenement.@timestamp'].empty) { return (doc['evenement.@timestamp'].value - doc['debutSejour'].value) } else { return null; }

my version is 6.5.4

help me please !
thank you

is your time field actually "evenement.@timestamp"? If that is correct you might have to add a check in the scripted field for the field existing in the document if not all documents contain all those fields.

Welcome to our community! :smiley:

I just wanted to pop in and make mention that 6.5 has been EOL for over a year now, please upgrade ASAP.

Hi,
"evenement.@timestamp" is my time field for 1 event and i confirm this field is not present in all documents.
my new script >

if (doc.containsKey('evenement.@timestamp') || doc.containsKey('debutSejour')) { return doc['evenement.@timestamp'].value - doc['debutSejour'].value } else { return null }

dev tools return >

{
"took" : 62,
"timed_out" : false,
"_shards" : {
"total" : 353,
"successful" : 353,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2544886,
"max_score" : 1.0,

but allways shards failed =(

You need an "AND" instead of the "OR" here:
if (doc.containsKey('evenement.@timestamp') || doc.containsKey('debutSejour'))

if (doc.containsKey('evenement.@timestamp') && doc.containsKey('debutSejour')) { return doc['evenement.@timestamp'].value - doc['debutSejour'].value } else { return null }

same result :

{
"took" : 82,
"timed_out" : false,
"_shards" : {
"total" : 353,
"successful" : 353,
"skipped" : 0,
"failed" : 0
},

preview result >

[
{
"_id": "6DFq0XkBjzvHLYjgrDwS",
"Duree du sejour": [
null
]
},

hi i have resolved my problem.
thank you

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