# Boolean field script doesn't work

**URL:** <https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770>\
**Category:** Elasticsearch\
**Created:** [November 20, 2012, 2:46pm UTC](https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770 "2012-11-20T14:46:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Udi\_Ben\_Amitai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udi_ben_amitai/32/805_2.png) [@Udi\_Ben\_Amitai](https://discuss.elastic.co/u/Udi_Ben_Amitai)\
**Post date:** [November 20, 2012, 2:46pm UTC](https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770/1 "2012-11-20T14:46:43Z")

</div>

Hi,  
I have this mapping:

products: {  
product: {  
boosts: {  
properties: {  
isAvailable: { type: "boolean" }  
}  
}  
}

And while doing this query:  
{  
"from": 0,  
"size": 20,  
"query": {  
"custom\_score": {  
"script": "\_score \*  
(doc['boosts.isAvailable'].value ? 1 : downBoostFactor)",  
"params": {  
"downBoostFactor": 0.001  
},  
"query": {  
"match\_all": {

```
                            } 
                    } 
            } 
    } 

```

}

I get error saying: nested: ScriptRuntimeException[expected Boolean; but  
found: java.lang.String];

Am I doing something wrong? Can boolean fileds be queried in script?

Thanks

--

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [November 20, 2012, 3:14pm UTC](https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770/2 "2012-11-20T15:14:03Z")

</div>

Hello,

I can also reproduce this on 0.20.0.RC1. The issue seems to have been  
reported for a while now:  
[https://github.com/elasticsearch/elasticsearch/issues/609](https://github.com/elasticsearch/elasticsearch/issues/609)

But I'm not sure what's the status on it. I suppose the workaround for  
now would be to index that field as a numeric value.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, Nov 20, 2012 at 4:46 PM, Udi Ben Amitai [sabaudi@gmail.com](mailto:sabaudi@gmail.com) wrote:

> Hi,  
> I have this mapping:
> 
> products: {  
> product: {  
> boosts: {  
> properties: {  
> isAvailable: { type: "boolean" }  
> }  
> }  
> }
> 
> And while doing this query:  
> {  
> "from": 0,  
> "size": 20,  
> "query": {  
> "custom\_score": {  
> "script": "\_score \* (doc['boosts.isAvailable'].value  
> ? 1 : downBoostFactor)",  
> "params": {  
> "downBoostFactor": 0.001  
> },  
> "query": {  
> "match\_all": {
> 
> ```
> }
> }
> }
> }
> 
> ```
> 
> }
> 
> I get error saying: nested: ScriptRuntimeException[expected Boolean; but  
> found: java.lang.String];
> 
> Am I doing something wrong? Can boolean fileds be queried in script?
> 
> Thanks
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Udi\_Ben\_Amitai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udi_ben_amitai/32/805_2.png) [@Udi\_Ben\_Amitai](https://discuss.elastic.co/u/Udi_Ben_Amitai)\
**Post date:** [November 20, 2012, 3:23pm UTC](https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770/3 "2012-11-20T15:23:58Z")

</div>

Thanks!

--

---

<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, 3:03am UTC](https://discuss.elastic.co/t/boolean-field-script-doesnt-work/9770/4 "2017-07-06T03:03:32Z")

</div>


