Rename multi percolate item actions:

count_percolate -> count
percolate_existing_doc -> percolate
count_percolate_existing_doc -> count

If header contains `id` field, then it will automatically be percolation  an existing document.
This commit is contained in:
Martijn van Groningen 2013-08-26 18:00:36 +02:00
parent 3ca0239668
commit 29626dd201
2 changed files with 60 additions and 62 deletions

View File

@ -35,7 +35,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.action.ValidateActions.addValidationError;
@ -117,14 +119,9 @@ public class MultiPercolateRequest extends ActionRequest<MultiPercolateRequest>
String percolateAction = parser.currentName(); String percolateAction = parser.currentName();
if ("percolate".equals(percolateAction)) { if ("percolate".equals(percolateAction)) {
parsePercolateAction(parser, percolateRequest); parsePercolateAction(parser, percolateRequest);
} else if ("count_percolate".equals(percolateAction) || "countPercolate".equals(percolateAction)) { } else if ("count".equals(percolateAction)) {
percolateRequest.onlyCount(true); percolateRequest.onlyCount(true);
parsePercolateAction(parser, percolateRequest); parsePercolateAction(parser, percolateRequest);
} else if ("percolate_existing_doc".equals(percolateAction) || "percolateExistingDoc".equals(percolateAction)) {
parsePercolateExistingAction(parser, percolateRequest);
} else if ("count_percolate_existing_doc".equals(percolateAction) || "countPercolateExistingDoc".equals(percolateAction)) {
percolateRequest.onlyCount(true);
parsePercolateExistingAction(parser, percolateRequest);
} else { } else {
throw new ElasticSearchParseException(percolateAction + " isn't a supported percolate operation"); throw new ElasticSearchParseException(percolateAction + " isn't a supported percolate operation");
} }
@ -154,70 +151,71 @@ public class MultiPercolateRequest extends ActionRequest<MultiPercolateRequest>
} }
private void parsePercolateAction(XContentParser parser, PercolateRequest percolateRequest) throws IOException { private void parsePercolateAction(XContentParser parser, PercolateRequest percolateRequest) throws IOException {
String globalIndex = indices != null && indices.length > 0 ? indices[0] : null;
Map<String, Object> header = new HashMap<String, Object>();
String currentFieldName = null; String currentFieldName = null;
XContentParser.Token token; XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) { if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName(); currentFieldName = parser.currentName();
} else if (token.isValue()) { } else if (token.isValue()) {
if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) { header.put(currentFieldName, parser.text());
percolateRequest.indices(Strings.splitStringByCommaToArray(parser.text()));
} else if ("type".equals(currentFieldName)) {
percolateRequest.documentType(parser.text());
} else if ("preference".equals(currentFieldName)) {
percolateRequest.preference(parser.text());
} else if ("routing".equals(currentFieldName)) {
percolateRequest.routing(parser.text());
} else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString(parser.text()));
}
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) { header.put(currentFieldName, parseArray(parser));
percolateRequest.indices(parseArray(parser));
} else {
throw new ElasticSearchParseException(currentFieldName + " doesn't support arrays");
}
}
} }
} }
private void parsePercolateExistingAction(XContentParser parser, PercolateRequest percolateRequest) throws IOException { if (header.containsKey("id")) {
String globalIndex = indices != null && indices.length > 0 ? indices[0] : null;
GetRequest getRequest = new GetRequest(globalIndex); GetRequest getRequest = new GetRequest(globalIndex);
percolateRequest.getRequest(getRequest); percolateRequest.getRequest(getRequest);
for (Map.Entry<String, Object> entry : header.entrySet()) {
String currentFieldName = null; Object value = entry.getValue();
XContentParser.Token token; if ("id".equals(entry.getKey())) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { getRequest.id((String) value);
if (token == XContentParser.Token.FIELD_NAME) { header.put("id", entry.getValue());
currentFieldName = parser.currentName(); } else if ("index".equals(entry.getKey()) || "indices".equals(entry.getKey())) {
} else if (token.isValue()) { getRequest.index((String) value);
if ("id".equals(currentFieldName)) { } else if ("type".equals(entry.getKey())) {
getRequest.id(parser.text()); getRequest.type((String) value);
} else if ("index".equals(currentFieldName)) { } else if ("preference".equals(entry.getKey())) {
getRequest.index(parser.text()); getRequest.preference((String) value);
} else if ("type".equals(currentFieldName)) { } else if ("routing".equals(entry.getKey())) {
getRequest.type(parser.text()); getRequest.routing((String) value);
} else if ("preference".equals(currentFieldName)) { } else if ("percolate_index".equals(entry.getKey()) || "percolate_indices".equals(entry.getKey()) || "percolateIndex".equals(entry.getKey()) || "percolateIndices".equals(entry.getKey())) {
getRequest.preference(parser.text()); if (value instanceof String[]) {
} else if ("routing".equals(currentFieldName)) { percolateRequest.indices((String[]) value);
getRequest.routing(parser.text());
} else if ("percolate_index".equals(currentFieldName) || "percolate_indices".equals(currentFieldName) || "percolateIndex".equals(currentFieldName) || "percolateIndices".equals(currentFieldName)) {
percolateRequest.indices(Strings.splitStringByCommaToArray(parser.text()));
} else if ("percolate_type".equals(currentFieldName) || "percolateType".equals(currentFieldName)) {
percolateRequest.documentType(parser.text());
} else if ("percolate_preference".equals(currentFieldName) || "percolatePreference".equals(currentFieldName)) {
percolateRequest.preference(parser.text());
} else if ("percolate_routing".equals(currentFieldName) || "percolateRouting".equals(currentFieldName)) {
percolateRequest.routing(parser.text());
} else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString(parser.text()));
}
} else if (token == XContentParser.Token.START_ARRAY) {
if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) {
percolateRequest.indices(parseArray(parser));
} else { } else {
throw new ElasticSearchParseException(currentFieldName + " doesn't support arrays"); percolateRequest.indices(Strings.splitStringByCommaToArray((String) value));
}
} else if ("percolate_type".equals(entry.getKey()) || "percolateType".equals(entry.getKey())) {
percolateRequest.documentType((String) value);
} else if ("percolate_preference".equals(entry.getKey()) || "percolatePreference".equals(entry.getKey())) {
percolateRequest.preference((String) value);
} else if ("percolate_routing".equals(entry.getKey()) || "percolateRouting".equals(entry.getKey())) {
percolateRequest.routing((String) value);
} else if ("ignore_indices".equals(entry.getKey()) || "ignoreIndices".equals(entry.getKey())) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString((String) value));
}
}
} else {
for (Map.Entry<String, Object> entry : header.entrySet()) {
Object value = entry.getValue();
if ("index".equals(entry.getKey()) || "indices".equals(entry.getKey())) {
if (value instanceof String[]) {
percolateRequest.indices((String[]) value);
} else {
percolateRequest.indices(Strings.splitStringByCommaToArray((String) value));
}
} else if ("type".equals(entry.getKey())) {
percolateRequest.documentType((String) value);
} else if ("preference".equals(entry.getKey())) {
percolateRequest.preference((String) value);
} else if ("routing".equals(entry.getKey())) {
percolateRequest.routing((String) value);
} else if ("ignore_indices".equals(entry.getKey()) || "ignoreIndices".equals(entry.getKey())) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString((String) value));
} }
} }
} }

