Dist. Percolation: Use .percolator instead of _percolator for type name

Use .percolator as the internal (hidden) type name for percolators within the index. Seems nicer name to represent "hidden" types within an index.
closes #4090
This commit is contained in:
Shay Banon 2013-11-05 20:02:59 +01:00
parent af183a1619
commit 7c32269f4f
13 changed files with 139 additions and 143 deletions

View File

@ -14,7 +14,7 @@ documentation before reading this guide.
QueryBuilder qb = termQuery("content", "amazing");
//Index the query = register it in the percolator
client.prepareIndex("myIndexName", "_percolator", "myDesignatedQueryName")
client.prepareIndex("myIndexName", ".percolator", "myDesignatedQueryName")
.setSource(jsonBuilder()
.startObject()
.field("query", qb) // Register the query

View File

@ -22,7 +22,7 @@ Adding a query to the percolator:
[source,js]
--------------------------------------------------
curl -XPUT 'localhost:9200/my-index/_percolator/1' -d '{
curl -XPUT 'localhost:9200/my-index/.percolator/1' -d '{
"query" : {
"match" : {
"message" : "bonsai tree"
@ -69,7 +69,7 @@ The percolate api returns matches that refer to percolate queries that have matc
=== Indexing percolator queries
Percolate queries are stored as documents in a specific format and in an arbitrary index under a reserved type with the
name `_percolator`. The query itself is placed as is in a json objects under the top level field `query`.
name `.percolator`. The query itself is placed as is in a json objects under the top level field `query`.
[source,js]
--------------------------------------------------
@ -99,7 +99,7 @@ percolate documents by specific queries.
On top of this also a mapping type can be associated with the this query. This allows to control how certain queries
like range queries, shape filters and other query & filters that rely on mapping settings get constructed. This is
important since the percolate queries are indexed into the `_percolator` type, and the queries / filters that rely on
important since the percolate queries are indexed into the `.percolator` type, and the queries / filters that rely on
mapping settings would yield unexpected behaviour. Note by default field names do get resolved in a smart manner,
but in certain cases with multiple types this can lead to unexpected behaviour, so being explicit about it will help.
@ -122,15 +122,15 @@ but in certain cases with multiple types this can lead to unexpected behaviour,
In the above example the range query gets really parsed into a Lucene numeric range query, based on the settings for
the field `created_at` in the type `tweet`.
Just as with any other type, the `_percolator` type has a mapping, which you can configure via the mappings apis.
Just as with any other type, the `.percolator` type has a mapping, which you can configure via the mappings apis.
The default percolate mapping doesn't index the query field and only stores it.
Because `_percolate` is a type it also has a mapping. By default the following mapping is active:
Because `.percolate` is a type it also has a mapping. By default the following mapping is active:
[source,js]
--------------------------------------------------
{
"_percolator" : {
".percolator" : {
"properties" : {
"query" : {
"type" : "object",
@ -148,7 +148,7 @@ the following delete requests needs to be executed:
[source,js]
--------------------------------------------------
curl -XDELETE localhost:9200/my-index/_percolator/1
curl -XDELETE localhost:9200/my-index/.percolator/1
--------------------------------------------------
[float]
@ -157,7 +157,7 @@ curl -XDELETE localhost:9200/my-index/_percolator/1
The percolate api executes in a distributed manner, meaning it executes on all shards an index points to.
.Required options
* `index` - The index that contains the `_percolator` type. This can also be an alias.
* `index` - The index that contains the `.percolator` type. This can also be an alias.
* `type` - The type of the document to be percolated. The mapping of that type is used to parse document.
* `doc` - The actual document to percolate. Unlike the other two options this needs to be specified in the request body. Note this isn't required when percolating an existing document.
@ -416,9 +416,9 @@ were specified. In case a percolate request failed, the item response is substit
[float]
=== How it works under the hood
When indexing a document that contains a query in an index and the `_percolator` type the query part of the documents gets
When indexing a document that contains a query in an index and the `.percolator` type the query part of the documents gets
parsed into a Lucene query and is kept in memory until that percolator document is removed or the index containing the
`_percolator` type get removed. So all the active percolator queries are kept in memory.
`.percolator` type get removed. So all the active percolator queries are kept in memory.
At percolate time the document specified in the request gets parsed into a Lucene document and is stored in a in-memory
Lucene index. This in-memory index can just hold this one document and it is optimized for that. Then all the queries

View File

@ -444,7 +444,7 @@ public class MetaDataMappingService extends AbstractComponent {
} else if (!mappingType.equals(newMappers.values().iterator().next().type())) {
throw new InvalidTypeNameException("Type name provided does not match type name within mapping definition");
}
if (!MapperService.DEFAULT_MAPPING.equals(mappingType) && !PercolatorService.Constants.TYPE_NAME.equals(mappingType) && mappingType.charAt(0) == '_') {
if (!MapperService.DEFAULT_MAPPING.equals(mappingType) && !PercolatorService.TYPE_NAME.equals(mappingType) && mappingType.charAt(0) == '_') {
throw new InvalidTypeNameException("Document mapping type name can't start with '_'");
}

View File

@ -173,7 +173,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
}
} else {
defaultPercolatorMappingSource = "{\n" +
" \"_default_\":{\n" +
//" \"" + PercolatorService.TYPE_NAME + "\":{\n" +
" \"" + "_default_" + "\":{\n" +
" \"_id\" : {\"index\": \"not_analyzed\"}," +
" \"properties\" : {\n" +
" \"query\" : {\n" +
@ -246,7 +247,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
if (mapper.type().length() == 0) {
throw new InvalidTypeNameException("mapping type name is empty");
}
if (mapper.type().charAt(0) == '_' && !PercolatorService.Constants.TYPE_NAME.equals(mapper.type())) {
if (mapper.type().charAt(0) == '_' && !PercolatorService.TYPE_NAME.equals(mapper.type())) {
throw new InvalidTypeNameException("mapping type name [" + mapper.type() + "] can't start with '_'");
}
if (mapper.type().contains("#")) {
@ -363,8 +364,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
public DocumentMapper parse(String mappingType, String mappingSource, boolean applyDefault) throws MapperParsingException {
String defaultMappingSource;
if (PercolatorService.Constants.TYPE_NAME.equals(mappingType)) {
defaultMappingSource = defaultPercolatorMappingSource;
if (PercolatorService.TYPE_NAME.equals(mappingType)) {
defaultMappingSource = this.defaultPercolatorMappingSource;
} else {
defaultMappingSource = this.defaultMappingSource;
}
@ -407,10 +408,10 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
*/
@Nullable
public Filter searchFilter(String... types) {
boolean filterPercolateType = hasMapping(PercolatorService.Constants.TYPE_NAME);
boolean filterPercolateType = hasMapping(PercolatorService.TYPE_NAME);
if (types != null && filterPercolateType) {
for (String type : types) {
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
if (PercolatorService.TYPE_NAME.equals(type)) {
filterPercolateType = false;
break;
}
@ -418,7 +419,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
}
Filter excludePercolatorType = null;
if (filterPercolateType) {
excludePercolatorType = new NotFilter(documentMapper(PercolatorService.Constants.TYPE_NAME).typeFilter());
excludePercolatorType = new NotFilter(documentMapper(PercolatorService.TYPE_NAME).typeFilter());
}
if (types == null || types.length == 0) {

View File

@ -37,8 +37,8 @@ import java.util.Map;
import java.util.concurrent.ConcurrentMap;
/**
* Each shard will have a percolator registry even if there isn't a _percolator document type in the index.
* For shards with indices that have no _percolator document type, this will hold no percolate queries.
* Each shard will have a percolator registry even if there isn't a {@link PercolatorService#TYPE_NAME} document type in the index.
* For shards with indices that have no {@link PercolatorService#TYPE_NAME} document type, this will hold no percolate queries.
* <p/>
* Once a document type has been created, the real-time percolator will start to listen to write events and update the
* this registry with queries in real time.
@ -116,7 +116,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
}
public void removePercolateQuery(String idAsString) {
HashedBytesRef id =new HashedBytesRef(idAsString) ;
HashedBytesRef id = new HashedBytesRef(idAsString);
Query query = percolateQueries.remove(id);
if (query != null) {
shardPercolateService.removedQuery(id, query);
@ -194,14 +194,14 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public void created(String type) {
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
if (PercolatorService.TYPE_NAME.equals(type)) {
enableRealTimePercolator();
}
}
@Override
public void removed(String type) {
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
if (PercolatorService.TYPE_NAME.equals(type)) {
disableRealTimePercolator();
clear();
}
@ -231,7 +231,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
private boolean hasPercolatorType(IndexShard indexShard) {
ShardId otherShardId = indexShard.shardId();
return shardId.equals(otherShardId) && mapperService.hasMapping(PercolatorService.Constants.TYPE_NAME);
return shardId.equals(otherShardId) && mapperService.hasMapping(PercolatorService.TYPE_NAME);
}
private void loadQueries(IndexShard shard) {
@ -241,7 +241,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
try {
Query query = new XConstantScoreQuery(
indexCache.filter().cache(
new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.Constants.TYPE_NAME))
new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.TYPE_NAME))
)
);
QueriesLoaderCollector queryCollector = new QueriesLoaderCollector(PercolatorQueriesRegistry.this, logger, indexFieldDataService);
@ -266,7 +266,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public Engine.Create preCreate(Engine.Create create) {
// validate the query here, before we index
if (PercolatorService.Constants.TYPE_NAME.equals(create.type())) {
if (PercolatorService.TYPE_NAME.equals(create.type())) {
parsePercolatorDocument(create.id(), create.source());
}
return create;
@ -275,7 +275,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public void postCreateUnderLock(Engine.Create create) {
// add the query under a doc lock
if (PercolatorService.Constants.TYPE_NAME.equals(create.type())) {
if (PercolatorService.TYPE_NAME.equals(create.type())) {
addPercolateQuery(create.id(), create.source());
}
}
@ -283,7 +283,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public Engine.Index preIndex(Engine.Index index) {
// validate the query here, before we index
if (PercolatorService.Constants.TYPE_NAME.equals(index.type())) {
if (PercolatorService.TYPE_NAME.equals(index.type())) {
parsePercolatorDocument(index.id(), index.source());
}
return index;
@ -292,7 +292,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public void postIndexUnderLock(Engine.Index index) {
// add the query under a doc lock
if (PercolatorService.Constants.TYPE_NAME.equals(index.type())) {
if (PercolatorService.TYPE_NAME.equals(index.type())) {
addPercolateQuery(index.id(), index.source());
}
}
@ -300,7 +300,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
@Override
public void postDeleteUnderLock(Engine.Delete delete) {
// remove the query under a lock
if (PercolatorService.Constants.TYPE_NAME.equals(delete.type())) {
if (PercolatorService.TYPE_NAME.equals(delete.type())) {
removePercolateQuery(delete.id());
}
}

View File

@ -73,10 +73,7 @@ import org.elasticsearch.index.query.ParsedQuery;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.percolator.QueryCollector.Count;
import org.elasticsearch.percolator.QueryCollector.Match;
import org.elasticsearch.percolator.QueryCollector.MatchAndScore;
import org.elasticsearch.percolator.QueryCollector.MatchAndSort;
import org.elasticsearch.percolator.QueryCollector.*;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.facet.Facet;
@ -100,6 +97,7 @@ import static org.elasticsearch.percolator.QueryCollector.*;
public class PercolatorService extends AbstractComponent {
public final static float NO_SCORE = Float.NEGATIVE_INFINITY;
public static final String TYPE_NAME = ".percolator";
private final CloseableThreadLocal<MemoryIndex> cache;
private final IndicesService indicesService;
@ -239,7 +237,7 @@ public class PercolatorService extends AbstractComponent {
// We switch types because this context needs to be in the context of the percolate queries in the shard and
// not the in memory percolate doc
String[] previousTypes = context.types();
context.types(new String[]{Constants.TYPE_NAME});
context.types(new String[]{TYPE_NAME});
SearchContext.setCurrent(context);
try {
parser = XContentFactory.xContent(source).createParser(source);
@ -746,7 +744,7 @@ public class PercolatorService extends AbstractComponent {
};
private void queryBasedPercolating(Engine.Searcher percolatorSearcher, PercolateContext context, QueryCollector percolateCollector) throws IOException {
Filter percolatorTypeFilter = context.indexService().mapperService().documentMapper(Constants.TYPE_NAME).typeFilter();
Filter percolatorTypeFilter = context.indexService().mapperService().documentMapper(TYPE_NAME).typeFilter();
percolatorTypeFilter = context.indexService().cache().filter().cache(percolatorTypeFilter);
FilteredQuery query = new FilteredQuery(context.percolateQuery(), percolatorTypeFilter);
percolatorSearcher.searcher().search(query, percolateCollector);
@ -806,12 +804,6 @@ public class PercolatorService extends AbstractComponent {
}
}
public static final class Constants {
public static final String TYPE_NAME = "_percolator";
}
private InternalFacets reduceFacets(List<PercolateShardResponse> shardResults) {
if (shardResults.size() == 1) {
return shardResults.get(0).facets();

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.StopWatch;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.node.Node;
import org.elasticsearch.percolator.PercolatorService;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
@ -83,7 +84,7 @@ public class PercolatorStressBenchmark {
// register queries
int i = 0;
for (; i < TERM_QUERIES; i++) {
client.prepareIndex("test", "_percolator", Integer.toString(i))
client.prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject()
.field("query", termQuery("name", "value"))
.endObject())
@ -92,7 +93,7 @@ public class PercolatorStressBenchmark {
int[] numbers = new int[RANGE_QUERIES];
for (; i < QUERIES; i++) {
client.prepareIndex("test", "_percolator", Integer.toString(i))
client.prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject()
.field("query", rangeQuery("numeric1").from(i).to(i))
.endObject())

View File

@ -80,10 +80,10 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
.field("field2", "value")
.endObject()).execute().actionGet();
client().prepareIndex("index", "_percolator", "test1")
client().prepareIndex("index", PercolatorService.TYPE_NAME, "test1")
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject())
.execute().actionGet();
client().prepareIndex("index", "_percolator", "test2")
client().prepareIndex("index", PercolatorService.TYPE_NAME, "test2")
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
.execute().actionGet();
@ -190,19 +190,19 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
IndexResponse response;
switch (x) {
case 0:
response = client().prepareIndex("index", "_percolator", id)
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
.setSource(onlyField1)
.execute().actionGet();
type1.incrementAndGet();
break;
case 1:
response = client().prepareIndex("index", "_percolator", id)
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
.setSource(onlyField2)
.execute().actionGet();
type2.incrementAndGet();
break;
case 2:
response = client().prepareIndex("index", "_percolator", id)
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
.setSource(field1And2)
.execute().actionGet();
type3.incrementAndGet();
@ -320,7 +320,8 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
try {
XContentBuilder doc = XContentFactory.jsonBuilder().startObject()
.field("query", termQuery("field1", "value")).endObject();
outer: while (run.get()) {
outer:
while (run.get()) {
semaphore.acquire();
try {
if (!liveIds.isEmpty() && getRandom().nextInt(100) < 19) {
@ -332,13 +333,13 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
id = Integer.toString(randomInt(idGen.get()));
} while (!liveIds.remove(id));
DeleteResponse response = client().prepareDelete("index", "_percolator", id)
DeleteResponse response = client().prepareDelete("index", PercolatorService.TYPE_NAME, id)
.execute().actionGet();
assertThat(response.getId(), equalTo(id));
assertThat("doc[" + id + "] should have been deleted, but isn't", response.isNotFound(), equalTo(false));
} else {
String id = Integer.toString(idGen.getAndIncrement());
IndexResponse response = client().prepareIndex("index", "_percolator", id)
IndexResponse response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
.setSource(doc)
.execute().actionGet();
liveIds.add(id);

View File

@ -43,19 +43,19 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
@ -125,7 +125,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
int numQueries = randomIntBetween(50, 100);
logger.info("--> register a queries");
for (int i = 0; i < numQueries; i++) {
client().prepareIndex("test", "_percolator", Integer.toString(i))
client().prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
}
@ -204,7 +204,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
int numQueries = randomIntBetween(50, 100);
logger.info("--> register a queries");
for (int i = 0; i < numQueries; i++) {
client().prepareIndex("test", "_percolator", Integer.toString(i))
client().prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
}
@ -265,7 +265,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
assertThat(response.items().length, equalTo(numPercolateRequest + 1));
assertThat(response.items()[numPercolateRequest].isFailure(), equalTo(false));
assertNoFailures(response.items()[numPercolateRequest].getResponse());
assertThat(response.items()[numPercolateRequest].getResponse().getCount(), equalTo((long ) numQueries));
assertThat(response.items()[numPercolateRequest].getResponse().getCount(), equalTo((long) numQueries));
assertThat(response.items()[numPercolateRequest].getResponse().getMatches().length, equalTo(numQueries));
}

View File

@ -57,7 +57,7 @@ public class PercolatorFacetsTests extends AbstractIntegrationTest {
String value = values[i % numUniqueQueries];
expectedCount[i % numUniqueQueries]++;
QueryBuilder queryBuilder = matchQuery("field1", value);
client().prepareIndex("test", "_percolator", Integer.toString(i))
client().prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", queryBuilder).field("field2", "b").endObject())
.execute().actionGet();
}
@ -92,9 +92,9 @@ public class PercolatorFacetsTests extends AbstractIntegrationTest {
assertThat(response.getFacets().facets().size(), equalTo(1));
assertThat(response.getFacets().facets().get(0).getName(), equalTo("a"));
assertThat(((TermsFacet)response.getFacets().facets().get(0)).getEntries().size(), equalTo(1));
assertThat(((TermsFacet)response.getFacets().facets().get(0)).getEntries().get(0).getCount(), equalTo(expectedCount[i % values.length]));
assertThat(((TermsFacet)response.getFacets().facets().get(0)).getEntries().get(0).getTerm().string(), equalTo("b"));
assertThat(((TermsFacet) response.getFacets().facets().get(0)).getEntries().size(), equalTo(1));
assertThat(((TermsFacet) response.getFacets().facets().get(0)).getEntries().get(0).getCount(), equalTo(expectedCount[i % values.length]));
assertThat(((TermsFacet) response.getFacets().facets().get(0)).getEntries().get(0).getTerm().string(), equalTo("b"));
}
}

View File

@ -75,19 +75,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -177,7 +177,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(response.getMatches(), emptyArray());
// add first query...
client().prepareIndex("test", "_percolator", "test1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "test1")
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject())
.execute().actionGet();
@ -194,7 +194,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
// add second query...
client().prepareIndex("test", "_percolator", "test2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "test2")
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
.execute().actionGet();
@ -206,7 +206,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("test1", "test2"));
client().prepareDelete("test", "_percolator", "test2").execute().actionGet();
client().prepareDelete("test", PercolatorService.TYPE_NAME, "test2").execute().actionGet();
response = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
.setSource(doc).execute().actionGet();
@ -215,7 +215,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
// add a range query (cached)
// add a query
client().prepareIndex("test1", "_percolator")
client().prepareIndex("test1", PercolatorService.TYPE_NAME)
.setSource(
XContentFactory.jsonBuilder().startObject().field("query",
constantScoreQuery(FilterBuilders.rangeFilter("field2").from("value").includeLower(true))
@ -239,7 +239,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
logger.info("--> register a queries");
for (int i = 1; i <= 100; i++) {
client().prepareIndex("test", "_percolator", Integer.toString(i))
client().prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.setRouting(Integer.toString(i % 2))
.execute().actionGet();
@ -276,7 +276,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
logger.info("--> register a query");
client().prepareIndex("my-queries-index", "_percolator", "kuku")
client().prepareIndex("my-queries-index", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -290,7 +290,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
logger.info("--> register a query");
client().prepareIndex("my-queries-index", "_percolator", "kuku")
client().prepareIndex("my-queries-index", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -321,7 +321,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject()
.field("source", "productizer")
.field("query", QueryBuilders.constantScoreQuery(QueryBuilders.queryString("filingcategory:s")))
@ -346,7 +346,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -355,7 +355,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
refresh();
CountResponse countResponse = client().prepareCount()
.setQuery(matchAllQuery()).setTypes("_percolator")
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
.execute().actionGet();
assertThat(countResponse.getCount(), equalTo(1l));
@ -382,7 +382,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().admin().indices().prepareDelete("test").execute().actionGet();
logger.info("--> make sure percolated queries for it have been deleted as well");
countResponse = client().prepareCount()
.setQuery(matchAllQuery()).setTypes("_percolator")
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
.execute().actionGet();
assertThat(countResponse.getCount(), equalTo(0l));
}
@ -393,7 +393,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query 1");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -402,7 +402,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
.execute().actionGet();
logger.info("--> register a query 2");
client().prepareIndex("test", "_percolator", "bubu")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "bubu")
.setSource(jsonBuilder().startObject()
.field("color", "green")
.field("query", termQuery("field1", "value2"))
@ -432,7 +432,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query 1");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -448,7 +448,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
logger.info("--> register a query 2");
client().prepareIndex("test", "_percolator", "bubu")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "bubu")
.setSource(jsonBuilder().startObject()
.field("color", "green")
.field("query", termQuery("field1", "value2"))
@ -464,7 +464,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("bubu"));
logger.info("--> register a query 3");
client().prepareIndex("test", "_percolator", "susu")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "susu")
.setSource(jsonBuilder().startObject()
.field("color", "red")
.field("query", termQuery("field1", "value2"))
@ -483,7 +483,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("susu"));
logger.info("--> deleting query 1");
client().prepareDelete("test", "_percolator", "kuku").setRefresh(true).execute().actionGet();
client().prepareDelete("test", PercolatorService.TYPE_NAME, "kuku").setRefresh(true).execute().actionGet();
percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
@ -507,7 +507,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("query", termQuery("field1", "value1"))
.endObject())
@ -532,7 +532,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
ensureGreen();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -620,19 +620,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -698,19 +698,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "4").setSource("field1", "d").setRouting("1").execute().actionGet();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -768,19 +768,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
logger.info("--> registering queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -832,7 +832,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
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))
client().prepareIndex(index, PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
}
@ -906,19 +906,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -978,19 +978,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
logger.info("--> register a queries");
client().prepareIndex("test", "_percolator", "1")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "2")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "3")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "_percolator", "4")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh("test").execute().actionGet();
@ -1044,10 +1044,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
int numLevels = randomIntBetween(1, 25);
long numQueriesPerLevel = randomIntBetween(10, 250);
long totalQueries = numLevels * numQueriesPerLevel;
logger.info("--> register " + totalQueries +" queries");
logger.info("--> register " + totalQueries + " queries");
for (int level = 1; level <= numLevels; level++) {
for (int query = 1; query <= numQueriesPerLevel; query++) {
client().prepareIndex("my-index", "_percolator", level + "-" + query)
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, level + "-" + query)
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", level).endObject())
.execute().actionGet();
}
@ -1145,10 +1145,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
Map<Integer, NavigableSet<Integer>> controlMap = new HashMap<Integer, NavigableSet<Integer>>();
long numQueries = randomIntBetween(100, 250);
logger.info("--> register " + numQueries +" queries");
logger.info("--> register " + numQueries + " queries");
for (int i = 0; i < numQueries; i++) {
int value = randomInt(10);
client().prepareIndex("my-index", "_percolator", Integer.toString(i))
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", i).field("field1", value).endObject())
.execute().actionGet();
if (!controlMap.containsKey(value)) {
@ -1231,10 +1231,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().admin().indices().prepareCreate("my-index").execute().actionGet();
ensureGreen();
client().prepareIndex("my-index", "_percolator", "1")
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 1).endObject())
.execute().actionGet();
client().prepareIndex("my-index", "_percolator", "2")
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 2).endObject())
.execute().actionGet();
refresh();
@ -1288,7 +1288,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
.execute().actionGet();
ensureGreen();
client().prepareIndex("my-index", "_percolator", "1")
client().prepareIndex("my-index", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 1).endObject())
.execute().actionGet();
@ -1323,19 +1323,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
}
logger.info("--> register a queries");
client.prepareIndex("test", "_percolator", "1")
client.prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "brown fox")).endObject())
.execute().actionGet();
client.prepareIndex("test", "_percolator", "2")
client.prepareIndex("test", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "lazy dog")).endObject())
.execute().actionGet();
client.prepareIndex("test", "_percolator", "3")
client.prepareIndex("test", PercolatorService.TYPE_NAME, "3")
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "jumps")).endObject())
.execute().actionGet();
client.prepareIndex("test", "_percolator", "4")
client.prepareIndex("test", PercolatorService.TYPE_NAME, "4")
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "dog")).endObject())
.execute().actionGet();
client.prepareIndex("test", "_percolator", "5")
client.prepareIndex("test", PercolatorService.TYPE_NAME, "5")
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "fox")).endObject())
.execute().actionGet();
@ -1469,10 +1469,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
client().admin().indices().prepareCreate("test2").execute().actionGet();
ensureGreen();
client().prepareIndex("test1", "_percolator", "1")
client().prepareIndex("test1", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().prepareIndex("test2", "_percolator", "1")
client().prepareIndex("test2", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
@ -1483,9 +1483,9 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertThat(response.getCount(), equalTo(2l));
CountDownLatch test1Latch = createCountDownLatch("test1");
CountDownLatch test2Latch =createCountDownLatch("test2");
CountDownLatch test2Latch = createCountDownLatch("test2");
client().admin().indices().prepareDeleteMapping("test1").setType("_percolator").execute().actionGet();
client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME).execute().actionGet();
test1Latch.await();
response = client().preparePercolate()
@ -1495,7 +1495,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
assertNoFailures(response);
assertThat(response.getCount(), equalTo(1l));
client().admin().indices().prepareDeleteMapping("test2").setType("_percolator").execute().actionGet();
client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME).execute().actionGet();
test2Latch.await();
// Percolate api should return 0 matches, because all _percolate types have been removed.

View File

@ -69,7 +69,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
).execute().actionGet();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -114,7 +114,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
.setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -122,7 +122,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
.setRefresh(true)
.execute().actionGet();
assertThat(client().prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
PercolateResponse percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
@ -140,7 +140,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
assertThat(client().prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
DeleteIndexResponse actionGet = client().admin().indices().prepareDelete("test").execute().actionGet();
assertThat(actionGet.isAcknowledged(), equalTo(true));
@ -149,7 +149,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
assertThat(client().prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
@ -160,7 +160,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
assertThat(percolate.getMatches(), emptyArray());
logger.info("--> register a query");
client().prepareIndex("test", "_percolator", "kuku")
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
.setSource(jsonBuilder().startObject()
.field("color", "blue")
.field("query", termQuery("field1", "value1"))
@ -168,7 +168,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
.setRefresh(true)
.execute().actionGet();
assertThat(client().prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
percolate = client().preparePercolate()
.setIndices("test").setDocumentType("type1")
@ -204,7 +204,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
logger.info("--> register a queries");
for (int i = 1; i <= 100; i++) {
client().prepareIndex("test", "_percolator", Integer.toString(i))
client().prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject()
.field("query", rangeQuery("field1").from(0).to(i))
// The type must be set now, because two fields with the same name exist in different types.
@ -278,7 +278,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
final int numQueries = randomIntBetween(50, 100);
logger.info("--> register a queries");
for (int i = 0; i < numQueries; i++) {
client.prepareIndex("test", "_percolator", Integer.toString(i))
client.prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
}

View File

@ -38,7 +38,7 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
client.admin().indices().prepareDelete().execute().actionGet();
ensureGreen();
String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator")
String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject(PercolatorService.TYPE_NAME)
.startObject("_ttl").field("enabled", true).endObject()
.startObject("_timestamp").field("enabled", true).endObject()
.endObject().endObject().string();
@ -50,14 +50,14 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
client.admin().indices().prepareCreate("test")
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
.addMapping("_percolator", precolatorMapping)
.addMapping(PercolatorService.TYPE_NAME, precolatorMapping)
.addMapping("type1", typeMapping)
.execute().actionGet();
ensureGreen();
long ttl = 1500;
long now = System.currentTimeMillis();
client.prepareIndex("test", "_percolator", "kuku").setSource(jsonBuilder()
client.prepareIndex("test", PercolatorService.TYPE_NAME, "kuku").setSource(jsonBuilder()
.startObject()
.startObject("query")
.startObject("term")
@ -84,7 +84,7 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
assertNoFailures(percolateResponse);
if (percolateResponse.getMatches().length == 0) {
// OK, ttl + purgeInterval has passed (slow machine or many other tests were running at the same time
GetResponse getResponse = client.prepareGet("test", "_percolator", "kuku").execute().actionGet();
GetResponse getResponse = client.prepareGet("test", PercolatorService.TYPE_NAME, "kuku").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(false));
response = client.admin().indices().prepareStats("test")
.clear().setIndexing(true)
@ -110,7 +110,8 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
.execute().actionGet();
// This returns the number of delete operations stats (not Lucene delete count)
currentDeleteCount = response.getIndices().get("test").getTotal().getIndexing().getTotal().getDeleteCount();
} 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));
percolateResponse = client.preparePercolate()