diff --git a/docs/java-api/percolate.asciidoc b/docs/java-api/percolate.asciidoc index a9d807ff852..f0187fd3394 100644 --- a/docs/java-api/percolate.asciidoc +++ b/docs/java-api/percolate.asciidoc @@ -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 diff --git a/docs/reference/search/percolate.asciidoc b/docs/reference/search/percolate.asciidoc index 59156f239cf..c06166cb725 100644 --- a/docs/reference/search/percolate.asciidoc +++ b/docs/reference/search/percolate.asciidoc @@ -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 diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 313519a7d8e..643808eafeb 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -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 '_'"); } diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 9db3a184af7..e10b72d8ffb 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -173,7 +173,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable * 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()); } } diff --git a/src/main/java/org/elasticsearch/percolator/PercolatorService.java b/src/main/java/org/elasticsearch/percolator/PercolatorService.java index cd207dae590..d3289c35854 100644 --- a/src/main/java/org/elasticsearch/percolator/PercolatorService.java +++ b/src/main/java/org/elasticsearch/percolator/PercolatorService.java @@ -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 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 shardResults) { if (shardResults.size() == 1) { return shardResults.get(0).facets(); diff --git a/src/test/java/org/elasticsearch/benchmark/percolator/PercolatorStressBenchmark.java b/src/test/java/org/elasticsearch/benchmark/percolator/PercolatorStressBenchmark.java index 8d9f7bebc11..9df3f2a6da4 100644 --- a/src/test/java/org/elasticsearch/benchmark/percolator/PercolatorStressBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/percolator/PercolatorStressBenchmark.java @@ -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()) diff --git a/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorTests.java index d2d1de6089e..18be0f32ed0 100644 --- a/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorTests.java @@ -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); diff --git a/src/test/java/org/elasticsearch/percolator/MultiPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/MultiPercolatorTests.java index 41a20824db7..85538e30be9 100644 --- a/src/test/java/org/elasticsearch/percolator/MultiPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/MultiPercolatorTests.java @@ -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(); @@ -91,7 +91,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest { assertThat(item.getResponse().getCount(), equalTo(2l)); assertThat(convertFromTextArray(item.getResponse().getMatches(), "test"), arrayContainingInAnyOrder("2", "4")); - item = response.getItems()[2]; + item = response.getItems()[2]; assertThat(item.errorMessage(), nullValue()); assertNoFailures(item.response()); assertThat(item.getResponse().getMatches(), arrayWithSize(4)); @@ -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(); } @@ -214,8 +214,8 @@ public class MultiPercolatorTests extends AbstractIntegrationTest { for (int i = 0; i < numPercolateRequest; i++) { builder.add( client().preparePercolate() - .setIndices("test").setDocumentType("type") - .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field", "a").endObject()))); + .setIndices("test").setDocumentType("type") + .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field", "a").endObject()))); } MultiPercolateResponse response = builder.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)); } diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorFacetsTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorFacetsTests.java index a357b70cd29..041379697fd 100644 --- a/src/test/java/org/elasticsearch/percolator/PercolatorFacetsTests.java +++ b/src/test/java/org/elasticsearch/percolator/PercolatorFacetsTests.java @@ -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")); } } diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java index 9781f9a66b6..0cca5c05b78 100644 --- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java @@ -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> controlMap = new HashMap>(); 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. diff --git a/src/test/java/org/elasticsearch/percolator/RecoveryPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/RecoveryPercolatorTests.java index 98744288677..b694a7afbab 100644 --- a/src/test/java/org/elasticsearch/percolator/RecoveryPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/RecoveryPercolatorTests.java @@ -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")) @@ -111,10 +111,10 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest { .build(); cluster().startNode(settings); client().admin().indices().prepareCreate("test") - .setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); + .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(); } diff --git a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java index eeae4d0fc21..4a260c0861e 100644 --- a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java @@ -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()