Improved alias support in the percolate api

* Changed the response to include the alias as part of each match.
* Added `percolate_format=ids` query string option to just serialize the ids in the rest response.
* Added support for multiple indices in the percolate api.

Closes #3420
This commit is contained in:
Martijn van Groningen 2013-08-01 10:42:14 +02:00
parent 5cd01461f6
commit 56227cc141
13 changed files with 365 additions and 183 deletions

View File

@ -61,8 +61,8 @@ public class PercolateRequest extends BroadcastOperationRequest<PercolateRequest
PercolateRequest() { PercolateRequest() {
} }
public PercolateRequest(String index, String documentType) { public PercolateRequest(String[] indices, String documentType) {
super(new String[]{index}); super(indices);
this.documentType = documentType; this.documentType = documentType;
} }

View File

@ -40,22 +40,10 @@ public class PercolateRequestBuilder extends BroadcastOperationRequestBuilder<Pe
private PercolateSourceBuilder sourceBuilder; private PercolateSourceBuilder sourceBuilder;
public PercolateRequestBuilder(Client client, String index, String type) { public PercolateRequestBuilder(Client client) {
super((InternalClient) client, new PercolateRequest(index, type));
}
PercolateRequestBuilder(Client client) {
super((InternalClient) client, new PercolateRequest()); super((InternalClient) client, new PercolateRequest());
} }
/**
* Sets the index to percolate the document against.
*/
public PercolateRequestBuilder setIndex(String index) {
request.indices(index);
return this;
}
/** /**
* Sets the type of the document to percolate. * Sets the type of the document to percolate.
*/ */

View File

@ -23,6 +23,7 @@ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
@ -34,12 +35,12 @@ import java.util.List;
/** /**
* *
*/ */
public class PercolateResponse extends BroadcastOperationResponse implements Iterable<Text> { public class PercolateResponse extends BroadcastOperationResponse implements Iterable<PercolateResponse.Match> {
private long tookInMillis; private long tookInMillis;
private Text[] matches; private Match[] matches;
public PercolateResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures, Text[] matches, long tookInMillis) { public PercolateResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures, Match[] matches, long tookInMillis) {
super(totalShards, successfulShards, failedShards, shardFailures); super(totalShards, successfulShards, failedShards, shardFailures);
this.tookInMillis = tookInMillis; this.tookInMillis = tookInMillis;
this.matches = matches; this.matches = matches;
@ -53,7 +54,7 @@ public class PercolateResponse extends BroadcastOperationResponse implements Ite
PercolateResponse() { PercolateResponse() {
} }
public PercolateResponse(Text[] matches) { public PercolateResponse(Match[] matches) {
this.matches = matches; this.matches = matches;
} }
@ -71,12 +72,12 @@ public class PercolateResponse extends BroadcastOperationResponse implements Ite
return tookInMillis; return tookInMillis;
} }
public Text[] getMatches() { public Match[] getMatches() {
return this.matches; return this.matches;
} }
@Override @Override
public Iterator<Text> iterator() { public Iterator<Match> iterator() {
return Arrays.asList(matches).iterator(); return Arrays.asList(matches).iterator();
} }
@ -84,13 +85,63 @@ public class PercolateResponse extends BroadcastOperationResponse implements Ite
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
tookInMillis = in.readVLong(); tookInMillis = in.readVLong();
matches = in.readTextArray(); int size = in.readVInt();
matches = new Match[size];
for (int i = 0; i < size; i++) {
matches[i] = new Match();
matches[i].readFrom(in);
}
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeVLong(tookInMillis); out.writeVLong(tookInMillis);
out.writeTextArray(matches); out.writeVInt(matches.length);
for (Match match : matches) {
match.writeTo(out);
}
}
public static class Match implements Streamable {
private Text id;
private Text index;
public Match(Text id, Text index) {
this.id = id;
this.index = index;
}
Match() {
}
public Text id() {
return id;
}
public Text index() {
return index;
}
public Text getId() {
return id;
}
public Text getIndex() {
return index;
}
@Override
public void readFrom(StreamInput in) throws IOException {
id = in.readText();
index = in.readText();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeText(id);
out.writeText(index);
}
} }
} }

View File

