# Possible bug in TopChildrenQuery

**URL:** <https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643>\
**Category:** Elasticsearch\
**Created:** [July 3, 2013, 1:27pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643 "2013-07-03T13:27:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_Ribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ribeiro/32/2238_2.png) [@Rodrigo\_Ribeiro](https://discuss.elastic.co/u/Rodrigo_Ribeiro)\
**Post date:** [July 3, 2013, 1:27pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/1 "2013-07-03T13:27:43Z")

</div>

I'm getting this error using the TopChildrenQuery:  
ClassCastException[org.elasticsearch.index.search.child.TopChildrenQuery  
cannot be cast to org.elasticsearch.index.search.child.HasChildFilter];

Debugging, i found the error to happen in this line:

> <https://github.com/elastic/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java>

Which seems weird, why would it convert to HasChildFilter there? Shouldn't  
it be casting to TopChildrenQuery?  
If it is a bug, i can submit the issue/pull-request fixing.

Thanks.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Ribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ribeiro/32/2238_2.png) [@Rodrigo\_Ribeiro](https://discuss.elastic.co/u/Rodrigo_Ribeiro)\
**Post date:** [July 3, 2013, 4:42pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/2 "2013-07-03T16:42:53Z")

</div>

I've done few tests.  
Changing the casting to TopChildrenQuery did stop the error, but i'm not  
sure about side effects, i'll look more into it.

Something also weird is that the .equals() method on XFilteredQuery can  
return false when compared with itself.  
So, i actually need to change the equals method on TopChildrenQuery  
to: [TopChildrenQueryEquals.java · GitHub](https://gist.github.com/rodrigopr/5920278)  
This is just some experimentations, trying to see any side effect.

On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:

> I'm getting this error using the TopChildrenQuery:  
> ClassCastException[org.elasticsearch.index.search.child.TopChildrenQuery  
> cannot be cast to org.elasticsearch.index.search.child.HasChildFilter];
> 
> Debugging, i found the error to happen in this line:
> 
> [https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> 
> Which seems weird, why would it convert to HasChildFilter there? Shouldn't  
> it be casting to TopChildrenQuery?  
> If it is a bug, i can submit the issue/pull-request fixing.
> 
> Thanks.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 3, 2013, 7:30pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/3 "2013-07-03T19:30:56Z")

</div>

That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery, but  
also in the ChildrenQuery and ParentQuery classes. I will open an issue  
soon and fix this. Thanks for reporting this.

Btw: How are you using the top\_children query in your search requests? Are  
you wrapping it in a `fquery` filter?

On 3 July 2013 18:42, Rodrigo Ribeiro [rodriguinho@jusbrasil.com.br](mailto:rodriguinho@jusbrasil.com.br) wrote:

> I've done few tests.  
> Changing the casting to TopChildrenQuery did stop the error, but i'm not  
> sure about side effects, i'll look more into it.
> 
> Something also weird is that the .equals() method on XFilteredQuery can  
> return false when compared with itself.  
> So, i actually need to change the equals method on TopChildrenQuery to:  
> [TopChildrenQueryEquals.java · GitHub](https://gist.github.com/rodrigopr/5920278)  
> This is just some experimentations, trying to see any side effect.
> 
> On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> 
> > I'm getting this error using the TopChildrenQuery:  
> > ClassCastException[org.\*\*elasticsearch.index.search.\*\*child.TopChildrenQuery  
> > cannot be cast to org.elasticsearch.index.\*\*search.child.HasChildFilter];
> > 
> > Debugging, i found the error to happen in this line:  
> > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > child/TopChildrenQuery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > 
> > Which seems weird, why would it convert to HasChildFilter there?  
> > Shouldn't it be casting to TopChildrenQuery?  
> > If it is a bug, i can submit the issue/pull-request fixing.
> > 
> > Thanks.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 3, 2013, 7:41pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/4 "2013-07-03T19:41:47Z")

</div>

I've opened a issue for this:

> <https://github.com/elastic/elasticsearch/issues/3290>
>
> In the case that the \`top\_children\`, \`has\_child\` or \`has\_parent\` queries are cac…hed via the \`fquery\` filter then an class cast exception error occurs.

Also I pushed a fix for it in master and 0.90 branches.

On 3 July 2013 21:30, Martijn v Groningen [martijn.v.groningen@gmail.com](mailto:martijn.v.groningen@gmail.com)wrote:

> That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery, but  
> also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> soon and fix this. Thanks for reporting this.
> 
> Btw: How are you using the top\_children query in your search requests? Are  
> you wrapping it in a `fquery` filter?
> 
> On 3 July 2013 18:42, Rodrigo Ribeiro [rodriguinho@jusbrasil.com.br](mailto:rodriguinho@jusbrasil.com.br)wrote:
> 
> > I've done few tests.  
> > Changing the casting to TopChildrenQuery did stop the error, but i'm not  
> > sure about side effects, i'll look more into it.
> > 
> > Something also weird is that the .equals() method on XFilteredQuery can  
> > return false when compared with itself.  
> > So, i actually need to change the equals method on TopChildrenQuery to:  
> > [TopChildrenQueryEquals.java · GitHub](https://gist.github.com/rodrigopr/5920278)  
> > This is just some experimentations, trying to see any side effect.
> > 
> > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > 
> > > I'm getting this error using the TopChildrenQuery:  
> > > ClassCastException[org.\*\*elasticsearch.index.search.**child.TopChildrenQuery  
> > > cannot be cast to org.elasticsearch.index.**  
> > > search.child.HasChildFilter];
> > > 
> > > Debugging, i found the error to happen in this line:  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > child/TopChildrenQuery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > 
> > > Which seems weird, why would it convert to HasChildFilter there?  
> > > Shouldn't it be casting to TopChildrenQuery?  
> > > If it is a bug, i can submit the issue/pull-request fixing.
> > > 
> > > Thanks.
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Ribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ribeiro/32/2238_2.png) [@Rodrigo\_Ribeiro](https://discuss.elastic.co/u/Rodrigo_Ribeiro)\
**Post date:** [July 3, 2013, 9:06pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/5 "2013-07-03T21:06:04Z")

</div>

Thanks Martjn,

The first error was fixed, but now i'm running in another problem, the one  
that I mention before about XFilteredQuery.

The following comparison returns false, even `originalChildQuery` and  
`that.originalChildQuery` being the same instance:

> <https://github.com/elastic/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265>

This is a problem for the rewrite() method of the TopChildQuery, cause it  
do a indexOf and can't found the query, resulting on  
a ArrayIndexOutOfBoundsException later:

> <https://github.com/elastic/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116>

This is kinda how i'm using it: [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)

Thanks again for the quick help.

On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:

> I've opened a issue for this:  
> [The top\_children, has\_child and has\_parent query can cause error when cached. · Issue #3290 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> Also I pushed a fix for it in master and 0.90 branches.
> 
> On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery, but  
> > also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > soon and fix this. Thanks for reporting this.
> > 
> > Btw: How are you using the top\_children query in your search requests?  
> > Are you wrapping it in a `fquery` filter?
> > 
> > On 3 July 2013 18:42, Rodrigo Ribeiro \<rodri...@jusbrasil.com.br\<javascript:\>
> > 
> > > wrote:
> > 
> > > I've done few tests.  
> > > Changing the casting to TopChildrenQuery did stop the error, but i'm not  
> > > sure about side effects, i'll look more into it.
> > > 
> > > Something also weird is that the .equals() method on XFilteredQuery can  
> > > return false when compared with itself.  
> > > So, i actually need to change the equals method on TopChildrenQuery to:  
> > > [TopChildrenQueryEquals.java · GitHub](https://gist.github.com/rodrigopr/5920278)  
> > > This is just some experimentations, trying to see any side effect.
> > > 
> > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > 
> > > > I'm getting this error using the TopChildrenQuery:  
> > > > ClassCastException[org.\*\*elasticsearch.index.search.**child.TopChildrenQuery  
> > > > cannot be cast to org.elasticsearch.index.**  
> > > > search.child.HasChildFilter];
> > > > 
> > > > Debugging, i found the error to happen in this line:  
> > > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > > child/TopChildrenQuery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > 
> > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > 
> > > > Thanks.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 4, 2013, 10:31am UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/6 "2013-07-04T10:31:26Z")

</div>

I think that the following code in TopChildrenQuery#equals() is correct:  
TopChildrenQuery that = (TopChildrenQuery) obj;  
if (!originalChildQuery.equals(that.originalChildQuery)) {  
return false;  
}

All Query impl should have the following code, that returns in the case the  
instance is the same:  
if (this == obj) {  
return true;  
}

So I wouldn't expect that TopChildrenQuery#equals method to be a problem.  
What query are you wrapping in the top\_children query in your gist?

On 3 July 2013 23:06, Rodrigo Ribeiro [rodriguinho@jusbrasil.com.br](mailto:rodriguinho@jusbrasil.com.br) wrote:

> Thanks Martjn,
> 
> The first error was fixed, but now i'm running in another problem, the one  
> that I mention before about XFilteredQuery.
> 
> The following comparison returns false, even `originalChildQuery` and  
> `that.originalChildQuery` being the same instance:
> 
> [https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265)
> 
> This is a problem for the rewrite() method of the TopChildQuery, cause it  
> do a indexOf and can't found the query, resulting on  
> a ArrayIndexOutOfBoundsException later:
> 
> [https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116)
> 
> This is kinda how i'm using it: [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)
> 
> Thanks again for the quick help.
> 
> On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:
> 
> > I've opened a issue for this: [https://github.com/](https://github.com/)\*\*  
> > elasticsearch/elasticsearch/\*\*issues/3290[https://github.com/elasticsearch/elasticsearch/issues/3290](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> > Also I pushed a fix for it in master and 0.90 branches.
> > 
> > On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\*\*\>wrote:
> > 
> > > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery, but  
> > > also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > > soon and fix this. Thanks for reporting this.
> > > 
> > > Btw: How are you using the top\_children query in your search requests?  
> > > Are you wrapping it in a `fquery` filter?
> > > 
> > > On 3 July 2013 18:42, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br) wrote:
> > > 
> > > > I've done few tests.  
> > > > Changing the casting to TopChildrenQuery did stop the error, but i'm  
> > > > not sure about side effects, i'll look more into it.
> > > > 
> > > > Something also weird is that the .equals() method on XFilteredQuery can  
> > > > return false when compared with itself.  
> > > > So, i actually need to change the equals method on TopChildrenQuery to:  
> > > > [https://gist.github.com/\*\*rodrigopr/5920278](https://gist.github.com/**rodrigopr/5920278)[https://gist.github.com/rodrigopr/5920278](https://gist.github.com/rodrigopr/5920278)  
> > > > This is just some experimentations, trying to see any side effect.
> > > > 
> > > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > > 
> > > > > I'm getting this error using the TopChildrenQuery:  
> > > > > ClassCastException[org. **elastic** search.index.search.\*\*child.\*\*TopChildrenQuery  
> > > > > cannot be cast to org.elasticsearch.index. **search**  
> > > > > .child.HasChildFilter];
> > > > > 
> > > > > Debugging, i found the error to happen in this line:  
> > > > > [https://github.com/\*\*elasticsear\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear** ch/elasticsearch/**blob/0.90/)\*\*  
> > > > > src/main/java/org/ **elasticsearc** h/index/search/ **child/**  
> > > > > TopChildrenQuery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > > 
> > > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > > 
> > > > > Thanks.
> > > > 
> > > > --  
> > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > 
> > > --  
> > > Met vriendelijke groet,
> > > 
> > > Martijn van Groningen
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Ribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ribeiro/32/2238_2.png) [@Rodrigo\_Ribeiro](https://discuss.elastic.co/u/Rodrigo_Ribeiro)\
**Post date:** [July 4, 2013, 2:15pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/7 "2013-07-04T14:15:38Z")

</div>

I agree with you about the TopChildrenQuery#equals method.

I think the problem is actually on:  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162)

Cause `xFilteredQueryInstance.equals(xFilteredQueryInstance)` can return  
false.

This is how we are using the top\_children:  
[https://gist.github.com/rodrigopr/5928134](https://gist.github.com/rodrigopr/5928134)

On Thursday, July 4, 2013 7:31:26 AM UTC-3, Martijn v Groningen wrote:

> I think that the following code in TopChildrenQuery#equals() is correct:  
> TopChildrenQuery that = (TopChildrenQuery) obj;  
> if (!originalChildQuery.equals(that.originalChildQuery)) {  
> return false;  
> }
> 
> All Query impl should have the following code, that returns in the case  
> the instance is the same:  
> if (this == obj) {  
> return true;  
> }
> 
> So I wouldn't expect that TopChildrenQuery#equals method to be a problem.  
> What query are you wrapping in the top\_children query in your gist?
> 
> On 3 July 2013 23:06, Rodrigo Ribeiro \<rodri...@jusbrasil.com.br\<javascript:\>
> 
> > wrote:
> 
> > Thanks Martjn,
> > 
> > The first error was fixed, but now i'm running in another problem, the  
> > one that I mention before about XFilteredQuery.
> > 
> > The following comparison returns false, even `originalChildQuery` and  
> > `that.originalChildQuery` being the same instance:
> > 
> > [https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265)
> > 
> > This is a problem for the rewrite() method of the TopChildQuery, cause it  
> > do a indexOf and can't found the query, resulting on  
> > a ArrayIndexOutOfBoundsException later:
> > 
> > [https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116)
> > 
> > This is kinda how i'm using it: [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)
> > 
> > Thanks again for the quick help.
> > 
> > On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:
> > 
> > > I've opened a issue for this: [https://github.com/](https://github.com/)\*\*  
> > > elasticsearch/elasticsearch/\*\*issues/3290[https://github.com/elasticsearch/elasticsearch/issues/3290](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> > > Also I pushed a fix for it in master and 0.90 branches.
> > > 
> > > On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\*\*\>wrote:
> > > 
> > > > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery, but  
> > > > also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > > > soon and fix this. Thanks for reporting this.
> > > > 
> > > > Btw: How are you using the top\_children query in your search requests?  
> > > > Are you wrapping it in a `fquery` filter?
> > > > 
> > > > On 3 July 2013 18:42, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br)wrote:
> > > > 
> > > > > I've done few tests.  
> > > > > Changing the casting to TopChildrenQuery did stop the error, but i'm  
> > > > > not sure about side effects, i'll look more into it.
> > > > > 
> > > > > Something also weird is that the .equals() method on XFilteredQuery  
> > > > > can return false when compared with itself.  
> > > > > So, i actually need to change the equals method on TopChildrenQuery  
> > > > > to: [https://gist.github.com/\*\*rodrigopr/5920278](https://gist.github.com/**rodrigopr/5920278)[https://gist.github.com/rodrigopr/5920278](https://gist.github.com/rodrigopr/5920278)  
> > > > > This is just some experimentations, trying to see any side effect.
> > > > > 
> > > > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > > > 
> > > > > > I'm getting this error using the TopChildrenQuery:  
> > > > > > ClassCastException[org. **elastic** search.index.search.\*\*child.\*\*TopChildrenQuery  
> > > > > > cannot be cast to org.elasticsearch.index. **search**  
> > > > > > .child.HasChildFilter];
> > > > > > 
> > > > > > Debugging, i found the error to happen in this line:  
> > > > > > [https://github.com/\*\*elasticsear\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear** ch/elasticsearch/**blob/0.90/)\*\*  
> > > > > > src/main/java/org/ **elasticsearc** h/index/search/ **child/**  
> > > > > > TopChildrenQuery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > > > 
> > > > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > > > 
> > > > > > Thanks.
> > > > > 
> > > > > --  
> > > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > > 
> > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > > 
> > > > --  
> > > > Met vriendelijke groet,
> > > > 
> > > > Martijn van Groningen
> > > 
> > > --  
> > > Met vriendelijke groet,
> > > 
> > > Martijn van Groningen
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 4, 2013, 4:28pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/8 "2013-07-04T16:28:59Z")

</div>

I don't think that the XFilteredQuery#equals method is a problem, since it  
delegates all calls to FilteredQuery#equals (delegate).  
I assume that you are using `search_type` with option  
`dfs_query_then_fetch`, right?  
Also what elasticsearch version are you using?

On 4 July 2013 16:15, Rodrigo Ribeiro [rodriguinho@jusbrasil.com.br](mailto:rodriguinho@jusbrasil.com.br) wrote:

> I agree with you about the TopChildrenQuery#equals method.
> 
> I think the problem is actually on:
> 
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162)
> 
> Cause `xFilteredQueryInstance.equals(xFilteredQueryInstance)` can return  
> false.
> 
> This is how we are using the top\_children:  
> [https://gist.github.com/rodrigopr/5928134](https://gist.github.com/rodrigopr/5928134)
> 
> On Thursday, July 4, 2013 7:31:26 AM UTC-3, Martijn v Groningen wrote:
> 
> > I think that the following code in TopChildrenQuery#equals() is correct:  
> > TopChildrenQuery that = (TopChildrenQuery) obj;  
> > if (!originalChildQuery.equals(\*\*that.originalChildQuery)) {  
> > return false;  
> > }
> > 
> > All Query impl should have the following code, that returns in the case  
> > the instance is the same:  
> > if (this == obj) {  
> > return true;  
> > }
> > 
> > So I wouldn't expect that TopChildrenQuery#equals method to be a problem.  
> > What query are you wrapping in the top\_children query in your gist?
> > 
> > On 3 July 2013 23:06, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br) wrote:
> > 
> > > Thanks Martjn,
> > > 
> > > The first error was fixed, but now i'm running in another problem, the  
> > > one that I mention before about XFilteredQuery.
> > > 
> > > The following comparison returns false, even `originalChildQuery` and  
> > > `that.originalChildQuery` being the same instance:  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > child/TopChildrenQuery.java#\*\*L265[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265)
> > > 
> > > This is a problem for the rewrite() method of the TopChildQuery, cause  
> > > it do a indexOf and can't found the query, resulting on a **ArrayIndexOutOfBoundsException  
> > > later:  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)**  
> > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > child/TopChildrenQuery.java#\*\*L116[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116)
> > > 
> > > This is kinda how i'm using it: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > rodrigopr/5922742 [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)
> > > 
> > > Thanks again for the quick help.
> > > 
> > > On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:
> > > 
> > > > I've opened a issue for this: [https://github.com/\*\*elast](https://github.com/**elast)\*\*  
> > > > icsearch/elasticsearch/\*\*issues/\*\*3290[https://github.com/elasticsearch/elasticsearch/issues/3290](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> > > > Also I pushed a fix for it in master and 0.90 branches.
> > > > 
> > > > On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\*\*\>wrote:
> > > > 
> > > > > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery,  
> > > > > but also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > > > > soon and fix this. Thanks for reporting this.
> > > > > 
> > > > > Btw: How are you using the top\_children query in your search requests?  
> > > > > Are you wrapping it in a `fquery` filter?
> > > > > 
> > > > > On 3 July 2013 18:42, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br)wrote:
> > > > > 
> > > > > > I've done few tests.  
> > > > > > Changing the casting to TopChildrenQuery did stop the error, but i'm  
> > > > > > not sure about side effects, i'll look more into it.
> > > > > > 
> > > > > > Something also weird is that the .equals() method on XFilteredQuery  
> > > > > > can return false when compared with itself.  
> > > > > > So, i actually need to change the equals method on TopChildrenQuery  
> > > > > > to: [https://gist.github.com/\*\*ro\*\*drigopr/5920278](https://gist.github.com/ **ro** drigopr/5920278)[https://gist.github.com/rodrigopr/5920278](https://gist.github.com/rodrigopr/5920278)  
> > > > > > This is just some experimentations, trying to see any side effect.
> > > > > > 
> > > > > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > > > > 
> > > > > > > I'm getting this error using the TopChildrenQuery:  
> > > > > > > ClassCastException[org.**elastic\*\*\*\*search.index.search.child.  
> > > > > > > TopC**hildrenQuery cannot be cast to org.elasticsearch.index.\*\*  
> > > > > > > search\*\*\*\*.child.HasChildFilter];
> > > > > > > 
> > > > > > > Debugging, i found the error to happen in this line:  
> > > > > > > [https://github.com/\*\*elasticsear\*\*\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear**** ch/elasticsearch/**blob/0.90/)\*\*  
> > > > > > > src\*\*/main/java/org/ **elasticsearc** h/**index/search/child/  
> > > > > > > TopChildren**Query.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > > > > 
> > > > > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > > > > 
> > > > > > > Thanks.
> > > > > > 
> > > > > > --  
> > > > > > 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 elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > > > > 
> > > > > --  
> > > > > Met vriendelijke groet,
> > > > > 
> > > > > Martijn van Groningen
> > > > 
> > > > --  
> > > > Met vriendelijke groet,
> > > > 
> > > > Martijn van Groningen
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Ribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ribeiro/32/2238_2.png) [@Rodrigo\_Ribeiro](https://discuss.elastic.co/u/Rodrigo_Ribeiro)\
**Post date:** [July 4, 2013, 4:37pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/9 "2013-07-04T16:37:24Z")

</div>

Yes, i'm using dfs\_query\_then\_fetch.  
Now that you mention, i tried with just query\_then\_fetch, and it  
works(maybe it is not caching something)

I'm using 0.90.1.

I did mention the equals cause the delegate was a instance  
of org.apache.lucene.search.FilteredQuery, and was being compared with  
a XFilteredQuery object.  
The comparison failed on an `if (getClass() != obj.getClass())` check from  
org.apache.lucene.search.Query#equals

Thanks for your help so far mate.

On Thursday, July 4, 2013 1:28:59 PM UTC-3, Martijn v Groningen wrote:

> I don't think that the XFilteredQuery#equals method is a problem, since it  
> delegates all calls to FilteredQuery#equals (delegate).  
> I assume that you are using `search_type` with option  
> `dfs_query_then_fetch`, right?  
> Also what elasticsearch version are you using?
> 
> On 4 July 2013 16:15, Rodrigo Ribeiro \<rodri...@jusbrasil.com.br\<javascript:\>
> 
> > wrote:
> 
> > I agree with you about the TopChildrenQuery#equals method.
> > 
> > I think the problem is actually on:
> > 
> > [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162)
> > 
> > Cause `xFilteredQueryInstance.equals(xFilteredQueryInstance)` can return  
> > false.
> > 
> > This is how we are using the top\_children:  
> > [https://gist.github.com/rodrigopr/5928134](https://gist.github.com/rodrigopr/5928134)
> > 
> > On Thursday, July 4, 2013 7:31:26 AM UTC-3, Martijn v Groningen wrote:
> > 
> > > I think that the following code in TopChildrenQuery#equals() is correct:  
> > > TopChildrenQuery that = (TopChildrenQuery) obj;  
> > > if (!originalChildQuery.equals(\*\*that.originalChildQuery)) {  
> > > return false;  
> > > }
> > > 
> > > All Query impl should have the following code, that returns in the case  
> > > the instance is the same:  
> > > if (this == obj) {  
> > > return true;  
> > > }
> > > 
> > > So I wouldn't expect that TopChildrenQuery#equals method to be a  
> > > problem. What query are you wrapping in the top\_children query in your gist?
> > > 
> > > On 3 July 2013 23:06, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br) wrote:
> > > 
> > > > Thanks Martjn,
> > > > 
> > > > The first error was fixed, but now i'm running in another problem, the  
> > > > one that I mention before about XFilteredQuery.
> > > > 
> > > > The following comparison returns false, even `originalChildQuery` and  
> > > > `that.originalChildQuery` being the same instance:  
> > > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > > child/TopChildrenQuery.java#\*\*L265[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265)
> > > > 
> > > > This is a problem for the rewrite() method of the TopChildQuery, cause  
> > > > it do a indexOf and can't found the query, resulting on a **ArrayIndexOutOfBoundsException  
> > > > later:  
> > > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)**  
> > > > blob/0.90/src/main/java/org/ **elasticsearch/index/search/**  
> > > > child/TopChildrenQuery.java#\*\*L116[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116)
> > > > 
> > > > This is kinda how i'm using it: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > > rodrigopr/5922742 [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)
> > > > 
> > > > Thanks again for the quick help.
> > > > 
> > > > On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:
> > > > 
> > > > > I've opened a issue for this: [https://github.com/\*\*elast](https://github.com/**elast)\*\*  
> > > > > icsearch/elasticsearch/\*\*issues/\*\*3290[https://github.com/elasticsearch/elasticsearch/issues/3290](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> > > > > Also I pushed a fix for it in master and 0.90 branches.
> > > > > 
> > > > > On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\*\*\>wrote:
> > > > > 
> > > > > > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery,  
> > > > > > but also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > > > > > soon and fix this. Thanks for reporting this.
> > > > > > 
> > > > > > Btw: How are you using the top\_children query in your search  
> > > > > > requests? Are you wrapping it in a `fquery` filter?
> > > > > > 
> > > > > > On 3 July 2013 18:42, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br)wrote:
> > > > > > 
> > > > > > > I've done few tests.  
> > > > > > > Changing the casting to TopChildrenQuery did stop the error, but i'm  
> > > > > > > not sure about side effects, i'll look more into it.
> > > > > > > 
> > > > > > > Something also weird is that the .equals() method on XFilteredQuery  
> > > > > > > can return false when compared with itself.  
> > > > > > > So, i actually need to change the equals method on TopChildrenQuery  
> > > > > > > to: [https://gist.github.com/\*\*ro\*\*drigopr/5920278](https://gist.github.com/ **ro** drigopr/5920278)[https://gist.github.com/rodrigopr/5920278](https://gist.github.com/rodrigopr/5920278)  
> > > > > > > This is just some experimentations, trying to see any side effect.
> > > > > > > 
> > > > > > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > > > > > 
> > > > > > > > I'm getting this error using the TopChildrenQuery:  
> > > > > > > > ClassCastException[org.**elastic\*\*\*\*search.index.search.child.  
> > > > > > > > TopC**hildrenQuery cannot be cast to org.elasticsearch.index.\*\*  
> > > > > > > > search\*\*\*\*.child.HasChildFilter];
> > > > > > > > 
> > > > > > > > Debugging, i found the error to happen in this line:  
> > > > > > > > [https://github.com/\*\*elasticsear\*\*\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear**** ch/elasticsearch/**blob/0.90/)\*\*  
> > > > > > > > src\*\*/main/java/org/ **elasticsearc** h/**index/search/child/  
> > > > > > > > TopChildren**Query.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > > > > > 
> > > > > > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > > > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > > > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > > > > > 
> > > > > > > > Thanks.
> > > > > > > 
> > > > > > > --  
> > > > > > > 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 elasticsearc...@\*\*googlegroups.\*\*com.
> > > > > > > 
> > > > > > > For more options, visit [https://groups.google.com/\*\*grou\*\*ps/opt\_out](https://groups.google.com/ **grou** ps/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > > .
> > > > > > 
> > > > > > --  
> > > > > > Met vriendelijke groet,
> > > > > > 
> > > > > > Martijn van Groningen
> > > > > 
> > > > > --  
> > > > > Met vriendelijke groet,
> > > > > 
> > > > > Martijn van Groningen
> > > 
> > > --  
> > > Met vriendelijke groet,
> > > 
> > > Martijn van Groningen
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 4, 2013, 8:03pm UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/10 "2013-07-04T20:03:27Z")

</div>

This seems like a bug (with the dfs\_\* search type). I suspect that the  
query rewrite is causing this. The TopChildrenQuery#rewrite method looks  
wrong. This part:  
if (rewritten == rewrittenChildQuery) {  
return this;  
}

I haven't been able to reproduce the error that you've encountered, but I  
will update the TopChildrenQuery#rewrite method.

On 4 July 2013 18:37, Rodrigo Ribeiro [rodriguinho@jusbrasil.com.br](mailto:rodriguinho@jusbrasil.com.br) wrote:

> Yes, i'm using dfs\_query\_then\_fetch.  
> Now that you mention, i tried with just query\_then\_fetch, and it  
> works(maybe it is not caching something)
> 
> I'm using 0.90.1.
> 
> I did mention the equals cause the delegate was a instance  
> of org.apache.lucene.search.FilteredQuery, and was being compared with  
> a XFilteredQuery object.  
> The comparison failed on an `if (getClass() != obj.getClass())` check from  
> org.apache.lucene.search.Query#equals
> 
> Thanks for your help so far mate.
> 
> On Thursday, July 4, 2013 1:28:59 PM UTC-3, Martijn v Groningen wrote:
> 
> > I don't think that the XFilteredQuery#equals method is a problem, since  
> > it delegates all calls to FilteredQuery#equals (delegate).  
> > I assume that you are using `search_type` with option  
> > `dfs_query_then_fetch`, right?  
> > Also what elasticsearch version are you using?
> > 
> > On 4 July 2013 16:15, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br) wrote:
> > 
> > > I agree with you about the TopChildrenQuery#equals method.
> > > 
> > > I think the problem is actually on:  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)\*\*  
> > > blob/master/src/main/java/org/ **elasticsearch/common/lucene/**  
> > > search/XFilteredQuery.java#\*\*L162[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java#L162)
> > > 
> > > Cause `xFilteredQueryInstance.**equals(xFilteredQueryInstance)**` can  
> > > return false.
> > > 
> > > This is how we are using the top\_children: [https://gist](https://gist).\*\*  
> > > [github.com/rodrigopr/5928134](http://github.com/rodrigopr/5928134) [https://gist.github.com/rodrigopr/5928134](https://gist.github.com/rodrigopr/5928134)
> > > 
> > > On Thursday, July 4, 2013 7:31:26 AM UTC-3, Martijn v Groningen wrote:
> > > 
> > > > I think that the following code in TopChildrenQuery#equals() is correct:  
> > > > TopChildrenQuery that = (TopChildrenQuery) obj;  
> > > > if (!originalChildQuery.equals( **th** at.originalChildQuery)) {  
> > > > return false;  
> > > > }
> > > > 
> > > > All Query impl should have the following code, that returns in the case  
> > > > the instance is the same:  
> > > > if (this == obj) {  
> > > > return true;  
> > > > }
> > > > 
> > > > So I wouldn't expect that TopChildrenQuery#equals method to be a  
> > > > problem. What query are you wrapping in the top\_children query in your gist?
> > > > 
> > > > On 3 July 2013 23:06, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br)wrote:
> > > > 
> > > > > Thanks Martjn,
> > > > > 
> > > > > The first error was fixed, but now i'm running in another problem, the  
> > > > > one that I mention before about XFilteredQuery.
> > > > > 
> > > > > The following comparison returns false, even `originalChildQuery` and  
> > > > > `that.originalChildQuery` being the same instance:  
> > > > > [https://github.com/\*\*elasticsear\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear** ch/elasticsearch/**blob/0.90/)\*\*  
> > > > > src/main/java/org/ **elasticsearc** h/index/search/ **child/**  
> > > > > TopChildrenQuery.java#\*\*L265[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L265)
> > > > > 
> > > > > This is a problem for the rewrite() method of the TopChildQuery, cause  
> > > > > it do a indexOf and can't found the query, resulting on a \*\*  
> > > > > ArrayIndexOutOfBoundsExcepti**on later:  
> > > > > [https://github.com/\*\*elasticsear\*\*ch/elasticsearch/\*\*blob/0.90/](https://github.com/ **elasticsear** ch/elasticsearch/**blob/0.90/)**  
> > > > > src/main/java/org/ **elasticsearc** h/index/search/ **child/**  
> > > > > TopChildrenQuery.java#\*\*L116[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L116)
> > > > > 
> > > > > This is kinda how i'm using it: [https://gist.github.com/\*\*rodrig](https://gist.github.com/**rodrig)\*\*  
> > > > > opr/5922742 [https://gist.github.com/rodrigopr/5922742](https://gist.github.com/rodrigopr/5922742)
> > > > > 
> > > > > Thanks again for the quick help.
> > > > > 
> > > > > On Wednesday, July 3, 2013 4:41:47 PM UTC-3, Martijn v Groningen wrote:
> > > > > 
> > > > > > I've opened a issue for this: [https://github.com/\*\*elast](https://github.com/**elast)\*\*\*\*  
> > > > > > icsearch/elasticsearch/\*\*issues/\*\*\*\*3290[https://github.com/elasticsearch/elasticsearch/issues/3290](https://github.com/elasticsearch/elasticsearch/issues/3290)  
> > > > > > Also I pushed a fix for it in master and 0.90 branches.
> > > > > > 
> > > > > > On 3 July 2013 21:30, Martijn v Groningen \<[martijn.v...@gmail.com](mailto:martijn.v...@gmail.com)\*\*\>wrote:
> > > > > > 
> > > > > > > That is an epic 'copy-paste' bug... It isn't only TopChildrenQuery,  
> > > > > > > but also in the ChildrenQuery and ParentQuery classes. I will open an issue  
> > > > > > > soon and fix this. Thanks for reporting this.
> > > > > > > 
> > > > > > > Btw: How are you using the top\_children query in your search  
> > > > > > > requests? Are you wrapping it in a `fquery` filter?
> > > > > > > 
> > > > > > > On 3 July 2013 18:42, Rodrigo Ribeiro [rodri...@jusbrasil.com.br](mailto:rodri...@jusbrasil.com.br)wrote:
> > > > > > > 
> > > > > > > > I've done few tests.  
> > > > > > > > Changing the casting to TopChildrenQuery did stop the error, but  
> > > > > > > > i'm not sure about side effects, i'll look more into it.
> > > > > > > > 
> > > > > > > > Something also weird is that the .equals() method on XFilteredQuery  
> > > > > > > > can return false when compared with itself.  
> > > > > > > > So, i actually need to change the equals method on TopChildrenQuery  
> > > > > > > > to: [https://gist.github.com/\*\*ro\*\*\*\*drigopr/5920278](https://gist.github.com/ **ro**** drigopr/5920278)[https://gist.github.com/rodrigopr/5920278](https://gist.github.com/rodrigopr/5920278)  
> > > > > > > > This is just some experimentations, trying to see any side effect.
> > > > > > > > 
> > > > > > > > On Wednesday, July 3, 2013 10:27:43 AM UTC-3, Rodrigo Ribeiro wrote:
> > > > > > > > 
> > > > > > > > > I'm getting this error using the TopChildrenQuery:  
> > > > > > > > > ClassCastException[org. **elastic**** search.index.search.\*\*child.  
> > > > > > > > > \*\*TopC**hildrenQuery cannot be cast to org.elasticsearch.index.\*  
> > > > > > > > > _search_\*\*\*\*\*.child.HasChildFilter];
> > > > > > > > > 
> > > > > > > > > Debugging, i found the error to happen in this line:  
> > > > > > > > > [https://github.com/\*\*elasticsear\*\*\*\*\*\*ch/elasticsearch/](https://github.com/ **elasticsear****** ch/elasticsearch/)\*\*  
> > > > > > > > > blob/0.90/ **src** \*\*/main/java/org/ **elasticsearc** h/ **i**  
> > > > > > > > > ndex/search/ **child/TopChildrenQ** uery.java#\*\*L264[https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264](https://github.com/elasticsearch/elasticsearch/blob/0.90/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java#L264)
> > > > > > > > > 
> > > > > > > > > Which seems weird, why would it convert to HasChildFilter there?  
> > > > > > > > > Shouldn't it be casting to TopChildrenQuery?  
> > > > > > > > > If it is a bug, i can submit the issue/pull-request fixing.
> > > > > > > > > 
> > > > > > > > > Thanks.
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > 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 elasticsearc...@\*\*googlegroups. **c** om.
> > > > > > > > 
> > > > > > > > For more options, visit [https://groups.google.com/\*\*grou](https://groups.google.com/**grou)\*\*\*\*  
> > > > > > > > ps/opt\_out [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > 
> > > > > > > --  
> > > > > > > Met vriendelijke groet,
> > > > > > > 
> > > > > > > Martijn van Groningen
> > > > > > 
> > > > > > --  
> > > > > > Met vriendelijke groet,
> > > > > > 
> > > > > > Martijn van Groningen
> > > > 
> > > > --  
> > > > Met vriendelijke groet,
> > > > 
> > > > Martijn van Groningen
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:28am UTC](https://discuss.elastic.co/t/possible-bug-in-topchildrenquery/12643/11 "2017-07-06T02:28:08Z")

</div>


