Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasChild query picks wrong type #5783

Closed
MrHash opened this issue Apr 11, 2014 · 7 comments
Closed

HasChild query picks wrong type #5783

MrHash opened this issue Apr 11, 2014 · 7 comments
Assignees
Labels

Comments

@MrHash
Copy link

MrHash commented Apr 11, 2014

Given the following setup:

curl -XPUT 'http://localhost:9200/haschildtest/'

curl -XPUT 'localhost:9200/haschildtest/posts/_mapping' -d '
{
   "posts":{
      "_parent":{
         "type":"features"
      },
      "_routing":{
         "required":true
      }
   }
}'

curl -XPUT 'localhost:9200/haschildtest/features/feature1' -d '
{
   "title": "feature title 1"
}'

curl -XPUT 'localhost:9200/haschildtest/posts/post1?parent=feature1' -d '
{
   "specials":{
      "title": "jack"
   }
}'

curl -XPUT 'localhost:9200/haschildtest/specials/special1' -d '
{
   "title": "this somehow interferes with the has_child query"
}'

This query runs correctly:

curl -XPOST 'localhost:9200/haschildtest/features/_search?pretty=true' -d '
{
   "query": {
      "has_child": {
         "type": "posts",
         "query": {
            "match": {
               "specials.title": "jack"
            }
         }
      }
   }
}'

Whereas this query with the parent type specifed after the query, fails:

curl -XPOST 'localhost:9200/haschildtest/features/_search?pretty=true' -d '
{
   "query": {
      "has_child": {
         "query": {
            "match": {
               "specials.title": "jack"
            }
         },
         "type": "posts"
      }
   }
}'

Somehow the second example is picking the specials type title field instead of the type specified in the has_child block. I have tested this on ES 1.0.2 and took me a while to figure out what was going on...

@clintongormley
Copy link

Also see #5399

@MrHash
Copy link
Author

MrHash commented Apr 15, 2014

I'm not entirely sure if these are related issues. The curiosity here is the position of type in the query. Why should its positioning after the match query affect the results?

@s1monw
Copy link
Contributor

s1monw commented Apr 15, 2014

I think it's simply ignored and then you don't have a type restriction seems like a bug

@s1monw s1monw added the bug label Apr 15, 2014
@s1monw s1monw self-assigned this Apr 15, 2014
@dakrone dakrone assigned dakrone and unassigned s1monw Apr 15, 2014
@dakrone
Copy link
Member

dakrone commented Apr 15, 2014

@MrHash this is a bug with the way that has_child queries are parsed before parsing out the "type" field, I'm working on a fix for this.

dakrone added a commit to dakrone/elasticsearch that referenced this issue Apr 22, 2014
dakrone added a commit that referenced this issue Apr 22, 2014
Fixes #5783
Fixes #5838

Conflicts:
	src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java
	src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java
	src/main/java/org/elasticsearch/index/query/HasParentFilterParser.java
	src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java
	src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java
mikemccand pushed a commit to mikemccand/elasticsearch that referenced this issue Apr 24, 2014
@fanbiao
Copy link

fanbiao commented Jul 3, 2014

when i use has_child to index and search ,i get no result return ,why?i have use losts of es version.please help me.

@clintongormley
Copy link

@fanbiao Please ask these questions on the mailing list

@fanbiao
Copy link

fanbiao commented Jul 11, 2014

we could not retrieve the child document _source when i use parent-child query,how can i do that?

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Fixes elastic#5783
Fixes elastic#5838

Conflicts:
	src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java
	src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java
	src/main/java/org/elasticsearch/index/query/HasParentFilterParser.java
	src/main/java/org/elasticsearch/index/query/HasParentQueryParser.java
	src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants