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

Parse has_child query/filter after child type has been parsed #5838

Closed
wants to merge 1 commit into from

Conversation

dakrone
Copy link
Member

@dakrone dakrone commented Apr 16, 2014

Fixes #5783

} finally {
QueryParseContext.setTypes(origTypes);
}
innerQueryBytes = XContentFactory.jsonBuilder().map(parser.mapOrdered()).bytes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do this in a more optimize manner. We can create a builder, and then use copyCurrentStructure on the builder (passing it a parser), to just copy it over, compared with parsing into a map and then serializing the map. Also, since its internal, I would use smile builder, as its considerably more efficient than json.

@kimchy
Copy link
Member

kimchy commented Apr 16, 2014

can we have a test that verifies it by sending building the search request programmatically maybe (and not using the query builders)?

@dakrone
Copy link
Member Author

dakrone commented Apr 16, 2014

can we have a test that verifies it

Whoops! Forgot to stage the file with the test, pushed with the test and builder change

} finally {
QueryParseContext.setTypes(origTypes);
}
innerQueryBytes = XContentFactory.smileBuilder().copyCurrentStructure(parser).bytes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not guaranteed to be smile! We randomize this in our tests I thing this should break if you run it multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't parsing this as smile, it's creating a internal parser that can be read from. I used smile because Shay recommended it as more efficient than a JSON builder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I misread! I wonder if we need this somewhere else and if we could represent this as an object ie something like this:


public class XContentStructure {
    public XContentStructure( XContentParser parser, WhaterverWeNeedHere ) {
        // copy current struct...
     } 

     public Query asQuery(String...types) {
        //... do it
     }

     public Filter asFilter(String...types) {
        //... do it
     }
}

does this make sense?

@s1monw
Copy link
Contributor

s1monw commented Apr 16, 2014

while you are at it maybe we want to fix the indices query as well it has similar problems?

@martijnvg
Copy link
Member

Also the top_children and has_parent parsers have the same issue. Can these be addressed in this PR as well?

@dakrone
Copy link
Member Author

dakrone commented Apr 17, 2014

Sure, I will work on fixes for the indices, top_children, and has_parent parsers as well as factoring out the parser stuff like Simon recommended.

@dakrone
Copy link
Member Author

dakrone commented Apr 17, 2014

@s1monw @martijnvg pushed a new commit addressing the other query types and refactoring.

* under the License.
*/

package org.elasticsearch.common.xcontent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this deals with parsing of query/filter, I don't think it should be in the common.xcontent package, maybe place it in the same package as QueryParserContext?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think org.elasticsearch.index.query contains almost entirely builder/parsers and QueryParseContext, I think org.elasticsearch.index.query.support would fit better

@dakrone
Copy link
Member Author

dakrone commented Apr 21, 2014

@martijnvg added some commits to this, it now will parse the query/filter in a streaming manner if they types are available when the query/filter is encountered.

@martijnvg
Copy link
Member

Thanks @dakrone! LGTM

@dakrone dakrone added the v1.2.0 label Apr 22, 2014
dakrone added a commit that referenced this pull request 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
dakrone added a commit that referenced this pull request Apr 22, 2014
dakrone added a commit that referenced this pull request Apr 22, 2014
@dakrone dakrone closed this in 029b13c Apr 22, 2014
@dakrone dakrone deleted the 5783-has-child-parser-fix branch April 22, 2014 16:28
mikemccand pushed a commit to mikemccand/elasticsearch that referenced this pull request Apr 24, 2014
mute pushed a commit to mute/elasticsearch that referenced this pull request 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 pull request Jul 29, 2015
@clintongormley clintongormley added the :Search/Search Search-related issues that do not fall into other categories label Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories v1.0.4 v1.1.2 v1.2.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HasChild query picks wrong type
5 participants