mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
A search with an empty fields param causes a NullPointerException or a runaway process. Changed logic for an empty fields array, where it won't return the source in this case. Closes #55.
This commit is contained in:
parent
7c68489758
commit
4b04db9030
@ -152,7 +152,7 @@ public class FetchPhase implements SearchPhase {
|
||||
}
|
||||
|
||||
private FieldSelector buildFieldSelectors(SearchContext context) {
|
||||
if (context.fieldNames() == null || context.fieldNames().length == 0) {
|
||||
if (context.fieldNames() == null) {
|
||||
return new UidAndSourceFieldSelector();
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import org.codehaus.jackson.JsonParser;
|
||||
import org.codehaus.jackson.JsonToken;
|
||||
import org.elasticsearch.search.SearchParseElement;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.util.Strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -34,12 +35,15 @@ public class FieldsParseElement implements SearchParseElement {
|
||||
@Override public void parse(JsonParser jp, SearchContext context) throws Exception {
|
||||
JsonToken token = jp.getCurrentToken();
|
||||
if (token == JsonToken.START_ARRAY) {
|
||||
jp.nextToken();
|
||||
ArrayList<String> fieldNames = new ArrayList<String>();
|
||||
do {
|
||||
while ((token = jp.nextToken()) != JsonToken.END_ARRAY) {
|
||||
fieldNames.add(jp.getText());
|
||||
} while ((token = jp.nextToken()) != JsonToken.END_ARRAY);
|
||||
context.fieldNames(fieldNames.toArray(new String[fieldNames.size()]));
|
||||
}
|
||||
if (fieldNames.isEmpty()) {
|
||||
context.fieldNames(Strings.EMPTY_ARRAY);
|
||||
} else {
|
||||
context.fieldNames(fieldNames.toArray(new String[fieldNames.size()]));
|
||||
}
|
||||
} else if (token == JsonToken.VALUE_STRING) {
|
||||
context.fieldNames(new String[]{jp.getText()});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user