mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-08 22:14:59 +00:00
mget API should support global routing parameter
mget API support `_routing` field but not `routing` parameter. Reproduction here: ```sh curl -XDELETE "http://localhost:9200/test/"; echo curl -XPUT "http://localhost:9200/test/" -d'{ "settings": { "number_of_replicas": 0, "number_of_shards": 5 } }'; echo curl -XPUT 'http://localhost:9200/test/order/1-1?routing=key1' -d '{ "productName":"doc 1" }'; echo curl -XPUT 'http://localhost:9200/test/order/1-2?routing=key1' -d '{ "productName":"doc 2" }'; echo curl -XPUT 'http://localhost:9200/test/order/1-3?routing=key1&refresh=true' -d '{ "productName":"doc 3" }'; echo curl -XPOST 'http://localhost:9200/test/order/_mget?pretty' -d '{ "docs" : [ { "_index" : "test", "_type" : "order", "_id" : "1-1", "_routing" : "key1" }, { "_index" : "test", "_type" : "order", "_id" : "1-2", "_routing" : "key1" }, { "_index" : "test", "_type" : "order", "_id" : "1-3", "_routing" : "key1" } ] }'; echo curl -XPOST 'http://localhost:9200/test/order/_mget?pretty&routing=key1' -d '{ "ids": [ "1-1", "1-2", "1-3" ] }'; echo ``` Closes #3996.
This commit is contained in:
parent
e3db12bf50
commit
5d90abf701
@ -96,3 +96,31 @@ curl 'localhost:9200/_mget' -d '{
|
|||||||
]
|
]
|
||||||
}'
|
}'
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
|
[float]
|
||||||
|
[[mget-routing]]
|
||||||
|
=== Routing
|
||||||
|
|
||||||
|
You can specify also specify routing value as a parameter:
|
||||||
|
|
||||||
|
[source,js]
|
||||||
|
--------------------------------------------------
|
||||||
|
curl 'localhost:9200/_mget?routing=key1' -d '{
|
||||||
|
"docs" : [
|
||||||
|
{
|
||||||
|
"_index" : "test",
|
||||||
|
"_type" : "type",
|
||||||
|
"_id" : "1",
|
||||||
|
"_routing" : "key2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_index" : "test",
|
||||||
|
"_type" : "type",
|
||||||
|
"_id" : "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}'
|
||||||
|
--------------------------------------------------
|
||||||
|
|
||||||
|
In this example, document `test/type/2` will be fetch from shard corresponding to routing key `key1` but
|
||||||
|
document `test/type/1` will be fetch from shard corresponding to routing key `key2`.
|
||||||
|
@ -273,6 +273,10 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MultiGetRequest add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, BytesReference data, boolean allowExplicitIndex) throws Exception {
|
public MultiGetRequest add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, BytesReference data, boolean allowExplicitIndex) throws Exception {
|
||||||
|
return add(defaultIndex, defaultType, defaultFields, defaultFetchSource, null, data, allowExplicitIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiGetRequest add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSource, @Nullable String defaultRouting, BytesReference data, boolean allowExplicitIndex) throws Exception {
|
||||||
XContentParser parser = XContentFactory.xContent(data).createParser(data);
|
XContentParser parser = XContentFactory.xContent(data).createParser(data);
|
||||||
try {
|
try {
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
@ -289,7 +293,7 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> {
|
|||||||
String index = defaultIndex;
|
String index = defaultIndex;
|
||||||
String type = defaultType;
|
String type = defaultType;
|
||||||
String id = null;
|
String id = null;
|
||||||
String routing = null;
|
String routing = defaultRouting;
|
||||||
String parent = null;
|
String parent = null;
|
||||||
List<String> fields = null;
|
List<String> fields = null;
|
||||||
long version = Versions.MATCH_ANY;
|
long version = Versions.MATCH_ANY;
|
||||||
@ -389,7 +393,7 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> {
|
|||||||
if (!token.isValue()) {
|
if (!token.isValue()) {
|
||||||
throw new ElasticSearchIllegalArgumentException("ids array element should only contain ids");
|
throw new ElasticSearchIllegalArgumentException("ids array element should only contain ids");
|
||||||
}
|
}
|
||||||
add(new Item(defaultIndex, defaultType, parser.text()).fields(defaultFields).fetchSourceContext(defaultFetchSource));
|
add(new Item(defaultIndex, defaultType, parser.text()).fields(defaultFields).fetchSourceContext(defaultFetchSource).routing(defaultRouting));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class RestMultiGetAction extends BaseRestHandler {
|
|||||||
FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
|
FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.content(), allowExplicitIndex);
|
multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), request.content(), allowExplicitIndex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
XContentBuilder builder = restContentBuilder(request);
|
XContentBuilder builder = restContentBuilder(request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user