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
Disabled parent/child queries in the delete by query api. #5916
Closed
martijnvg
wants to merge
3
commits into
elastic:master
from
martijnvg:bug/disable-pc-in-delete-by-query-api
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/org/elasticsearch/index/query/QueryParserUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.query; | ||
|
||
import org.elasticsearch.search.internal.SearchContext; | ||
|
||
/** | ||
*/ | ||
public final class QueryParserUtils { | ||
|
||
private QueryParserUtils() { | ||
} | ||
|
||
/** | ||
* Ensures that the query parsing wasn't invoked via the delete by query api. | ||
*/ | ||
public static void ensureNotDeleteByQuery(String name, QueryParseContext parseContext) { | ||
if ("delete_by_query".equals(SearchContext.current().source())) { | ||
throw new QueryParsingException(parseContext.index(), "[" + name + "] unsupported in delete_by_query api"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,19 @@ | |
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.lucene.search.XFilteredQuery; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.query.support.XContentStructure; | ||
import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData; | ||
import org.elasticsearch.index.mapper.DocumentMapper; | ||
import org.elasticsearch.index.mapper.internal.ParentFieldMapper; | ||
import org.elasticsearch.index.query.support.XContentStructure; | ||
import org.elasticsearch.index.search.child.CustomQueryWrappingFilter; | ||
import org.elasticsearch.index.search.child.ScoreType; | ||
import org.elasticsearch.index.search.child.TopChildrenQuery; | ||
import org.elasticsearch.index.search.nested.NonNestedDocsFilter; | ||
import org.elasticsearch.search.internal.SearchContext; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.index.query.QueryParserUtils.ensureNotDeleteByQuery; | ||
|
||
/** | ||
* | ||
*/ | ||
|
@@ -54,6 +55,7 @@ public String[] names() { | |
|
||
@Override | ||
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should generalize this in a utils methods like public void ensureNotDeleteByQuery(QueryParser parser, QueryParseContext parseContext) {
if ("delete_by_query".equals(SearchContext.current().source())) {
throw new QueryParsingException(parseContext.index(), "[" + parser.names()[0] + "] unsupported in delete_by_query api");
}
} that way you only need to have that logic in one place.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! I'll change that. |
||
ensureNotDeleteByQuery(NAME, parseContext); | ||
XContentParser parser = parseContext.parser(); | ||
|
||
boolean queryFound = false; | ||
|
@@ -116,10 +118,6 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars | |
return null; | ||
} | ||
|
||
if ("delete_by_query".equals(SearchContext.current().source())) { | ||
throw new QueryParsingException(parseContext.index(), "[top_children] unsupported in delete_by_query api"); | ||
} | ||
|
||
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType); | ||
if (childDocMapper == null) { | ||
throw new QueryParsingException(parseContext.index(), "No mapping for for type [" + childType + "]"); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a constant here? and use it both here and in the delete by query action?