mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-08 03:49:38 +00:00
Empty list in ids query should not fail, but match no docs
relates to #2687
This commit is contained in:
parent
bde36647fb
commit
4bb4e49155
@ -19,21 +19,22 @@
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.apache.lucene.queries.TermsFilter;
|
||||
import org.apache.lucene.search.ConstantScoreQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.search.Queries;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.Uid;
|
||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -60,11 +61,13 @@ public class IdsQueryParser implements QueryParser {
|
||||
String currentFieldName = null;
|
||||
float boost = 1.0f;
|
||||
XContentParser.Token token;
|
||||
boolean idsProvided = false;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
if ("values".equals(currentFieldName)) {
|
||||
idsProvided = true;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
BytesRef value = parser.bytesOrNull();
|
||||
if (value == null) {
|
||||
@ -95,10 +98,14 @@ public class IdsQueryParser implements QueryParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.size() == 0) {
|
||||
if (!idsProvided) {
|
||||
throw new QueryParsingException(parseContext.index(), "[ids] query, no ids values provided");
|
||||
}
|
||||
|
||||
if (ids.isEmpty()) {
|
||||
return Queries.NO_MATCH_QUERY;
|
||||
}
|
||||
|
||||
if (types == null || types.isEmpty()) {
|
||||
types = parseContext.queryTypes();
|
||||
} else if (types.size() == 1 && Iterables.getFirst(types, null).equals("_all")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user