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:
parent
3ca0239668
commit
29626dd201
|
@ -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()) {
|
||||||
|
Object value = entry.getValue();
|
||||||
String currentFieldName = null;
|
if ("id".equals(entry.getKey())) {
|
||||||
XContentParser.Token token;
|
getRequest.id((String) value);
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
header.put("id", entry.getValue());
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
} else if ("index".equals(entry.getKey()) || "indices".equals(entry.getKey())) {
|
||||||
currentFieldName = parser.currentName();
|
getRequest.index((String) value);
|
||||||
} else if (token.isValue()) {
|
} else if ("type".equals(entry.getKey())) {
|
||||||
if ("id".equals(currentFieldName)) {
|
getRequest.type((String) value);
|
||||||
getRequest.id(parser.text());
|
} else if ("preference".equals(entry.getKey())) {
|
||||||
} else if ("index".equals(currentFieldName)) {
|
getRequest.preference((String) value);
|
||||||
getRequest.index(parser.text());
|
} else if ("routing".equals(entry.getKey())) {
|
||||||
} else if ("type".equals(currentFieldName)) {
|
getRequest.routing((String) value);
|
||||||
getRequest.type(parser.text());
|
} else if ("percolate_index".equals(entry.getKey()) || "percolate_indices".equals(entry.getKey()) || "percolateIndex".equals(entry.getKey()) || "percolateIndices".equals(entry.getKey())) {
|
||||||
} else if ("preference".equals(currentFieldName)) {
|
if (value instanceof String[]) {
|
||||||
getRequest.preference(parser.text());
|
percolateRequest.indices((String[]) value);
|
||||||
} else if ("routing".equals(currentFieldName)) {
|
} else {
|
||||||
getRequest.routing(parser.text());
|
percolateRequest.indices(Strings.splitStringByCommaToArray((String) value));
|
||||||
} 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(entry.getKey()) || "percolateType".equals(entry.getKey())) {
|
||||||
} else if ("percolate_type".equals(currentFieldName) || "percolateType".equals(currentFieldName)) {
|
percolateRequest.documentType((String) value);
|
||||||
percolateRequest.documentType(parser.text());
|
} else if ("percolate_preference".equals(entry.getKey()) || "percolatePreference".equals(entry.getKey())) {
|
||||||
} else if ("percolate_preference".equals(currentFieldName) || "percolatePreference".equals(currentFieldName)) {
|
percolateRequest.preference((String) value);
|
||||||
percolateRequest.preference(parser.text());
|
} else if ("percolate_routing".equals(entry.getKey()) || "percolateRouting".equals(entry.getKey())) {
|
||||||
} else if ("percolate_routing".equals(currentFieldName) || "percolateRouting".equals(currentFieldName)) {
|
percolateRequest.routing((String) value);
|
||||||
percolateRequest.routing(parser.text());
|
} else if ("ignore_indices".equals(entry.getKey()) || "ignoreIndices".equals(entry.getKey())) {
|
||||||
} else if ("ignore_indices".equals(currentFieldName) || "ignoreIndices".equals(currentFieldName)) {
|
percolateRequest.ignoreIndices(IgnoreIndices.fromString((String) value));
|
||||||
percolateRequest.ignoreIndices(IgnoreIndices.fromString(parser.text()));
|
|
||||||
}
|
}
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
}
|
||||||
if ("index".equals(currentFieldName) || "indices".equals(currentFieldName)) {
|
} else {
|
||||||
percolateRequest.indices(parseArray(parser));
|
for (Map.Entry<String, Object> entry : header.entrySet()) {
|
||||||
} else {
|
Object value = entry.getValue();
|
||||||
throw new ElasticSearchParseException(currentFieldName + " doesn't support arrays");
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"}}
|
||||||
|
|
Loading…
Reference in New Issue