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:
parent
af183a1619
commit
7c32269f4f
|
@ -14,7 +14,7 @@ documentation before reading this guide.
|
||||||
QueryBuilder qb = termQuery("content", "amazing");
|
QueryBuilder qb = termQuery("content", "amazing");
|
||||||
|
|
||||||
//Index the query = register it in the percolator
|
//Index the query = register it in the percolator
|
||||||
client.prepareIndex("myIndexName", "_percolator", "myDesignatedQueryName")
|
client.prepareIndex("myIndexName", ".percolator", "myDesignatedQueryName")
|
||||||
.setSource(jsonBuilder()
|
.setSource(jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("query", qb) // Register the query
|
.field("query", qb) // Register the query
|
||||||
|
|
|
@ -22,7 +22,7 @@ Adding a query to the percolator:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT 'localhost:9200/my-index/_percolator/1' -d '{
|
curl -XPUT 'localhost:9200/my-index/.percolator/1' -d '{
|
||||||
"query" : {
|
"query" : {
|
||||||
"match" : {
|
"match" : {
|
||||||
"message" : "bonsai tree"
|
"message" : "bonsai tree"
|
||||||
|
@ -69,7 +69,7 @@ The percolate api returns matches that refer to percolate queries that have matc
|
||||||
=== Indexing percolator queries
|
=== Indexing percolator queries
|
||||||
|
|
||||||
Percolate queries are stored as documents in a specific format and in an arbitrary index under a reserved type with the
|
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]
|
[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
|
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
|
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,
|
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.
|
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
|
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`.
|
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.
|
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]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{
|
{
|
||||||
"_percolator" : {
|
".percolator" : {
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"query" : {
|
"query" : {
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
|
@ -148,7 +148,7 @@ the following delete requests needs to be executed:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XDELETE localhost:9200/my-index/_percolator/1
|
curl -XDELETE localhost:9200/my-index/.percolator/1
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
[float]
|
[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.
|
The percolate api executes in a distributed manner, meaning it executes on all shards an index points to.
|
||||||
|
|
||||||
.Required options
|
.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.
|
* `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.
|
* `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]
|
[float]
|
||||||
=== How it works under the hood
|
=== 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
|
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
|
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
|
Lucene index. This in-memory index can just hold this one document and it is optimized for that. Then all the queries
|
||||||
|
|
|
@ -444,7 +444,7 @@ public class MetaDataMappingService extends AbstractComponent {
|
||||||
} else if (!mappingType.equals(newMappers.values().iterator().next().type())) {
|
} else if (!mappingType.equals(newMappers.values().iterator().next().type())) {
|
||||||
throw new InvalidTypeNameException("Type name provided does not match type name within mapping definition");
|
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 '_'");
|
throw new InvalidTypeNameException("Document mapping type name can't start with '_'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultPercolatorMappingSource = "{\n" +
|
defaultPercolatorMappingSource = "{\n" +
|
||||||
" \"_default_\":{\n" +
|
//" \"" + PercolatorService.TYPE_NAME + "\":{\n" +
|
||||||
|
" \"" + "_default_" + "\":{\n" +
|
||||||
" \"_id\" : {\"index\": \"not_analyzed\"}," +
|
" \"_id\" : {\"index\": \"not_analyzed\"}," +
|
||||||
" \"properties\" : {\n" +
|
" \"properties\" : {\n" +
|
||||||
" \"query\" : {\n" +
|
" \"query\" : {\n" +
|
||||||
|
@ -246,7 +247,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||||
if (mapper.type().length() == 0) {
|
if (mapper.type().length() == 0) {
|
||||||
throw new InvalidTypeNameException("mapping type name is empty");
|
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 '_'");
|
throw new InvalidTypeNameException("mapping type name [" + mapper.type() + "] can't start with '_'");
|
||||||
}
|
}
|
||||||
if (mapper.type().contains("#")) {
|
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 {
|
public DocumentMapper parse(String mappingType, String mappingSource, boolean applyDefault) throws MapperParsingException {
|
||||||
String defaultMappingSource;
|
String defaultMappingSource;
|
||||||
if (PercolatorService.Constants.TYPE_NAME.equals(mappingType)) {
|
if (PercolatorService.TYPE_NAME.equals(mappingType)) {
|
||||||
defaultMappingSource = defaultPercolatorMappingSource;
|
defaultMappingSource = this.defaultPercolatorMappingSource;
|
||||||
} else {
|
} else {
|
||||||
defaultMappingSource = this.defaultMappingSource;
|
defaultMappingSource = this.defaultMappingSource;
|
||||||
}
|
}
|
||||||
|
@ -407,10 +408,10 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Filter searchFilter(String... types) {
|
public Filter searchFilter(String... types) {
|
||||||
boolean filterPercolateType = hasMapping(PercolatorService.Constants.TYPE_NAME);
|
boolean filterPercolateType = hasMapping(PercolatorService.TYPE_NAME);
|
||||||
if (types != null && filterPercolateType) {
|
if (types != null && filterPercolateType) {
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
|
if (PercolatorService.TYPE_NAME.equals(type)) {
|
||||||
filterPercolateType = false;
|
filterPercolateType = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -418,7 +419,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||||
}
|
}
|
||||||
Filter excludePercolatorType = null;
|
Filter excludePercolatorType = null;
|
||||||
if (filterPercolateType) {
|
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) {
|
if (types == null || types.length == 0) {
|
||||||
|
|
|
@ -37,8 +37,8 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each shard will have a percolator registry even if there isn't a _percolator document type in the index.
|
* 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 _percolator document type, this will hold no percolate queries.
|
* For shards with indices that have no {@link PercolatorService#TYPE_NAME} document type, this will hold no percolate queries.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Once a document type has been created, the real-time percolator will start to listen to write events and update the
|
* 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.
|
* this registry with queries in real time.
|
||||||
|
@ -116,7 +116,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePercolateQuery(String idAsString) {
|
public void removePercolateQuery(String idAsString) {
|
||||||
HashedBytesRef id =new HashedBytesRef(idAsString) ;
|
HashedBytesRef id = new HashedBytesRef(idAsString);
|
||||||
Query query = percolateQueries.remove(id);
|
Query query = percolateQueries.remove(id);
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
shardPercolateService.removedQuery(id, query);
|
shardPercolateService.removedQuery(id, query);
|
||||||
|
@ -194,14 +194,14 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void created(String type) {
|
public void created(String type) {
|
||||||
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
|
if (PercolatorService.TYPE_NAME.equals(type)) {
|
||||||
enableRealTimePercolator();
|
enableRealTimePercolator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed(String type) {
|
public void removed(String type) {
|
||||||
if (PercolatorService.Constants.TYPE_NAME.equals(type)) {
|
if (PercolatorService.TYPE_NAME.equals(type)) {
|
||||||
disableRealTimePercolator();
|
disableRealTimePercolator();
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
|
|
||||||
private boolean hasPercolatorType(IndexShard indexShard) {
|
private boolean hasPercolatorType(IndexShard indexShard) {
|
||||||
ShardId otherShardId = indexShard.shardId();
|
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) {
|
private void loadQueries(IndexShard shard) {
|
||||||
|
@ -241,7 +241,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
try {
|
try {
|
||||||
Query query = new XConstantScoreQuery(
|
Query query = new XConstantScoreQuery(
|
||||||
indexCache.filter().cache(
|
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);
|
QueriesLoaderCollector queryCollector = new QueriesLoaderCollector(PercolatorQueriesRegistry.this, logger, indexFieldDataService);
|
||||||
|
@ -266,7 +266,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
@Override
|
@Override
|
||||||
public Engine.Create preCreate(Engine.Create create) {
|
public Engine.Create preCreate(Engine.Create create) {
|
||||||
// validate the query here, before we index
|
// 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());
|
parsePercolatorDocument(create.id(), create.source());
|
||||||
}
|
}
|
||||||
return create;
|
return create;
|
||||||
|
@ -275,7 +275,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
@Override
|
@Override
|
||||||
public void postCreateUnderLock(Engine.Create create) {
|
public void postCreateUnderLock(Engine.Create create) {
|
||||||
// add the query under a doc lock
|
// 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());
|
addPercolateQuery(create.id(), create.source());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
@Override
|
@Override
|
||||||
public Engine.Index preIndex(Engine.Index index) {
|
public Engine.Index preIndex(Engine.Index index) {
|
||||||
// validate the query here, before we 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());
|
parsePercolatorDocument(index.id(), index.source());
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
|
@ -292,7 +292,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
@Override
|
@Override
|
||||||
public void postIndexUnderLock(Engine.Index index) {
|
public void postIndexUnderLock(Engine.Index index) {
|
||||||
// add the query under a doc lock
|
// 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());
|
addPercolateQuery(index.id(), index.source());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
|
||||||
@Override
|
@Override
|
||||||
public void postDeleteUnderLock(Engine.Delete delete) {
|
public void postDeleteUnderLock(Engine.Delete delete) {
|
||||||
// remove the query under a lock
|
// remove the query under a lock
|
||||||
if (PercolatorService.Constants.TYPE_NAME.equals(delete.type())) {
|
if (PercolatorService.TYPE_NAME.equals(delete.type())) {
|
||||||
removePercolateQuery(delete.id());
|
removePercolateQuery(delete.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,7 @@ import org.elasticsearch.index.query.ParsedQuery;
|
||||||
import org.elasticsearch.index.service.IndexService;
|
import org.elasticsearch.index.service.IndexService;
|
||||||
import org.elasticsearch.index.shard.service.IndexShard;
|
import org.elasticsearch.index.shard.service.IndexShard;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.percolator.QueryCollector.Count;
|
import org.elasticsearch.percolator.QueryCollector.*;
|
||||||
import org.elasticsearch.percolator.QueryCollector.Match;
|
|
||||||
import org.elasticsearch.percolator.QueryCollector.MatchAndScore;
|
|
||||||
import org.elasticsearch.percolator.QueryCollector.MatchAndSort;
|
|
||||||
import org.elasticsearch.search.SearchParseElement;
|
import org.elasticsearch.search.SearchParseElement;
|
||||||
import org.elasticsearch.search.SearchShardTarget;
|
import org.elasticsearch.search.SearchShardTarget;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
|
@ -100,6 +97,7 @@ import static org.elasticsearch.percolator.QueryCollector.*;
|
||||||
public class PercolatorService extends AbstractComponent {
|
public class PercolatorService extends AbstractComponent {
|
||||||
|
|
||||||
public final static float NO_SCORE = Float.NEGATIVE_INFINITY;
|
public final static float NO_SCORE = Float.NEGATIVE_INFINITY;
|
||||||
|
public static final String TYPE_NAME = ".percolator";
|
||||||
|
|
||||||
private final CloseableThreadLocal<MemoryIndex> cache;
|
private final CloseableThreadLocal<MemoryIndex> cache;
|
||||||
private final IndicesService indicesService;
|
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
|
// 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
|
// not the in memory percolate doc
|
||||||
String[] previousTypes = context.types();
|
String[] previousTypes = context.types();
|
||||||
context.types(new String[]{Constants.TYPE_NAME});
|
context.types(new String[]{TYPE_NAME});
|
||||||
SearchContext.setCurrent(context);
|
SearchContext.setCurrent(context);
|
||||||
try {
|
try {
|
||||||
parser = XContentFactory.xContent(source).createParser(source);
|
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 {
|
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);
|
percolatorTypeFilter = context.indexService().cache().filter().cache(percolatorTypeFilter);
|
||||||
FilteredQuery query = new FilteredQuery(context.percolateQuery(), percolatorTypeFilter);
|
FilteredQuery query = new FilteredQuery(context.percolateQuery(), percolatorTypeFilter);
|
||||||
percolatorSearcher.searcher().search(query, percolateCollector);
|
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) {
|
private InternalFacets reduceFacets(List<PercolateShardResponse> shardResults) {
|
||||||
if (shardResults.size() == 1) {
|
if (shardResults.size() == 1) {
|
||||||
return shardResults.get(0).facets();
|
return shardResults.get(0).facets();
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.StopWatch;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.node.Node;
|
import org.elasticsearch.node.Node;
|
||||||
|
import org.elasticsearch.percolator.PercolatorService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -83,7 +84,7 @@ public class PercolatorStressBenchmark {
|
||||||
// register queries
|
// register queries
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < TERM_QUERIES; i++) {
|
for (; i < TERM_QUERIES; i++) {
|
||||||
client.prepareIndex("test", "_percolator", Integer.toString(i))
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("query", termQuery("name", "value"))
|
.field("query", termQuery("name", "value"))
|
||||||
.endObject())
|
.endObject())
|
||||||
|
@ -92,7 +93,7 @@ public class PercolatorStressBenchmark {
|
||||||
|
|
||||||
int[] numbers = new int[RANGE_QUERIES];
|
int[] numbers = new int[RANGE_QUERIES];
|
||||||
for (; i < QUERIES; i++) {
|
for (; i < QUERIES; i++) {
|
||||||
client.prepareIndex("test", "_percolator", Integer.toString(i))
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, Integer.toString(i))
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("query", rangeQuery("numeric1").from(i).to(i))
|
.field("query", rangeQuery("numeric1").from(i).to(i))
|
||||||
.endObject())
|
.endObject())
|
||||||
|
|
|
@ -80,10 +80,10 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
|
||||||
.field("field2", "value")
|
.field("field2", "value")
|
||||||
.endObject()).execute().actionGet();
|
.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())
|
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("index", "_percolator", "test2")
|
client().prepareIndex("index", PercolatorService.TYPE_NAME, "test2")
|
||||||
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
|
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -190,19 +190,19 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
|
||||||
IndexResponse response;
|
IndexResponse response;
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case 0:
|
case 0:
|
||||||
response = client().prepareIndex("index", "_percolator", id)
|
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
|
||||||
.setSource(onlyField1)
|
.setSource(onlyField1)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
type1.incrementAndGet();
|
type1.incrementAndGet();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
response = client().prepareIndex("index", "_percolator", id)
|
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
|
||||||
.setSource(onlyField2)
|
.setSource(onlyField2)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
type2.incrementAndGet();
|
type2.incrementAndGet();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
response = client().prepareIndex("index", "_percolator", id)
|
response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
|
||||||
.setSource(field1And2)
|
.setSource(field1And2)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
type3.incrementAndGet();
|
type3.incrementAndGet();
|
||||||
|
@ -320,7 +320,8 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
|
||||||
try {
|
try {
|
||||||
XContentBuilder doc = XContentFactory.jsonBuilder().startObject()
|
XContentBuilder doc = XContentFactory.jsonBuilder().startObject()
|
||||||
.field("query", termQuery("field1", "value")).endObject();
|
.field("query", termQuery("field1", "value")).endObject();
|
||||||
outer: while (run.get()) {
|
outer:
|
||||||
|
while (run.get()) {
|
||||||
semaphore.acquire();
|
semaphore.acquire();
|
||||||
try {
|
try {
|
||||||
if (!liveIds.isEmpty() && getRandom().nextInt(100) < 19) {
|
if (!liveIds.isEmpty() && getRandom().nextInt(100) < 19) {
|
||||||
|
@ -332,13 +333,13 @@ public class ConcurrentPercolatorTests extends AbstractIntegrationTest {
|
||||||
id = Integer.toString(randomInt(idGen.get()));
|
id = Integer.toString(randomInt(idGen.get()));
|
||||||
} while (!liveIds.remove(id));
|
} while (!liveIds.remove(id));
|
||||||
|
|
||||||
DeleteResponse response = client().prepareDelete("index", "_percolator", id)
|
DeleteResponse response = client().prepareDelete("index", PercolatorService.TYPE_NAME, id)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertThat(response.getId(), equalTo(id));
|
assertThat(response.getId(), equalTo(id));
|
||||||
assertThat("doc[" + id + "] should have been deleted, but isn't", response.isNotFound(), equalTo(false));
|
assertThat("doc[" + id + "] should have been deleted, but isn't", response.isNotFound(), equalTo(false));
|
||||||
} else {
|
} else {
|
||||||
String id = Integer.toString(idGen.getAndIncrement());
|
String id = Integer.toString(idGen.getAndIncrement());
|
||||||
IndexResponse response = client().prepareIndex("index", "_percolator", id)
|
IndexResponse response = client().prepareIndex("index", PercolatorService.TYPE_NAME, id)
|
||||||
.setSource(doc)
|
.setSource(doc)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
liveIds.add(id);
|
liveIds.add(id);
|
||||||
|
|
|
@ -43,19 +43,19 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
|
||||||
int numQueries = randomIntBetween(50, 100);
|
int numQueries = randomIntBetween(50, 100);
|
||||||
logger.info("--> register a queries");
|
logger.info("--> register a queries");
|
||||||
for (int i = 0; i < numQueries; i++) {
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
|
||||||
int numQueries = randomIntBetween(50, 100);
|
int numQueries = randomIntBetween(50, 100);
|
||||||
logger.info("--> register a queries");
|
logger.info("--> register a queries");
|
||||||
for (int i = 0; i < numQueries; i++) {
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ public class MultiPercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(response.items().length, equalTo(numPercolateRequest + 1));
|
assertThat(response.items().length, equalTo(numPercolateRequest + 1));
|
||||||
assertThat(response.items()[numPercolateRequest].isFailure(), equalTo(false));
|
assertThat(response.items()[numPercolateRequest].isFailure(), equalTo(false));
|
||||||
assertNoFailures(response.items()[numPercolateRequest].getResponse());
|
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));
|
assertThat(response.items()[numPercolateRequest].getResponse().getMatches().length, equalTo(numQueries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class PercolatorFacetsTests extends AbstractIntegrationTest {
|
||||||
String value = values[i % numUniqueQueries];
|
String value = values[i % numUniqueQueries];
|
||||||
expectedCount[i % numUniqueQueries]++;
|
expectedCount[i % numUniqueQueries]++;
|
||||||
QueryBuilder queryBuilder = matchQuery("field1", value);
|
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())
|
.setSource(jsonBuilder().startObject().field("query", queryBuilder).field("field2", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,9 @@ public class PercolatorFacetsTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
assertThat(response.getFacets().facets().size(), equalTo(1));
|
assertThat(response.getFacets().facets().size(), equalTo(1));
|
||||||
assertThat(response.getFacets().facets().get(0).getName(), equalTo("a"));
|
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().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).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().get(0).getTerm().string(), equalTo("b"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,19 +75,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
|
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
||||||
|
@ -177,7 +177,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(response.getMatches(), emptyArray());
|
assertThat(response.getMatches(), emptyArray());
|
||||||
|
|
||||||
// add first query...
|
// 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())
|
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field2", "value")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
|
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContaining("test1"));
|
||||||
|
|
||||||
// add second query...
|
// 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())
|
.setSource(XContentFactory.jsonBuilder().startObject().field("query", termQuery("field1", 1)).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("test1", "test2"));
|
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()
|
response = client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
.setSource(doc).execute().actionGet();
|
.setSource(doc).execute().actionGet();
|
||||||
|
@ -215,7 +215,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
// add a range query (cached)
|
// add a range query (cached)
|
||||||
// add a query
|
// add a query
|
||||||
client().prepareIndex("test1", "_percolator")
|
client().prepareIndex("test1", PercolatorService.TYPE_NAME)
|
||||||
.setSource(
|
.setSource(
|
||||||
XContentFactory.jsonBuilder().startObject().field("query",
|
XContentFactory.jsonBuilder().startObject().field("query",
|
||||||
constantScoreQuery(FilterBuilders.rangeFilter("field2").from("value").includeLower(true))
|
constantScoreQuery(FilterBuilders.rangeFilter("field2").from("value").includeLower(true))
|
||||||
|
@ -239,7 +239,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
logger.info("--> register a queries");
|
||||||
for (int i = 1; i <= 100; i++) {
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.setRouting(Integer.toString(i % 2))
|
.setRouting(Integer.toString(i % 2))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
@ -276,7 +276,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
|
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("my-queries-index", "_percolator", "kuku")
|
client().prepareIndex("my-queries-index", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -290,7 +290,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
|
client().prepareIndex("test", "test", "1").setSource("field1", "value1").execute().actionGet();
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("my-queries-index", "_percolator", "kuku")
|
client().prepareIndex("my-queries-index", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -321,7 +321,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "1")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("source", "productizer")
|
.field("source", "productizer")
|
||||||
.field("query", QueryBuilders.constantScoreQuery(QueryBuilders.queryString("filingcategory:s")))
|
.field("query", QueryBuilders.constantScoreQuery(QueryBuilders.queryString("filingcategory:s")))
|
||||||
|
@ -346,7 +346,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -355,7 +355,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
CountResponse countResponse = client().prepareCount()
|
CountResponse countResponse = client().prepareCount()
|
||||||
.setQuery(matchAllQuery()).setTypes("_percolator")
|
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertThat(countResponse.getCount(), equalTo(1l));
|
assertThat(countResponse.getCount(), equalTo(1l));
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
client().admin().indices().prepareDelete("test").execute().actionGet();
|
client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||||
logger.info("--> make sure percolated queries for it have been deleted as well");
|
logger.info("--> make sure percolated queries for it have been deleted as well");
|
||||||
countResponse = client().prepareCount()
|
countResponse = client().prepareCount()
|
||||||
.setQuery(matchAllQuery()).setTypes("_percolator")
|
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertThat(countResponse.getCount(), equalTo(0l));
|
assertThat(countResponse.getCount(), equalTo(0l));
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query 1");
|
logger.info("--> register a query 1");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -402,7 +402,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a query 2");
|
logger.info("--> register a query 2");
|
||||||
client().prepareIndex("test", "_percolator", "bubu")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "bubu")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "green")
|
.field("color", "green")
|
||||||
.field("query", termQuery("field1", "value2"))
|
.field("query", termQuery("field1", "value2"))
|
||||||
|
@ -432,7 +432,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query 1");
|
logger.info("--> register a query 1");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -448,7 +448,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
|
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("kuku"));
|
||||||
|
|
||||||
logger.info("--> register a query 2");
|
logger.info("--> register a query 2");
|
||||||
client().prepareIndex("test", "_percolator", "bubu")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "bubu")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "green")
|
.field("color", "green")
|
||||||
.field("query", termQuery("field1", "value2"))
|
.field("query", termQuery("field1", "value2"))
|
||||||
|
@ -464,7 +464,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("bubu"));
|
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("bubu"));
|
||||||
|
|
||||||
logger.info("--> register a query 3");
|
logger.info("--> register a query 3");
|
||||||
client().prepareIndex("test", "_percolator", "susu")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "susu")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "red")
|
.field("color", "red")
|
||||||
.field("query", termQuery("field1", "value2"))
|
.field("query", termQuery("field1", "value2"))
|
||||||
|
@ -483,7 +483,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("susu"));
|
assertThat(convertFromTextArray(percolate.getMatches(), "test"), arrayContaining("susu"));
|
||||||
|
|
||||||
logger.info("--> deleting query 1");
|
logger.info("--> deleting query 1");
|
||||||
client().prepareDelete("test", "_percolator", "kuku").setRefresh(true).execute().actionGet();
|
client().prepareDelete("test", PercolatorService.TYPE_NAME, "kuku").setRefresh(true).execute().actionGet();
|
||||||
|
|
||||||
percolate = client().preparePercolate()
|
percolate = client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
|
@ -507,7 +507,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
.endObject())
|
.endObject())
|
||||||
|
@ -532,7 +532,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "1")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").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();
|
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").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();
|
client().prepareIndex("test", "type", "4").setSource("field1", "d").setRouting("1").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").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();
|
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> registering queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
||||||
|
@ -832,7 +832,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
logger.info("--> registering queries");
|
logger.info("--> registering queries");
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
String index = i % 2 == 0 ? "test1" : "test2";
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
@ -906,19 +906,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
|
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").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();
|
client().prepareIndex("test", "type", "4").setSource("field1", "d").execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "2")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "3")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
.setSource(jsonBuilder().startObject().field("query", boolQuery()
|
||||||
.must(matchQuery("field1", "b"))
|
.must(matchQuery("field1", "b"))
|
||||||
.must(matchQuery("field1", "c"))
|
.must(matchQuery("field1", "c"))
|
||||||
).endObject())
|
).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test", "_percolator", "4")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
||||||
|
@ -1044,10 +1044,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
int numLevels = randomIntBetween(1, 25);
|
int numLevels = randomIntBetween(1, 25);
|
||||||
long numQueriesPerLevel = randomIntBetween(10, 250);
|
long numQueriesPerLevel = randomIntBetween(10, 250);
|
||||||
long totalQueries = numLevels * numQueriesPerLevel;
|
long totalQueries = numLevels * numQueriesPerLevel;
|
||||||
logger.info("--> register " + totalQueries +" queries");
|
logger.info("--> register " + totalQueries + " queries");
|
||||||
for (int level = 1; level <= numLevels; level++) {
|
for (int level = 1; level <= numLevels; level++) {
|
||||||
for (int query = 1; query <= numQueriesPerLevel; query++) {
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", level).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
@ -1145,10 +1145,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
Map<Integer, NavigableSet<Integer>> controlMap = new HashMap<Integer, NavigableSet<Integer>>();
|
Map<Integer, NavigableSet<Integer>> controlMap = new HashMap<Integer, NavigableSet<Integer>>();
|
||||||
long numQueries = randomIntBetween(100, 250);
|
long numQueries = randomIntBetween(100, 250);
|
||||||
logger.info("--> register " + numQueries +" queries");
|
logger.info("--> register " + numQueries + " queries");
|
||||||
for (int i = 0; i < numQueries; i++) {
|
for (int i = 0; i < numQueries; i++) {
|
||||||
int value = randomInt(10);
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", i).field("field1", value).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
if (!controlMap.containsKey(value)) {
|
if (!controlMap.containsKey(value)) {
|
||||||
|
@ -1231,10 +1231,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
client().admin().indices().prepareCreate("my-index").execute().actionGet();
|
client().admin().indices().prepareCreate("my-index").execute().actionGet();
|
||||||
ensureGreen();
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 1).endObject())
|
||||||
.execute().actionGet();
|
.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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 2).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -1288,7 +1288,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
ensureGreen();
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).field("level", 1).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -1323,19 +1323,19 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "brown fox")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client.prepareIndex("test", "_percolator", "2")
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, "2")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "lazy dog")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "lazy dog")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client.prepareIndex("test", "_percolator", "3")
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, "3")
|
||||||
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "jumps")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "jumps")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client.prepareIndex("test", "_percolator", "4")
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, "4")
|
||||||
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "dog")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "dog")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client.prepareIndex("test", "_percolator", "5")
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, "5")
|
||||||
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "fox")).endObject())
|
.setSource(jsonBuilder().startObject().field("query", termQuery("field1", "fox")).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -1469,10 +1469,10 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
client().admin().indices().prepareCreate("test2").execute().actionGet();
|
client().admin().indices().prepareCreate("test2").execute().actionGet();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
client().prepareIndex("test1", "_percolator", "1")
|
client().prepareIndex("test1", PercolatorService.TYPE_NAME, "1")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
client().prepareIndex("test2", "_percolator", "1")
|
client().prepareIndex("test2", PercolatorService.TYPE_NAME, "1")
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
@ -1483,9 +1483,9 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(response.getCount(), equalTo(2l));
|
assertThat(response.getCount(), equalTo(2l));
|
||||||
|
|
||||||
CountDownLatch test1Latch = createCountDownLatch("test1");
|
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();
|
test1Latch.await();
|
||||||
|
|
||||||
response = client().preparePercolate()
|
response = client().preparePercolate()
|
||||||
|
@ -1495,7 +1495,7 @@ public class PercolatorTests extends AbstractIntegrationTest {
|
||||||
assertNoFailures(response);
|
assertNoFailures(response);
|
||||||
assertThat(response.getCount(), equalTo(1l));
|
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();
|
test2Latch.await();
|
||||||
|
|
||||||
// Percolate api should return 0 matches, because all _percolate types have been removed.
|
// Percolate api should return 0 matches, because all _percolate types have been removed.
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
).execute().actionGet();
|
).execute().actionGet();
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -114,7 +114,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
.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");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -122,7 +122,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
.setRefresh(true)
|
.setRefresh(true)
|
||||||
.execute().actionGet();
|
.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()
|
PercolateResponse percolate = client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
|
@ -140,7 +140,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
|
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();
|
DeleteIndexResponse actionGet = client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||||
assertThat(actionGet.isAcknowledged(), equalTo(true));
|
assertThat(actionGet.isAcknowledged(), equalTo(true));
|
||||||
|
@ -149,7 +149,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
||||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
|
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
|
||||||
assertThat(client().prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||||
|
|
||||||
percolate = client().preparePercolate()
|
percolate = client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
|
@ -160,7 +160,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
assertThat(percolate.getMatches(), emptyArray());
|
assertThat(percolate.getMatches(), emptyArray());
|
||||||
|
|
||||||
logger.info("--> register a query");
|
logger.info("--> register a query");
|
||||||
client().prepareIndex("test", "_percolator", "kuku")
|
client().prepareIndex("test", PercolatorService.TYPE_NAME, "kuku")
|
||||||
.setSource(jsonBuilder().startObject()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("color", "blue")
|
.field("color", "blue")
|
||||||
.field("query", termQuery("field1", "value1"))
|
.field("query", termQuery("field1", "value1"))
|
||||||
|
@ -168,7 +168,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
.setRefresh(true)
|
.setRefresh(true)
|
||||||
.execute().actionGet();
|
.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()
|
percolate = client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
|
@ -204,7 +204,7 @@ public class RecoveryPercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
logger.info("--> register a queries");
|
logger.info("--> register a queries");
|
||||||
for (int i = 1; i <= 100; i++) {
|
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()
|
.setSource(jsonBuilder().startObject()
|
||||||
.field("query", rangeQuery("field1").from(0).to(i))
|
.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.
|
// 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);
|
final int numQueries = randomIntBetween(50, 100);
|
||||||
logger.info("--> register a queries");
|
logger.info("--> register a queries");
|
||||||
for (int i = 0; i < numQueries; i++) {
|
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())
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
||||||
client.admin().indices().prepareDelete().execute().actionGet();
|
client.admin().indices().prepareDelete().execute().actionGet();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator")
|
String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject(PercolatorService.TYPE_NAME)
|
||||||
.startObject("_ttl").field("enabled", true).endObject()
|
.startObject("_ttl").field("enabled", true).endObject()
|
||||||
.startObject("_timestamp").field("enabled", true).endObject()
|
.startObject("_timestamp").field("enabled", true).endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
|
@ -50,14 +50,14 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
||||||
|
|
||||||
client.admin().indices().prepareCreate("test")
|
client.admin().indices().prepareCreate("test")
|
||||||
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
|
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
|
||||||
.addMapping("_percolator", precolatorMapping)
|
.addMapping(PercolatorService.TYPE_NAME, precolatorMapping)
|
||||||
.addMapping("type1", typeMapping)
|
.addMapping("type1", typeMapping)
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
long ttl = 1500;
|
long ttl = 1500;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
client.prepareIndex("test", "_percolator", "kuku").setSource(jsonBuilder()
|
client.prepareIndex("test", PercolatorService.TYPE_NAME, "kuku").setSource(jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startObject("query")
|
.startObject("query")
|
||||||
.startObject("term")
|
.startObject("term")
|
||||||
|
@ -84,7 +84,7 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
||||||
assertNoFailures(percolateResponse);
|
assertNoFailures(percolateResponse);
|
||||||
if (percolateResponse.getMatches().length == 0) {
|
if (percolateResponse.getMatches().length == 0) {
|
||||||
// OK, ttl + purgeInterval has passed (slow machine or many other tests were running at the same time
|
// 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));
|
assertThat(getResponse.isExists(), equalTo(false));
|
||||||
response = client.admin().indices().prepareStats("test")
|
response = client.admin().indices().prepareStats("test")
|
||||||
.clear().setIndexing(true)
|
.clear().setIndexing(true)
|
||||||
|
@ -110,7 +110,8 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
// This returns the number of delete operations stats (not Lucene delete count)
|
// This returns the number of delete operations stats (not Lucene delete count)
|
||||||
currentDeleteCount = response.getIndices().get("test").getTotal().getIndexing().getTotal().getDeleteCount();
|
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));
|
assertThat(currentDeleteCount, equalTo(2l));
|
||||||
|
|
||||||
percolateResponse = client.preparePercolate()
|
percolateResponse = client.preparePercolate()
|
||||||
|
|
Loading…
Reference in New Issue