# Problem with Or filter

**URL:** <https://discuss.elastic.co/t/problem-with-or-filter/3636>\
**Category:** Elasticsearch\
**Created:** [December 7, 2010, 1:38am UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636 "2010-12-07T01:38:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rs1050](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rs1050/32/2988_2.png) [@rs1050](https://discuss.elastic.co/u/rs1050)\
**Post date:** [December 7, 2010, 1:38am UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/1 "2010-12-07T01:38:28Z")

</div>

I am getting this exception

Dec 06 20:35:56,30 [31223651@qtp-32715418-11] ERROR org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [dfs], total failure; shardFailures {null: RemoteTransportException[[Multiple Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested: ArrayIndexOutOfBoundsException[216]; }{null: RemoteTransportException[[Multiple Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested: ArrayIndexOutOfBoundsException[216]; }{null: RemoteTransportException[[Multiple Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested: ArrayIndexOutOfBoundsException[216]; }{null: RemoteTransportException[[Multiple Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested: ArrayIndexOutOfBoundsException[216]; }{null: RemoteTransportException[[Multiple Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested: ArrayIndexOutOfBoundsException[216]; }

when using simple Or filter.

Thank you.  
RS

---

<div class="post-metadata">

**Author:** ![rs1050](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rs1050/32/2988_2.png) [@rs1050](https://discuss.elastic.co/u/rs1050)\
**Post date:** [December 7, 2010, 2:41am UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/2 "2010-12-07T02:41:11Z")

</div>

FYI I think this happens when one of the fields (both numeric) on which I had 'or' filter had null as value.

Does not hurt me anymore, but please change exception to save time for others.

Thank you.  
RS.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 7, 2010, 8:24pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/3 "2010-12-07T20:24:07Z")

</div>

Can you gist a recreation?  
On Tuesday, December 7, 2010 at 3:38 AM, rs1050 wrote:

> I am getting this exception
> 
> Dec 06 20:35:56,30 [31223651@qtp-32715418-11] ERROR  
> org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
> execute phase [dfs], total failure; shardFailures {null:  
> RemoteTransportException[[Multiple  
> Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested:  
> ArrayIndexOutOfBoundsException[216]; }{null:  
> RemoteTransportException[[Multiple  
> Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested:  
> ArrayIndexOutOfBoundsException[216]; }{null:  
> RemoteTransportException[[Multiple  
> Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested:  
> ArrayIndexOutOfBoundsException[216]; }{null:  
> RemoteTransportException[[Multiple  
> Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested:  
> ArrayIndexOutOfBoundsException[216]; }{null:  
> RemoteTransportException[[Multiple  
> Man][inet[/192.168.1.108:9300]][search/phase/dfs]]; nested:  
> ArrayIndexOutOfBoundsException[216]; }
> 
> when using simple Or filter.
> 
> Thank you.  
> RS
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2031072.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2031072.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![rs1050](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rs1050/32/2988_2.png) [@rs1050](https://discuss.elastic.co/u/rs1050)\
**Post date:** [December 7, 2010, 9:56pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/4 "2010-12-07T21:56:49Z")

</div>

Here is the code I had:  
XContentFilterBuilder filterBuilder = andFilter(termFilter(JOB\_FLD\_COUNTRY\_CODE, user.jobCountryCode1));

```
    NumericRangeFilterBuilder hourlyFilter = null;
    NumericRangeFilterBuilder totalFilter = null;

        hourlyFilter = numericRangeFilter(FIELD_B).gte(123)
        totalFilter = numericRangeFilter(FIELD_A).gte(432)

        filterBuilder.add(
                orFilter(
                        totalFilter,
                        hourlyFilter
                )
        );

```

When I was indexing the object, one of the values for FIELD\_A or FIELD\_B was null and then I got the exception. When I changed indexing piece to put zero if the field is null everything works.

I am using 0.13.1

Thank you.  
RS

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 7, 2010, 9:58pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/5 "2010-12-07T21:58:04Z")

</div>

Can you gist a curl recreation? One that index some data, and then issue the mentioned queries?  
On Tuesday, December 7, 2010 at 11:56 PM, rs1050 wrote:

> Here is the code I had:  
> XContentFilterBuilder filterBuilder =  
> andFilter(termFilter(JOB\_FLD\_COUNTRY\_CODE, user.jobCountryCode1));
> 
> NumericRangeFilterBuilder hourlyFilter = null;  
> NumericRangeFilterBuilder totalFilter = null;
> 
> hourlyFilter = numericRangeFilter(FIELD\_B).gte(123)  
> totalFilter = numericRangeFilter(FIELD\_A).gte(432)
> 
> filterBuilder.add(  
> orFilter(  
> totalFilter,  
> hourlyFilter  
> )  
> );
> 
> When I was indexing the object, one of the values for FIELD\_A or FIELD\_B was  
> null and then I got the exception. When I changed indexing piece to put zero  
> if the field is null everything works.
> 
> I am using 0.13.1
> 
> ## Thank you. RS
> 
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2036478.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2036478.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![rs1050](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rs1050/32/2988_2.png) [@rs1050](https://discuss.elastic.co/u/rs1050)\
**Post date:** [December 7, 2010, 11:29pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/6 "2010-12-07T23:29:53Z")

</div>

The index was created like this:

curl -XPUT '[http://localhost:9200/jobs](http://localhost:9200/jobs)'

The data was put via grails via java api, here is code I used:

```
    def builder = jsonBuilder().startObject();
                    .field(FIELD_A, job.maxHourlyComp)
                    .field(FIELD_B, job.maxTotalComp)

```

when I changed the code to this it works correctly

```
    def builder = jsonBuilder().startObject();
                    .field(FIELD_A, job.maxHourlyComp ?: AppConstants.ZERO)
                    .field(FIELD_B, job.maxTotalComp ?: AppConstants.ZERO)

```

where constant is defined as this:  
public static final double ZERO = 0.0;

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 7, 2010, 11:31pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/7 "2010-12-07T23:31:08Z")

</div>

Can you send a curl recreation? When curl requests to index the data, and then the curl request that does the search? It will simplify things on my end.  
On Wednesday, December 8, 2010 at 1:29 AM, rs1050 wrote:

> The index was created like this:
> 
> curl -XPUT '[http://localhost:9200/jobs](http://localhost:9200/jobs)'
> 
> The data was put via grails via java api, here is code I used:
> 
> def builder = jsonBuilder().startObject();  
> .field(FIELD\_A, job.maxHourlyComp)  
> .field(FIELD\_B, job.maxTotalComp)
> 
> when I changed the code to this it works correctly
> 
> def builder = jsonBuilder().startObject();  
> .field(FIELD\_A, job.maxHourlyComp ?:  
> AppConstants.ZERO)  
> .field(FIELD\_B, job.maxTotalComp ?:  
> AppConstants.ZERO)
> 
> where constant is defined as this:  
> public static final double ZERO = 0.0;
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2036979.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2036979.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![rs1050](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rs1050/32/2988_2.png) [@rs1050](https://discuss.elastic.co/u/rs1050)\
**Post date:** [December 7, 2010, 11:58pm UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/8 "2010-12-07T23:58:14Z")

</div>

I am having problems running the simple search via curl for some reason (0.13.1)

curl -XPUT '[http://localhost:9200/rs1050/](http://localhost:9200/rs1050/)'  
curl -XPUT '[http://localhost:9200/rs1050/jobs/1](http://localhost:9200/rs1050/jobs/1)' -d '  
{  
"user" : "rs1050",  
"fieldA" : null,  
"fieldB" : null  
}  
'  
then I use basic search like this  
curl -XGET '[http://localhost:9200/rs1050/jobs/\_search](http://localhost:9200/rs1050/jobs/_search)' -d '  
{  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "some query string here"  
}  
},  
"filter" : {  
"term" : { "user" : "kimchy" }  
}  
}  
}  
'

and I am getting this exception

org.elasticsearch.search.SearchParseException: [rs1050][4]: from[-1],size[-1]: Parse Failure [Failed to parse [  
{  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "some query string here"  
}  
},  
"filter" : {  
"term" : { "user" : "kimchy" }  
}  
}  
}  
]]  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:420)  
at org.elasticsearch.search.SearchService.createContext(SearchService.java:335)  
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:169)  
at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:131)  
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.j  
ava:76)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.access$000(TransportSearchTypeAction.java:77)  
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.run(TransportSearchTypeAction.java:150)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:619)  
Caused by: org.elasticsearch.search.SearchParseException: [rs1050][4]: from[-1],size[-1]: Parse Failure [No parser for element [filtered]]  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:405)  
... 10 more

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 8, 2010, 6:06am UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/9 "2010-12-08T06:06:30Z")

</div>

You need to wrap it in another query :), since the search body can have many more parameters, it needs to know what the main query is. Here is how it should look like: [gist:732957 · GitHub](https://gist.github.com/732957).  
On Wednesday, December 8, 2010 at 1:58 AM, rs1050 wrote:

> I am having problems running the simple search via curl for some reason  
> (0.13.1)
> 
> curl -XPUT '[http://localhost:9200/rs1050/](http://localhost:9200/rs1050/)'  
> curl -XPUT '[http://localhost:9200/rs1050/jobs/1](http://localhost:9200/rs1050/jobs/1)' -d '  
> {  
> "user" : "rs1050",  
> "fieldA" : null,  
> "fieldB" : null  
> }  
> '  
> then I use basic search like this  
> curl -XGET '[http://localhost:9200/rs1050/jobs/\_search](http://localhost:9200/rs1050/jobs/_search)' -d '  
> {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "some query string here"  
> }  
> },  
> "filter" : {  
> "term" : { "user" : "kimchy" }  
> }  
> }  
> }  
> '
> 
> and I am getting this exception
> 
> ## org.elasticsearch.search.SearchParseException: [rs1050][4]: from[-1],size[-1]: Parse Failure [Failed to parse [{ "filtered" : { "query" : { "query\_string" : { "query" : "some query string here" } }, "filter" : { "term" : { "user" : "kimchy" } } } }]] at org.elasticsearch.search.SearchService.parseSource(SearchService.java:420) at org.elasticsearch.search.SearchService.createContext(SearchService.java:335) at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:169) at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:131) at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.j ava:76) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.access$000(TransportSearchTypeAction.java:77) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.run(TransportSearchTypeAction.java:150) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: org.elasticsearch.search.SearchParseException: [rs1050][4]: from[-1],size[-1]: Parse Failure [No parser for element [filtered]] at org.elasticsearch.search.SearchService.parseSource(SearchService.java:405) ... 10 more
> 
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2037073.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-Or-filter-tp2031072p2037073.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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, 4:15am UTC](https://discuss.elastic.co/t/problem-with-or-filter/3636/10 "2017-07-06T04:15:33Z")

</div>


