# Exception while using facet scripts

**URL:** <https://discuss.elastic.co/t/exception-while-using-facet-scripts/10145>\
**Category:** Elasticsearch\
**Created:** [December 21, 2012, 6:09am UTC](https://discuss.elastic.co/t/exception-while-using-facet-scripts/10145 "2012-12-21T06:09:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)\
**Post date:** [December 21, 2012, 6:09am UTC](https://discuss.elastic.co/t/exception-while-using-facet-scripts/10145/1 "2012-12-21T06:09:27Z")

</div>

Hi,

Was trying to use histogram/terms facet to return some generated terms from  
an indexed Date type field. Following is the facet query :

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"custom-facet": {  
"terms": {  
"field": "contentPublishedTime",  
"size": 10,  
"script":  
"doc['contentPublishedTime'].date.dayOfWeek\<6?'Weekday':'Weekend'"  
}  
}  
},  
"size": 1  
}

where contentPublishedTime is a field mapped as a Date type.  
The above query gives an exception

"{"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][0]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][0]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][4]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][4]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][6]: RemoteTransportException[[es\_node\_210\_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][6]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][1]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][1]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][7]: RemoteTransportException[[es\_node\_210\_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][7]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][8]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][8]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][2]: RemoteTransportException[[es\_node\_210\_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][2]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][5]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][5]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][3]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][3]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][9]: RemoteTransportException[[es\_node\_102\_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][9]: query[ConstantScore(NotDeleted(_:_))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }]","status":500}"

I tried the same using histogram facets, as following :

{

```
"query": {

    "match_all": {}

},

"facets": {

    "histo1": {

        "histogram": {

            "key_script": "doc['contentPublishedTime'].date.dayOfWeek<6?'Weekday':'Weekend'",

            "value_script": "doc['anotherField'].value"

        }

    }

},

"size": 0

```

}

This one failed to with similar exception.

However, the following works:

{

```
"query": {

    "match_all": {}

},

"facets": {

    "histo1": {

        "histogram": {

            "key_script": "doc['contentPublishedTime'].date.dayOfWeek<6?55:56",

            "value_script": "doc['anotherField'].value"

        }

    }

},

"size": 0

```

}

Why cant I pass String values in script field? Any hints on how to achieve  
this?

Thanks,  
-- Sujoy.

--

---

<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:** [July 6, 2017, 2:58am UTC](https://discuss.elastic.co/t/exception-while-using-facet-scripts/10145/2 "2017-07-06T02:58:52Z")

</div>

Closed on July 6, 2017, 2:58am UTC


