Fix failure message serialization in MultiSearchResponse

Fixes #2498
This commit is contained in:
Igor Motov 2012-12-20 14:35:49 -05:00
parent 08b026d060
commit fcdc36977c
2 changed files with 25 additions and 0 deletions

View File

@ -96,6 +96,7 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
out.writeBoolean(true);
response.writeTo(out);
} else {
out.writeBoolean(false);
out.writeString(failureMessage);
}
}

View File

@ -21,12 +21,14 @@ package org.elasticsearch.test.integration.search.basic;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.search.MultiSearchResponse;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Unicode;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@ -369,6 +371,28 @@ public class TransportTwoNodesSearchTests extends AbstractNodesTests {
logger.info("Done Testing failed search");
}
@Test
public void testFailedMultiSearchWithWrongQuery() throws Exception {
logger.info("Start Testing failed multi search with a wrong query");
MultiSearchResponse response = client.prepareMultiSearch()
// Add custom score query with missing script
.add(client.prepareSearch("test").setQuery(QueryBuilders.customScoreQuery(QueryBuilders.termQuery("nid", 1))))
.add(client.prepareSearch("test").setQuery(QueryBuilders.termQuery("nid", 2)))
.add(client.prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()))
.execute().actionGet();
assertThat(response.responses().length, equalTo(3));
assertThat(response.responses()[0].failureMessage(), notNullValue());
assertThat(response.responses()[1].failureMessage(), nullValue());
assertThat(response.responses()[1].getResponse().hits().hits().length, equalTo(1));
assertThat(response.responses()[2].failureMessage(), nullValue());
assertThat(response.responses()[2].getResponse().hits().hits().length, equalTo(10));
logger.info("Done Testing failed search");
}
private void index(Client client, String id, String nameValue, int age) throws IOException {
client.index(Requests.indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet();
}