View File

@ -2,11 +2,11 @@
{"doc" : {"field1" : "value1"}} {"doc" : {"field1" : "value1"}}
{"percolate" : {"indices" : ["my-index2", "my-index3"], "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local", "ignore_indices" : "missing"}} {"percolate" : {"indices" : ["my-index2", "my-index3"], "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local", "ignore_indices" : "missing"}}
{"doc" : {"field1" : "value2"}} {"doc" : {"field1" : "value2"}}
{"count_percolate" : {"indices" : ["my-index4", "my-index5"], "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}} {"count" : {"indices" : ["my-index4", "my-index5"], "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}}
{"doc" : {"field1" : "value3"}} {"doc" : {"field1" : "value3"}}
{"percolate_existing_doc" : {"id" : "1", "index" : "my-index6", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}} {"percolate" : {"id" : "1", "index" : "my-index6", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}}
{} {}
{"count_percolate_existing_doc" : {"id" : "2", "index" : "my-index7", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}} {"count" : {"id" : "2", "index" : "my-index7", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "_local"}}
{} {}
{"percolate" : {"index" : "my-index8", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "primary"}} {"percolate" : {"index" : "my-index8", "type" : "my-type1", "routing" : "my-routing-1", "preference" : "primary"}}
{"doc" : {"field1" : "value4"}} {"doc" : {"field1" : "value4"}}