parent
db805cf5a9
commit
585cbf6886
|
@ -533,6 +533,7 @@ public class MoreLikeThisRequest extends ActionRequest<MoreLikeThisRequest> {
|
|||
index = in.readString();
|
||||
type = in.readString();
|
||||
id = in.readString();
|
||||
routing = in.readOptionalString();
|
||||
// no need to pass threading over the network, they are always false when coming throw a thread pool
|
||||
int size = in.readVInt();
|
||||
if (size == 0) {
|
||||
|
@ -602,6 +603,7 @@ public class MoreLikeThisRequest extends ActionRequest<MoreLikeThisRequest> {
|
|||
out.writeString(index);
|
||||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
out.writeOptionalString(routing);
|
||||
if (fields == null) {
|
||||
out.writeVInt(0);
|
||||
} else {
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.elasticsearch.cluster.routing.ShardIterator;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.elasticsearch.index.get.GetField;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
|
||||
|
@ -131,7 +132,7 @@ public class TransportMoreLikeThisAction extends TransportAction<MoreLikeThisReq
|
|||
@Override
|
||||
public void onResponse(GetResponse getResponse) {
|
||||
if (!getResponse.isExists()) {
|
||||
listener.onFailure(new ElasticSearchException("document missing"));
|
||||
listener.onFailure(new DocumentMissingException(null, request.type(), request.id()));
|
||||
return;
|
||||
}
|
||||
final BoolQueryBuilder boolBuilder = boolQuery();
|
||||
|
@ -234,7 +235,7 @@ public class TransportMoreLikeThisAction extends TransportAction<MoreLikeThisReq
|
|||
|
||||
// Redirects the request to a data node, that has the index meta data locally available.
|
||||
private void redirect(MoreLikeThisRequest request, final ActionListener<SearchResponse> listener, ClusterState clusterState) {
|
||||
ShardIterator shardIterator = clusterService.operationRouting().getShards(clusterState, request.index(), request.type(), request.id(), null, null);
|
||||
ShardIterator shardIterator = clusterService.operationRouting().getShards(clusterState, request.index(), request.type(), request.id(), request.routing(), null);
|
||||
ShardRouting shardRouting = shardIterator.firstOrNull();
|
||||
if (shardRouting == null) {
|
||||
throw new ElasticSearchException("No shards for index " + request.index());
|
||||
|
|
|
@ -185,4 +185,27 @@ public class MoreLikeThisActionTests extends AbstractNodesTests {
|
|||
assertThat(searchResponse, notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
// See issue: https://github.com/elasticsearch/elasticsearch/issues/3039
|
||||
public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception {
|
||||
startNode("server3");
|
||||
|
||||
client1.admin().indices().prepareDelete().execute().actionGet();
|
||||
client1.admin().indices().prepareCreate("foo")
|
||||
.setSettings(ImmutableSettings.builder().put("index.number_of_replicas", 0)
|
||||
.put("index.number_of_shards", 2)
|
||||
.put("index.routing.allocation.exclude.name", "server1")
|
||||
.put("index.routing.allocation.include.name", "server2,server3"))
|
||||
.execute().actionGet();
|
||||
client1.admin().cluster().prepareHealth("foo").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
client1.prepareIndex("foo", "bar", "1")
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject())
|
||||
.setRouting("4000")
|
||||
.execute().actionGet();
|
||||
client1.admin().indices().prepareRefresh("foo").execute().actionGet();
|
||||
SearchResponse searchResponse = client1.prepareMoreLikeThis("foo", "bar", "1").setRouting("4000").execute().actionGet();
|
||||
assertThat(searchResponse, notNullValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue