Sort for different date depending of the contentType

36 views
Skip to first unread message

Giovanni Luca Ulivo

unread,
Oct 6, 2021, 11:14:25 AM10/6/21
to dotCMS User Group
Hi guys. i have a problem with a sort  in a ElasticSearch query. 
I need to sort by a different date depending of the contentType.
 this is the query :

   "size":9,
   "from":0,
   "sort" :{ 
       "_script" : {
            "script" :{
              "lang": "painless",
               "source":" if(doc.contentType.value=='IntrEvents'){doc.modDate.value.millis }                                       else if(doc.contentType.value=='IntrPressReleases' ){                         doc.modDate.value.millis } "},
        "type" : "number",
        "order" : "desc"
    }
},
"query":{
    "bool":{
        "should":[
            {"bool":{"must":[{"terms":{"contenttype":["intrPressReleases"]}}]}},
            {"bool":{"must":[{"terms":{"contenttype":["intrEvents"]}}]}}
            ]
            }}
}


if i use the modDate fiels the response is ok. if i use a specific date of the contentType 
( for example : if(doc.contentType.value=='IntrEvents'){doc.startDate.value.millis } else if(doc.contentType.value=='IntrPressReleases' ){ doc.datePressReleases.value.millis }    ) i receive an error : 
ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]

The 2 date  are setted to be required and indexed in the contentType. 

why i dont'see the value of this fields in the doc map of script ? 
Reply all
Reply to author
Forward
0 new messages