@ -36,6 +36,7 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.StringText;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.index.engine.DocumentMissingException;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
@ -44,6 +45,7 @@ import org.elasticsearch.percolator.PercolatorService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -124,7 +126,7 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
int successfulShards = 0; int successfulShards = 0;
int failedShards = 0; int failedShards = 0;
List<Text[]> shardResults = null; List<PercolateShardResponse> shardResults = null;
List<ShardOperationFailedException> shardFailures = null; List<ShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.length(); i++) { for (int i = 0; i < shardsResponses.length(); i++) {
@ -142,7 +144,7 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
if (shardResults == null) { if (shardResults == null) {
shardResults = newArrayList(); shardResults = newArrayList();
} }
shardResults.add(percolateShardResponse.matches()); shardResults.add(percolateShardResponse);
successfulShards++; successfulShards++;
} }
} }
@ -153,17 +155,21 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
} }
int size = 0; int size = 0;
for (Text[] shardResult : shardResults) { for (PercolateShardResponse response : shardResults) {
size += shardResult.length; size += response.matches().length;
} }
Text[] finalMatches = new Text[size];
int offset = 0; List<PercolateResponse.Match> finalMatches = new ArrayList<PercolateResponse.Match>(size);
for (Text[] shardResult : shardResults) { for (PercolateShardResponse response : shardResults) {
System.arraycopy(shardResult, 0, finalMatches, offset, shardResult.length); Text index = new StringText(response.getIndex());
offset += shardResult.length; for (Text id : response.matches()) {
finalMatches.add(new PercolateResponse.Match(id, index));
} }
assert size == offset; }
return new PercolateResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures, finalMatches, tookInMillis);
return new PercolateResponse(
shardsResponses.length(), successfulShards, failedShards, shardFailures, finalMatches.toArray(new PercolateResponse.Match[size]), tookInMillis
);
} }
@Override @Override

View File

