allow to provide no header (but still \n) for msearch

This commit is contained in:
Shay Banon 2012-02-20 22:01:46 +02:00
parent c6130b95e5
commit 790e727843
1 changed files with 27 additions and 25 deletions

View File

@ -77,35 +77,37 @@ public class MultiSearchRequest implements ActionRequest {
} }
// now parse the action // now parse the action
XContentParser parser = xContent.createParser(data, from, nextMarker - from); if (nextMarker - from > 0) {
try { XContentParser parser = xContent.createParser(data, from, nextMarker - from);
// Move to START_OBJECT, if token is null, its an empty data try {
XContentParser.Token token = parser.nextToken(); // Move to START_OBJECT, if token is null, its an empty data
if (token != null) { XContentParser.Token token = parser.nextToken();
assert token == XContentParser.Token.START_OBJECT; if (token != null) {
String currentFieldName = null; assert token == XContentParser.Token.START_OBJECT;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { String currentFieldName = null;
if (token == XContentParser.Token.FIELD_NAME) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
currentFieldName = parser.currentName(); if (token == XContentParser.Token.FIELD_NAME) {
} else if (token.isValue()) { currentFieldName = parser.currentName();
if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) { } else if (token.isValue()) {
searchRequest.indices(Strings.splitStringByCommaToArray(parser.text())); if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) {
} else if ("type".equals(currentFieldName) || "types".equals(currentFieldName)) { searchRequest.indices(Strings.splitStringByCommaToArray(parser.text()));
searchRequest.types(Strings.splitStringByCommaToArray(parser.text())); } else if ("type".equals(currentFieldName) || "types".equals(currentFieldName)) {
} else if ("search_type".equals(currentFieldName) || "searchType".equals(currentFieldName)) { searchRequest.types(Strings.splitStringByCommaToArray(parser.text()));
searchRequest.searchType(parser.text()); } else if ("search_type".equals(currentFieldName) || "searchType".equals(currentFieldName)) {
} else if ("preference".equals(currentFieldName)) { searchRequest.searchType(parser.text());
searchRequest.preference(parser.text()); } else if ("preference".equals(currentFieldName)) {
} else if ("routing".equals(currentFieldName)) { searchRequest.preference(parser.text());
searchRequest.routing(parser.text()); } else if ("routing".equals(currentFieldName)) {
} else if ("query_hint".equals(currentFieldName) || "queryHint".equals(currentFieldName)) { searchRequest.routing(parser.text());
searchRequest.queryHint(parser.text()); } else if ("query_hint".equals(currentFieldName) || "queryHint".equals(currentFieldName)) {
searchRequest.queryHint(parser.text());
}
} }
} }
} }
} finally {
parser.close();
} }
} finally {
parser.close();
} }
// move pointers // move pointers