Skip to content

Commit

Permalink
Fix failure message serialization in MultiSearchResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
imotov committed Dec 22, 2012
1 parent 4501a78 commit 2a353e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -96,6 +96,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(true);
response.writeTo(out);
} else {
out.writeBoolean(false);
out.writeString(failureMessage);
}
}
Expand Down
Expand Up @@ -21,12 +21,14 @@

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;
Expand Down Expand Up @@ -369,6 +371,28 @@ public void testFailedSearchWithWrongFrom() throws Exception {
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();
}
Expand Down

0 comments on commit 2a353e7

Please sign in to comment.