@ -41,9 +41,6 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.mlt.MoreLikeThisRequest; import org.elasticsearch.action.mlt.MoreLikeThisRequest;
import org.elasticsearch.action.mlt.MoreLikeThisRequestBuilder; import org.elasticsearch.action.mlt.MoreLikeThisRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorRequest;
import org.elasticsearch.action.termvector.TermVectorRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorResponse;
import org.elasticsearch.action.percolate.PercolateRequest; import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateRequestBuilder; import org.elasticsearch.action.percolate.PercolateRequestBuilder;
import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.action.percolate.PercolateResponse;
@ -51,6 +48,9 @@ import org.elasticsearch.action.search.*;
import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestRequest;
import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.suggest.SuggestResponse; import org.elasticsearch.action.suggest.SuggestResponse;
import org.elasticsearch.action.termvector.TermVectorRequest;
import org.elasticsearch.action.termvector.TermVectorRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorResponse;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.action.update.UpdateResponse;
@ -485,11 +485,8 @@ public interface Client {
/** /**
* Percolates a request returning the matches documents. * Percolates a request returning the matches documents.
*
* @param index The index to percolate the doc
* @param type The type of the doc
*/ */
PercolateRequestBuilder preparePercolate(String index, String type); PercolateRequestBuilder preparePercolate();
/** /**
* Computes a score explanation for the specified request. * Computes a score explanation for the specified request.

View File

@ -48,10 +48,6 @@ import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.mlt.MoreLikeThisAction; import org.elasticsearch.action.mlt.MoreLikeThisAction;
import org.elasticsearch.action.mlt.MoreLikeThisRequest; import org.elasticsearch.action.mlt.MoreLikeThisRequest;
import org.elasticsearch.action.mlt.MoreLikeThisRequestBuilder; import org.elasticsearch.action.mlt.MoreLikeThisRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorAction;
import org.elasticsearch.action.termvector.TermVectorRequest;
import org.elasticsearch.action.termvector.TermVectorRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorResponse;
import org.elasticsearch.action.percolate.PercolateAction; import org.elasticsearch.action.percolate.PercolateAction;
import org.elasticsearch.action.percolate.PercolateRequest; import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateRequestBuilder; import org.elasticsearch.action.percolate.PercolateRequestBuilder;
@ -61,6 +57,10 @@ import org.elasticsearch.action.suggest.SuggestAction;
import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestRequest;
import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.suggest.SuggestResponse; import org.elasticsearch.action.suggest.SuggestResponse;
import org.elasticsearch.action.termvector.TermVectorAction;
import org.elasticsearch.action.termvector.TermVectorRequest;
import org.elasticsearch.action.termvector.TermVectorRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorResponse;
import org.elasticsearch.action.update.UpdateAction; import org.elasticsearch.action.update.UpdateAction;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder;
@ -324,8 +324,8 @@ public abstract class AbstractClient implements InternalClient {
} }
@Override @Override
public PercolateRequestBuilder preparePercolate(String index, String type) { public PercolateRequestBuilder preparePercolate() {
return new PercolateRequestBuilder(this, index, type); return new PercolateRequestBuilder(this);
} }
@Override @Override

View File

@ -24,10 +24,10 @@ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.percolate.PercolateRequest; import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.index.VersionType; import org.elasticsearch.index.VersionType;
@ -57,16 +57,19 @@ public class RestPercolateAction extends BaseRestHandler {
@Override @Override
public void handleRequest(RestRequest restRequest, RestChannel restChannel) { public void handleRequest(RestRequest restRequest, RestChannel restChannel) {
String index = restRequest.param("index"); String[] indices = RestActions.splitIndices(restRequest.param("index"));
String type = restRequest.param("type"); String type = restRequest.param("type");
PercolateRequest percolateRequest = new PercolateRequest(index, type); PercolateRequest percolateRequest = new PercolateRequest(indices, type);
percolateRequest.routing(restRequest.param("routing")); percolateRequest.routing(restRequest.param("routing"));
percolateRequest.preference(restRequest.param("preference")); percolateRequest.preference(restRequest.param("preference"));
percolateRequest.source(restRequest.content(), restRequest.contentUnsafe()); percolateRequest.source(restRequest.content(), restRequest.contentUnsafe());
percolateRequest.routing(restRequest.param("routing")); percolateRequest.routing(restRequest.param("routing"));
percolateRequest.preference(restRequest.param("preference")); percolateRequest.preference(restRequest.param("preference"));
if (restRequest.hasParam("ignore_indices")) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString(restRequest.param("ignore_indices")));
}
executePercolate(percolateRequest, restRequest, restChannel); executePercolate(percolateRequest, restRequest, restChannel);
} }
@ -100,8 +103,18 @@ public class RestPercolateAction extends BaseRestHandler {
builder.endObject(); builder.endObject();
builder.startArray(Fields.MATCHES); builder.startArray(Fields.MATCHES);
for (Text match : response) { boolean justIds = "ids".equals(restRequest.param("percolate_format"));
builder.value(match); if (justIds) {
for (PercolateResponse.Match match : response) {
builder.value(match.id());
}
} else {
for (PercolateResponse.Match match : response) {
builder.startObject();
builder.field(Fields._INDEX, match.getIndex());
builder.field(Fields._ID, match.getId());
builder.endObject();
}
} }
builder.endArray(); builder.endArray();
@ -141,7 +154,7 @@ public class RestPercolateAction extends BaseRestHandler {
getRequest.versionType(VersionType.fromString(restRequest.param("version_type"), getRequest.versionType())); getRequest.versionType(VersionType.fromString(restRequest.param("version_type"), getRequest.versionType()));
PercolateRequest percolateRequest = new PercolateRequest( PercolateRequest percolateRequest = new PercolateRequest(
restRequest.param("percolate_index", index), RestActions.splitIndices(restRequest.param("percolate_index", index)),
restRequest.param("percolate_type", type) restRequest.param("percolate_type", type)
); );
percolateRequest.getRequest(getRequest); percolateRequest.getRequest(getRequest);
@ -152,6 +165,9 @@ public class RestPercolateAction extends BaseRestHandler {
percolateRequest.routing(restRequest.param("percolate_routing")); percolateRequest.routing(restRequest.param("percolate_routing"));
percolateRequest.preference(restRequest.param("percolate_preference")); percolateRequest.preference(restRequest.param("percolate_preference"));
if (restRequest.hasParam("ignore_indices")) {
percolateRequest.ignoreIndices(IgnoreIndices.fromString(restRequest.param("ignore_indices")));
}
executePercolate(percolateRequest, restRequest, restChannel); executePercolate(percolateRequest, restRequest, restChannel);
} }
@ -169,5 +185,7 @@ public class RestPercolateAction extends BaseRestHandler {
static final XContentBuilderString REASON = new XContentBuilderString("reason"); static final XContentBuilderString REASON = new XContentBuilderString("reason");
static final XContentBuilderString TOOK = new XContentBuilderString("took"); static final XContentBuilderString TOOK = new XContentBuilderString("took");
static final XContentBuilderString MATCHES = new XContentBuilderString("matches"); static final XContentBuilderString MATCHES = new XContentBuilderString("matches");
static final XContentBuilderString _INDEX = new XContentBuilderString("_index");
static final XContentBuilderString _ID = new XContentBuilderString("_id");
} }
} }

View File

@ -113,7 +113,8 @@ public class PercolatorStressBenchmark {
source = source(Integer.toString(i), number); source = source(Integer.toString(i), number);
expectedMatches = 1; expectedMatches = 1;
} }
PercolateResponse percolate = client.preparePercolate("test", "type1") PercolateResponse percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(source) .setSource(source)
.execute().actionGet(); .execute().actionGet();
if (percolate.getMatches().length != expectedMatches) { if (percolate.getMatches().length != expectedMatches) {

View File

@ -88,7 +88,9 @@ public class NoMasterNodeTests extends AbstractNodesTests {
try { try {
PercolateSourceBuilder percolateSource = new PercolateSourceBuilder(); PercolateSourceBuilder percolateSource = new PercolateSourceBuilder();
percolateSource.percolateDocument().setDoc(new HashMap()); percolateSource.percolateDocument().setDoc(new HashMap());
node.client().preparePercolate("test", "type1").setSource(percolateSource).execute().actionGet(); node.client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(percolateSource).execute().actionGet();
assert false; assert false;
} catch (ClusterBlockException e) { } catch (ClusterBlockException e) {
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE)); assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));

View File

@ -133,20 +133,23 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
} }
PercolateResponse percolate; PercolateResponse percolate;
if (count % 3 == 0) { if (count % 3 == 0) {
percolate = client().preparePercolate("index", "type").setSource(bothFields) percolate = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(bothFields)
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(2)); assertThat(percolate.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContainingInAnyOrder("test1", "test2")); assertThat(convertFromTextArray(percolate.getMatches(), "index"), arrayContainingInAnyOrder("test1", "test2"));
} else if (count % 3 == 1) { } else if (count % 3 == 1) {
percolate = client().preparePercolate("index", "type").setSource(onlyField2) percolate = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(onlyField2)
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("test1")); assertThat(convertFromTextArray(percolate.getMatches(), "index"), arrayContaining("test1"));
} else { } else {
percolate = client().preparePercolate("index", "type").setSource(onlyField1) percolate = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(onlyField1)
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("test2")); assertThat(convertFromTextArray(percolate.getMatches(), "index"), arrayContaining("test2"));
} }
} }
@ -272,7 +275,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
switch (x) { switch (x) {
case 0: case 0:
atLeastExpected = type1.get(); atLeastExpected = type1.get();
response = client().preparePercolate("index", "type") response = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(onlyField1Doc).execute().actionGet(); .setSource(onlyField1Doc).execute().actionGet();
assertThat(response.getShardFailures(), emptyArray()); assertThat(response.getShardFailures(), emptyArray());
assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards())); assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards()));
@ -280,7 +283,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
break; break;
case 1: case 1:
atLeastExpected = type2.get(); atLeastExpected = type2.get();
response = client().preparePercolate("index", "type") response = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(onlyField2Doc).execute().actionGet(); .setSource(onlyField2Doc).execute().actionGet();
assertThat(response.getShardFailures(), emptyArray()); assertThat(response.getShardFailures(), emptyArray());
assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards())); assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards()));
@ -288,7 +291,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
break; break;
case 2: case 2:
atLeastExpected = type3.get(); atLeastExpected = type3.get();
response = client().preparePercolate("index", "type") response = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(field1AndField2Doc).execute().actionGet(); .setSource(field1AndField2Doc).execute().actionGet();
assertThat(response.getShardFailures(), emptyArray()); assertThat(response.getShardFailures(), emptyArray());
assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards())); assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards()));
@ -398,7 +401,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
break; break;
} }
int atLeastExpected = liveIds.size(); int atLeastExpected = liveIds.size();
PercolateResponse response = client().preparePercolate("index", "type") PercolateResponse response = client().preparePercolate().setIndices("index").setDocumentType("type")
.setSource(percolateDoc).execute().actionGet(); .setSource(percolateDoc).execute().actionGet();
assertThat(response.getShardFailures(), emptyArray()); assertThat(response.getShardFailures(), emptyArray());
assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards())); assertThat(response.getSuccessfulShards(), equalTo(response.getTotalShards()));

View File

@ -84,7 +84,9 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
PercolateResponse percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") PercolateResponse percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject()) .endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -102,7 +104,9 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject()) .endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -133,7 +137,9 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l)); assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
PercolateResponse percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") PercolateResponse percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject()) .endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -162,7 +168,9 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l)); assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject()) .endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -179,7 +187,9 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l)); assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") percolate = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject()) .endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -220,11 +230,12 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
} }
logger.info("--> Percolate doc with field1=95"); logger.info("--> Percolate doc with field1=95");
PercolateResponse response = client.preparePercolate("test", "type1") PercolateResponse response = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", 95).endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", 95).endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(6)); assertThat(response.getMatches(), arrayWithSize(6));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("95", "96", "97", "98", "99", "100")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("95", "96", "97", "98", "99", "100"));
logger.info("--> Close and open index to trigger percolate queries loading..."); logger.info("--> Close and open index to trigger percolate queries loading...");
client.admin().indices().prepareClose("test").execute().actionGet(); client.admin().indices().prepareClose("test").execute().actionGet();
@ -233,10 +244,11 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
ensureGreen(client); ensureGreen(client);
logger.info("--> Percolate doc with field1=100"); logger.info("--> Percolate doc with field1=100");
response = client.preparePercolate("test", "type1") response = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", 100).endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", 100).endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(response.getMatches()[0].string(), equalTo("100")); assertThat(response.getMatches()[0].id().string(), equalTo("100"));
} }
} }

View File

@ -21,15 +21,17 @@ package org.elasticsearch.test.integration.percolator;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.ImmutableSettings.Builder; import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.index.engine.DocumentMissingException;
@ -82,42 +84,47 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().admin().indices().prepareRefresh("test").execute().actionGet(); client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> Percolate doc with field1=b"); logger.info("--> Percolate doc with field1=b");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject())) .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "4"));
logger.info("--> Percolate doc with field1=c"); logger.info("--> Percolate doc with field1=c");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(yamlBuilder().startObject().field("field1", "c").endObject())) .setPercolateDoc(docBuilder().setDoc(yamlBuilder().startObject().field("field1", "c").endObject()))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("2", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("2", "4"));
logger.info("--> Percolate doc with field1=b c"); logger.info("--> Percolate doc with field1=b c");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(smileBuilder().startObject().field("field1", "b c").endObject())) .setPercolateDoc(docBuilder().setDoc(smileBuilder().startObject().field("field1", "b c").endObject()))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(4)); assertThat(response.getMatches(), arrayWithSize(4));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "2", "3", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "2", "3", "4"));
logger.info("--> Percolate doc with field1=d"); logger.info("--> Percolate doc with field1=d");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "d").endObject())) .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "d").endObject()))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("4"));
logger.info("--> Search dummy doc, percolate queries must not be included"); logger.info("--> Search dummy doc, percolate queries must not be included");
SearchResponse searchResponse = client().prepareSearch("test").execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test", "test").execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); assertThat(searchResponse.getHits().totalHits(), equalTo(1L));
assertThat(searchResponse.getHits().getAt(0).type(), equalTo("type")); assertThat(searchResponse.getHits().getAt(0).type(), equalTo("type"));
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1")); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
logger.info("--> Percolate non existing doc"); logger.info("--> Percolate non existing doc");
try { try {
client().preparePercolate("test", "type") client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("5")) .setGetRequest(Requests.getRequest("test").type("type").id("5"))
.execute().actionGet(); .execute().actionGet();
fail("Exception should have been thrown"); fail("Exception should have been thrown");
@ -152,7 +159,8 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.field("field2", "value") .field("field2", "value")
.endObject().endObject().endObject(); .endObject().endObject().endObject();
PercolateResponse response = client().preparePercolate("index", "type1").setSource(doc) PercolateResponse response = client().preparePercolate().setSource(doc)
.setIndices("test").setDocumentType("type1")
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), emptyArray()); assertThat(response.getMatches(), emptyArray());
@ -161,30 +169,37 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject()) .setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject())
.execute().actionGet(); .execute().actionGet();
response = client().preparePercolate("test", "type1").setSource(doc).execute().actionGet(); response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(doc).execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("test1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
response = client().preparePercolate("test", "type1").setSource(docWithType).execute().actionGet(); response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(docWithType).execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("test1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
// add second query... // add second query...
client().prepareIndex("test", "_percolator", "test2") client().prepareIndex("test", "_percolator", "test2")
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject()) .setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
.execute().actionGet(); .execute().actionGet();
response = client().preparePercolate("test", "type1") response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(doc) .setSource(doc)
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("test1", "test2")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("test1", "test2"));
client().prepareDelete("test", "_percolator", "test2").execute().actionGet(); client().prepareDelete("test", "_percolator", "test2").execute().actionGet();
response = client().preparePercolate("test", "type1").setSource(doc).execute().actionGet(); response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(doc).execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("test1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
// add a range query (cached) // add a range query (cached)
// add a query // add a query
@ -196,9 +211,11 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
) )
.execute().actionGet(); .execute().actionGet();
response = client().preparePercolate("test", "type1").setSource(doc).execute().actionGet(); response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(doc).execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("test1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
} }
@Test @Test
@ -217,20 +234,23 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
} }
logger.info("--> Percolate doc with no routing"); logger.info("--> Percolate doc with no routing");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(100)); assertThat(response.getMatches(), arrayWithSize(100));
logger.info("--> Percolate doc with routing=0"); logger.info("--> Percolate doc with routing=0");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.setRouting("0") .setRouting("0")
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(50)); assertThat(response.getMatches(), arrayWithSize(50));
logger.info("--> Percolate doc with routing=1"); logger.info("--> Percolate doc with routing=1");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.setRouting("1") .setRouting("1")
.execute().actionGet(); .execute().actionGet();
@ -297,7 +317,9 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
PercolateResponse percolate = client().preparePercolate("test", "doc").setSource(jsonBuilder().startObject() PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("doc")
.setSource(jsonBuilder().startObject()
.startObject("doc").field("filingcategory", "s").endObject() .startObject("doc").field("filingcategory", "s").endObject()
.field("query", termQuery("source", "productizer")) .field("query", termQuery("source", "productizer"))
.endObject()) .endObject())
@ -306,31 +328,6 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
} }
@Test
public void registerPercolatorAndThenCreateAnIndex() throws Exception {
logger.info("--> register a query");
client().prepareIndex("my-percolate-index", "_percolator", "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
.endObject())
.setRefresh(true)
.execute().actionGet();
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
ensureGreen();
PercolateResponse percolate = client().preparePercolate("my-percolate-index", "type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject())
.execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1));
percolate = client().preparePercolate("my-percolate-index", "type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1));
}
@Test @Test
public void createIndexAndThenRegisterPercolator() throws Exception { public void createIndexAndThenRegisterPercolator() throws Exception {
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
@ -352,14 +349,16 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
PercolateResponse percolate = client().preparePercolate("test", "type1") PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
} }
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
PercolateResponse percolate = client().preparePercolate("test", "type1") PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setPreference("_local") .setPreference("_local")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -399,17 +398,19 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
PercolateResponse percolate = client().preparePercolate("test", "type1") PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("kuku")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
percolate = client().preparePercolate("test", "type1") percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("bubu")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("bubu"));
} }
@ -427,11 +428,12 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
PercolateResponse percolate = client().preparePercolate("test", "type1") PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value1").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("kuku")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
logger.info("--> register a query 2"); logger.info("--> register a query 2");
client().prepareIndex("test", "_percolator", "bubu") client().prepareIndex("test", "_percolator", "bubu")
@ -442,11 +444,12 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
percolate = client().preparePercolate("test", "type1") percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("bubu")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("bubu"));
logger.info("--> register a query 3"); logger.info("--> register a query 3");
client().prepareIndex("test", "_percolator", "susu") client().prepareIndex("test", "_percolator", "susu")
@ -457,17 +460,20 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
percolate = client().preparePercolate("test", "type1") percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject() .setSource(jsonBuilder().startObject().startObject("doc").startObject("type1").field("field1", "value2").endObject().endObject()
.field("query", termQuery("color", "red")).endObject()) .field("query", termQuery("color", "red")).endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("susu")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("susu"));
logger.info("--> deleting query 1"); logger.info("--> deleting query 1");
client().prepareDelete("test", "_percolator", "kuku").setRefresh(true).execute().actionGet(); client().prepareDelete("test", "_percolator", "kuku").setRefresh(true).execute().actionGet();
percolate = client().preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc").startObject("type1") percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject().startObject("doc").startObject("type1")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject().endObject()) .endObject().endObject().endObject())
.execute().actionGet(); .execute().actionGet();
@ -495,14 +501,15 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
.execute().actionGet(); .execute().actionGet();
logger.info("--> percolate a document"); logger.info("--> percolate a document");
PercolateResponse percolate = client().preparePercolate("test", "type1").setSource(jsonBuilder().startObject() PercolateResponse percolate = client().preparePercolate().setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder().startObject()
.startObject("doc").startObject("type1") .startObject("doc").startObject("type1")
.field("field1", "value1") .field("field1", "value1")
.endObject().endObject() .endObject().endObject()
.endObject()) .endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(percolate.getMatches(), arrayWithSize(1)); assertThat(percolate.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(percolate.getMatches()), arrayContaining("kuku")); assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
} }
@Test @Test
@ -517,11 +524,12 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().admin().indices().prepareRefresh("test").execute().actionGet(); client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> First percolate request"); logger.info("--> First percolate request");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("1"));
IndicesStatsResponse indicesResponse = client().admin().indices().prepareStats("test").execute().actionGet(); IndicesStatsResponse indicesResponse = client().admin().indices().prepareStats("test").execute().actionGet();
assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(5l)); // We have 5 partitions assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(5l)); // We have 5 partitions
@ -535,11 +543,12 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
assertThat(percolateCount, equalTo(5l)); // We have 5 partitions assertThat(percolateCount, equalTo(5l)); // We have 5 partitions
logger.info("--> Second percolate request"); logger.info("--> Second percolate request");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("1"));
indicesResponse = client().admin().indices().prepareStats().setPercolate(true).execute().actionGet(); indicesResponse = client().admin().indices().prepareStats().setPercolate(true).execute().actionGet();
assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(10l)); assertThat(indicesResponse.getTotal().getPercolate().getCount(), equalTo(10l));
@ -563,11 +572,12 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
} }
logger.info("--> {}th percolate request", counter); logger.info("--> {}th percolate request", counter);
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject()) .setSource(jsonBuilder().startObject().startObject("doc").field("field", "val").endObject().endObject())
.execute().actionGet(); .execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("1")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("1"));
} while (++counter <= 1000); } while (++counter <= 1000);
assertTrue("Something is off, we should have spent at least 1ms on percolating...", moreThanOneMs); assertTrue("Something is off, we should have spent at least 1ms on percolating...", moreThanOneMs);
@ -610,40 +620,44 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().admin().indices().prepareRefresh("test").execute().actionGet(); client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> Percolate existing doc with id 1"); logger.info("--> Percolate existing doc with id 1");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("1")) .setGetRequest(Requests.getRequest("test").type("type").id("1"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "4"));
logger.info("--> Percolate existing doc with id 2"); logger.info("--> Percolate existing doc with id 2");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("2")) .setGetRequest(Requests.getRequest("test").type("type").id("2"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("2", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("2", "4"));
logger.info("--> Percolate existing doc with id 3"); logger.info("--> Percolate existing doc with id 3");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("3")) .setGetRequest(Requests.getRequest("test").type("type").id("3"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(4)); assertThat(response.getMatches(), arrayWithSize(4));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "2", "3", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "2", "3", "4"));
logger.info("--> Percolate existing doc with id 4"); logger.info("--> Percolate existing doc with id 4");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("4")) .setGetRequest(Requests.getRequest("test").type("type").id("4"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("4"));
logger.info("--> Search normals docs, percolate queries must not be included"); logger.info("--> Search normals docs, percolate queries must not be included");
SearchResponse searchResponse = client().prepareSearch("test").execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").execute().actionGet();
@ -684,40 +698,44 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().admin().indices().prepareRefresh("test").execute().actionGet(); client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> Percolate existing doc with id 1"); logger.info("--> Percolate existing doc with id 1");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("1").routing("4")) .setGetRequest(Requests.getRequest("test").type("type").id("1").routing("4"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "4"));
logger.info("--> Percolate existing doc with id 2"); logger.info("--> Percolate existing doc with id 2");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("2").routing("3")) .setGetRequest(Requests.getRequest("test").type("type").id("2").routing("3"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("2", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("2", "4"));
logger.info("--> Percolate existing doc with id 3"); logger.info("--> Percolate existing doc with id 3");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("3").routing("2")) .setGetRequest(Requests.getRequest("test").type("type").id("3").routing("2"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(4)); assertThat(response.getMatches(), arrayWithSize(4));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("1", "2", "3", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1", "2", "3", "4"));
logger.info("--> Percolate existing doc with id 4"); logger.info("--> Percolate existing doc with id 4");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("4").routing("1")) .setGetRequest(Requests.getRequest("test").type("type").id("4").routing("1"))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(1)); assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("4"));
} }
@Test @Test
@ -731,7 +749,7 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().prepareIndex("test", "type", "3").setSource("field1", "b c").execute().actionGet(); client().prepareIndex("test", "type", "3").setSource("field1", "b c").execute().actionGet();
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet(); client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
logger.info("--> register a queries"); logger.info("--> registering queries");
client().prepareIndex("test", "_percolator", "1") client().prepareIndex("test", "_percolator", "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject()) .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet(); .execute().actionGet();
@ -750,17 +768,19 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().admin().indices().prepareRefresh("test").execute().actionGet(); client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> Percolate existing doc with id 2 and version 1"); logger.info("--> Percolate existing doc with id 2 and version 1");
PercolateResponse response = client().preparePercolate("test", "type") PercolateResponse response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("2").version(1l)) .setGetRequest(Requests.getRequest("test").type("type").id("2").version(1l))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("2", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("2", "4"));
logger.info("--> Percolate existing doc with id 2 and version 2"); logger.info("--> Percolate existing doc with id 2 and version 2");
try { try {
client().preparePercolate("test", "type") client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("2").version(2l)) .setGetRequest(Requests.getRequest("test").type("type").id("2").version(2l))
.execute().actionGet(); .execute().actionGet();
fail("Error should have been thrown"); fail("Error should have been thrown");
@ -771,22 +791,102 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
client().prepareIndex("test", "type", "2").setSource("field1", "c").execute().actionGet(); client().prepareIndex("test", "type", "2").setSource("field1", "c").execute().actionGet();
logger.info("--> Percolate existing doc with id 2 and version 2"); logger.info("--> Percolate existing doc with id 2 and version 2");
response = client().preparePercolate("test", "type") response = client().preparePercolate()
.setIndices("test").setDocumentType("type")
.setGetRequest(Requests.getRequest("test").type("type").id("2").version(2l)) .setGetRequest(Requests.getRequest("test").type("type").id("2").version(2l))
.execute().actionGet(); .execute().actionGet();
assertThat(response.getFailedShards(), equalTo(0)); assertThat(response.getFailedShards(), equalTo(0));
assertThat(response.getSuccessfulShards(), equalTo(5)); assertThat(response.getSuccessfulShards(), equalTo(5));
assertThat(response.getMatches(), arrayWithSize(2)); assertThat(response.getMatches(), arrayWithSize(2));
assertThat(convertFromTextArray(response.getMatches()), arrayContainingInAnyOrder("2", "4")); assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("2", "4"));
} }
public static String[] convertFromTextArray(Text[] texts) { @Test
if (texts.length == 0) { public void testPercolateMultipleIndicesAndAliases() throws Exception {
client().admin().indices().prepareCreate("test1")
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
.execute().actionGet();
client().admin().indices().prepareCreate("test2")
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
.execute().actionGet();
ensureGreen();
logger.info("--> registering queries");
for (int i = 1; i <= 10; i++) {
String index = i % 2 == 0 ? "test1" : "test2";
client().prepareIndex(index, "_percolator", Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
}
logger.info("--> Percolate doc to index test1");
PercolateResponse response = client().preparePercolate()
.setIndices("test1").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(5));
logger.info("--> Percolate doc to index test2");
response = client().preparePercolate()
.setIndices("test2").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(5));
logger.info("--> Percolate doc to index test1 and test2");
response = client().preparePercolate()
.setIndices("test1", "test2").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(10));
logger.info("--> Percolate doc to index test2 and test3, with ignore missing");
response = client().preparePercolate()
.setIndices("test1", "test3").setDocumentType("type")
.setIgnoreIndices(IgnoreIndices.MISSING)
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(5));
logger.info("--> Adding aliases");
IndicesAliasesResponse aliasesResponse = client().admin().indices().prepareAliases()
.addAlias("test1", "my-alias1")
.addAlias("test2", "my-alias1")
.addAlias("test2", "my-alias2")
.setTimeout(TimeValue.timeValueHours(10))
.execute().actionGet();
assertTrue(aliasesResponse.isAcknowledged());
logger.info("--> Percolate doc to my-alias1");
response = client().preparePercolate()
.setIndices("my-alias1").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(10));
for (PercolateResponse.Match match : response) {
assertThat(match.getIndex().string(), anyOf(equalTo("test1"), equalTo("test2")));
}
logger.info("--> Percolate doc to my-alias2");
response = client().preparePercolate()
.setIndices("my-alias2").setDocumentType("type")
.setSource(jsonBuilder().startObject().startObject("doc").field("field1", "value").endObject().endObject())
.execute().actionGet();
assertThat(response.getMatches(), arrayWithSize(5));
for (PercolateResponse.Match match : response) {
assertThat(match.getIndex().string(), equalTo("test2"));
}
}
public static String[] convertFromTextArray(PercolateResponse.Match[] matches, String index) {
if (matches.length == 0) {
return Strings.EMPTY_ARRAY; return Strings.EMPTY_ARRAY;
} }
String[] strings = new String[texts.length]; String[] strings = new String[matches.length];
for (int i = 0; i < texts.length; i++) { for (int i = 0; i < matches.length; i++) {
strings[i] = texts[i].string(); assert index.equals(matches[i].getIndex().string());
strings[i] = matches[i].id().string();
} }
return strings; return strings;
} }

View File

@ -60,14 +60,16 @@ public class TTLPercolatorTests extends AbstractNodesTests {
.endObject() .endObject()
).setRefresh(true).setTTL(ttl).execute().actionGet(); ).setRefresh(true).setTTL(ttl).execute().actionGet();
PercolateResponse percolateResponse = client.preparePercolate("test", "type1").setSource(jsonBuilder() PercolateResponse percolateResponse = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder()
.startObject() .startObject()
.startObject("doc") .startObject("doc")
.field("field1", "value1") .field("field1", "value1")
.endObject() .endObject()
.endObject() .endObject()
).execute().actionGet(); ).execute().actionGet();
assertThat(convertFromTextArray(percolateResponse.getMatches()), arrayContaining("kuku")); assertThat(convertFromTextArray(percolateResponse.getMatches(), "test"), arrayContaining("kuku"));
long timeSpent = System.currentTimeMillis() - now; long timeSpent = System.currentTimeMillis() - now;
long waitTime = ttl + purgeInterval - timeSpent; long waitTime = ttl + purgeInterval - timeSpent;
if (waitTime >= 0) { if (waitTime >= 0) {
@ -90,7 +92,9 @@ public class TTLPercolatorTests extends AbstractNodesTests {
} while (currentDeleteCount < 2); // TTL deletes one doc, but it is indexed in the primary shard and replica shard. } while (currentDeleteCount < 2); // TTL deletes one doc, but it is indexed in the primary shard and replica shard.
assertThat(currentDeleteCount, equalTo(2l)); assertThat(currentDeleteCount, equalTo(2l));
percolateResponse = client.preparePercolate("test", "type1").setSource(jsonBuilder() percolateResponse = client.preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(jsonBuilder()
.startObject() .startObject()
.startObject("doc") .startObject("doc")
.field("field1", "value1") .field("field1", "value1")