# Using script filters in both the parent and the child filters fails

**URL:** https://discuss.elastic.co/t/using-script-filters-in-both-the-parent-and-the-child-filters-fails/16904
**Category:** Elasticsearch
**Created:** [April 9, 2014, 6:45pm UTC](https://discuss.elastic.co/t/using-script-filters-in-both-the-parent-and-the-child-filters-fails/16904 "2014-04-09T18:45:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jozsef\_Szalay](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jozsef\_Szalay](https://discuss.elastic.co/u/Jozsef_Szalay)
#### Post date: [April 9, 2014, 6:45pm UTC](https://discuss.elastic.co/t/using-script-filters-in-both-the-parent-and-the-child-filters-fails/16904/1 "2014-04-09T18:45:32Z")

</div>

I've encountered a weird problem that I hope someone has seen before, and  
can provide a resolution for.

I'm running Elasticsearch 1.0 downloaded as an RPM and installed on a  
cluster of two RedHat nodes. Five shards with one replica each is  
configured.

Unfortunately, I could not reproduce the problem with test data (yet), even  
though I tried it for hours. I'm posting my simplified setup with the hope  
that it helps.

# create the index

curl -XPUT [http://localhost:9200/test\_script/](http://localhost:9200/test_script/)

# add mapping for parent type

curl -XPUT [http://localhost:9200/test\_script/my\_parent/\_mapping](http://localhost:9200/test_script/my_parent/_mapping) -d '  
{  
"my\_parent": {  
"properties": {  
"name": {"type": "string"}  
}  
}  
}'

# add mapping for child type

curl -XPUT [http://localhost:9200/test\_script/my\_child/\_mapping](http://localhost:9200/test_script/my_child/_mapping) -d '  
{  
"my\_child": {  
"\_parent": {"type": "my\_parent"},  
"properties": {  
"value": {"type": "long"}  
}  
}  
}'

# index some records

curl -XPUT [http://localhost:9200/test\_script/my\_parent/1](http://localhost:9200/test_script/my_parent/1) -d '{"name":  
"Parent"}'  
curl -XPUT [http://localhost:9200/test\_script/my\_parent/2](http://localhost:9200/test_script/my_parent/2) -d '{"name":  
"ParentTwo"}'  
curl -XPUT [http://localhost:9200/test\_script/my\_parent/3](http://localhost:9200/test_script/my_parent/3) -d '{"name":  
"ParentThree"}'  
curl -XPUT [http://localhost:9200/test\_script/my\_child/abc?parent=1](http://localhost:9200/test_script/my_child/abc?parent=1) -d  
'{"value": 1234567}'

When I execute the following search (on my real index)

curl -XGET [http://localhost:9200/test\_script/my\_parent/\_search?pretty=true](http://localhost:9200/test_script/my_parent/_search?pretty=true)  
-d '  
{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must\_not": {  
"has\_child": {  
"type": "my\_child",  
"filter": {  
"script": {  
"script":  
"doc["my\_child.value"].value != 1234567"  
}  
}  
}  
},  
"must": {  
"script": {  
"script":  
"doc["my\_parent.name"].value.equals("parent")"  
}  
}  
}  
}  
}  
}  
}'

I get partial results because one of the shards fails with this error

"\_shards" : {  
"total" : 5,  
"successful" : 4,  
"failed" : 1,  
"failures" : [ {  
"index" : "test\_script",  
"shard" : 4,  
"status" : 500,  
"reason" :  
"RemoteTransportException[[host-2][inet[/192.168.0.2:9300]][search/phase/query]];  
nested: QueryPhaseExecutionException[[test\_script][4]:  
query[filtered(ConstantScore(BooleanFilter(-CustomQueryWrappingFilter(child\_filter[my\_child/my\_parent](filtered(ConstantScore(ScriptFilter(vid=(String)doc["my\_child."].value;  
doc["my\_child.value"].value !=  
1234567;)))-\>cache(\_type:my\_child))))))-\>cache(\_type:my\_parent)],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested:  
PropertyAccessException[[Error: could not access: value; in class:  
org.elasticsearch.index.fielddata.ScriptDocValues$Empty]\n[Near : {...  
value ....}]\n ^\n[Line: 1, Column: 1]]; "

All fields are dense (i.e. populated in every parent or child record), so  
the field and the value should be available.

It might be helpful to note that the exception always occurs on the other  
node and not on the one my http request targeted.

I never get an error, but receive the correct results, if I change the  
query to something like this

curl -XGET [http://localhost:9200/test\_script/my\_parent/\_search?pretty=true](http://localhost:9200/test_script/my_parent/_search?pretty=true)  
-d '  
{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must\_not": {  
"has\_child": {  
"type": "my\_child",  
"filter": {  
"script": {  
"script":  
"doc["my\_child.value"].value != 1234567"  
}  
}  
}  
},  
"must": {  
\* "term": {"my\_parent.name": "parent"}\*  
}  
}  
}  
}  
}  
}'

I appreciate any help you can provide.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7768222d-a7d7-41e8-bfc9-5dbe0ad13a8e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7768222d-a7d7-41e8-bfc9-5dbe0ad13a8e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Jozsef\_Szalay](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jozsef\_Szalay](https://discuss.elastic.co/u/Jozsef_Szalay)
#### Post date: [April 10, 2014, 3:19pm UTC](https://discuss.elastic.co/t/using-script-filters-in-both-the-parent-and-the-child-filters-fails/16904/2 "2014-04-10T15:19:22Z")

</div>

Update: I've tried to clear the cache, to refresh the index, closing and  
reopening the index, no joy. Then everything started to work automagically  
after a while (tens of minutes later). The index itself has a total of 620  
docs.

On Wednesday, April 9, 2014 1:45:32 PM UTC-5, Jozsef Szalay wrote:

> I've encountered a weird problem that I hope someone has seen before, and  
> can provide a resolution for.
> 
> I'm running Elasticsearch 1.0 downloaded as an RPM and installed on a  
> cluster of two RedHat nodes. Five shards with one replica each is  
> configured.
> 
> Unfortunately, I could not reproduce the problem with test data (yet),  
> even though I tried it for hours. I'm posting my simplified setup with the  
> hope that it helps.
> 
> # create the index
> 
> curl -XPUT [http://localhost:9200/test\_script/](http://localhost:9200/test_script/)
> 
> # add mapping for parent type
> 
> curl -XPUT [http://localhost:9200/test\_script/my\_parent/\_mapping](http://localhost:9200/test_script/my_parent/_mapping) -d '  
> {  
> "my\_parent": {  
> "properties": {  
> "name": {"type": "string"}  
> }  
> }  
> }'
> 
> # add mapping for child type
> 
> curl -XPUT [http://localhost:9200/test\_script/my\_child/\_mapping](http://localhost:9200/test_script/my_child/_mapping) -d '  
> {  
> "my\_child": {  
> "\_parent": {"type": "my\_parent"},  
> "properties": {  
> "value": {"type": "long"}  
> }  
> }  
> }'
> 
> # index some records
> 
> curl -XPUT [http://localhost:9200/test\_script/my\_parent/1](http://localhost:9200/test_script/my_parent/1) -d '{"name":  
> "Parent"}'  
> curl -XPUT [http://localhost:9200/test\_script/my\_parent/2](http://localhost:9200/test_script/my_parent/2) -d '{"name":  
> "ParentTwo"}'  
> curl -XPUT [http://localhost:9200/test\_script/my\_parent/3](http://localhost:9200/test_script/my_parent/3) -d '{"name":  
> "ParentThree"}'  
> curl -XPUT [http://localhost:9200/test\_script/my\_child/abc?parent=1](http://localhost:9200/test_script/my_child/abc?parent=1) -d  
> '{"value": 1234567}'
> 
> When I execute the following search (on my real index)
> 
> curl -XGET [http://localhost:9200/test\_script/my\_parent/\_search?pretty=true-d](http://localhost:9200/test_script/my_parent/_search?pretty=true-d) '  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "bool": {  
> "must\_not": {  
> "has\_child": {  
> "type": "my\_child",  
> "filter": {  
> "script": {  
> "script":  
> "doc["my\_child.value"].value != 1234567"  
> }  
> }  
> }  
> },  
> "must": {  
> "script": {  
> "script": "doc["my\_parent.name  
> "].value.equals("parent")"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> I get partial results because one of the shards fails with this error
> 
> "\_shards" : {  
> "total" : 5,  
> "successful" : 4,  
> "failed" : 1,  
> "failures" : [ {  
> "index" : "test\_script",  
> "shard" : 4,  
> "status" : 500,  
> "reason" :  
> "RemoteTransportException[[host-2][inet[/192.168.0.2:9300]][search/phase/query]];  
> nested: QueryPhaseExecutionException[[test\_script][4]:  
> query[filtered(ConstantScore(BooleanFilter(-CustomQueryWrappingFilter(child\_filter[my\_child/my\_parent](filtered(ConstantScore(ScriptFilter(vid=(String)doc["my\_child."].value;  
> doc["my\_child.value"].value !=  
> 1234567;)))-\>cache(\_type:my\_child))))))-\>cache(\_type:my\_parent)],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested:  
> PropertyAccessException[[Error: could not access: value; in class:  
> org.elasticsearch.index.fielddata.ScriptDocValues$Empty]\n[Near : {...  
> value ....}]\n ^\n[Line: 1, Column: 1]]; "
> 
> All fields are dense (i.e. populated in every parent or child record), so  
> the field and the value should be available.
> 
> It might be helpful to note that the exception always occurs on the other  
> node and not on the one my http request targeted.
> 
> I never get an error, but receive the correct results, if I change the  
> query to something like this
> 
> curl -XGET [http://localhost:9200/test\_script/my\_parent/\_search?pretty=true-d](http://localhost:9200/test_script/my_parent/_search?pretty=true-d) '  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "bool": {  
> "must\_not": {  
> "has\_child": {  
> "type": "my\_child",  
> "filter": {  
> "script": {  
> "script":  
> "doc["my\_child.value"].value != 1234567"  
> }  
> }  
> }  
> },  
> "must": {  
> \* "term": {"my\_parent.name  
> [http://my\_parent.name](http://my_parent.name)": "parent"}\*  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> I appreciate any help you can provide.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/83b54a47-0ccb-424f-99ea-1a166b2ed739%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/83b54a47-0ccb-424f-99ea-1a166b2ed739%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:36am UTC](https://discuss.elastic.co/t/using-script-filters-in-both-the-parent-and-the-child-filters-fails/16904/3 "2017-07-06T01:36:53Z")

</div>


