summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java
diff options
context:
space:
mode:
authorAdrien Grand <jpountz@gmail.com>2015-08-17 12:47:14 +0200
committerAdrien Grand <jpountz@gmail.com>2015-08-18 11:41:52 +0200
commita91b3fcbb9e493c3aac9b46723c8dcad2c23a3ae (patch)
treea9260054735dfce237cf88d074344b8da705ae19 /core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java
parent7765b0497d322914bf34fd4f2a5f819e5d095548 (diff)
Move the `murmur3` field to a plugin and fix defaults.
This move the `murmur3` field to the `mapper-murmur3` plugin and fixes its defaults so that values will not be indexed by default, as the only purpose of this field is to speed up `cardinality` aggregations on high-cardinality string fields, which only requires doc values. I also removed the `rehash` option from the `cardinality` aggregation as it doesn't bring much value (rehashing is cheap) and allowed to remove the coupling between the `cardinality` aggregation and the `murmur3` field. Close #12874
Diffstat (limited to 'core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java')
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java108
1 files changed, 15 insertions, 93 deletions
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java
index 491e4f694c..d77e4d1ccd 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java
@@ -61,54 +61,23 @@ public class CardinalityIT extends ESIntegTestCase {
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("str_value")
.field("type", "string")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
.endObject()
.startObject("str_values")
.field("type", "string")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
.endObject()
.startObject("l_value")
.field("type", "long")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
.endObject()
.startObject("l_values")
.field("type", "long")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
.endObject()
- .startObject("d_value")
- .field("type", "double")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
- .endObject()
- .startObject("d_values")
- .field("type", "double")
- .startObject("fields")
- .startObject("hash")
- .field("type", "murmur3")
- .endObject()
- .endObject()
- .endObject()
- .endObject()
- .endObject().endObject()).execute().actionGet();
+ .startObject("d_value")
+ .field("type", "double")
+ .endObject()
+ .startObject("d_values")
+ .field("type", "double")
+ .endObject()
+ .endObject().endObject().endObject()).execute().actionGet();
numDocs = randomIntBetween(2, 100);
precisionThreshold = randomIntBetween(0, 1 << randomInt(20));
@@ -145,12 +114,12 @@ public class CardinalityIT extends ESIntegTestCase {
assertThat(count.getValue(), greaterThan(0L));
}
}
- private String singleNumericField(boolean hash) {
- return (randomBoolean() ? "l_value" : "d_value") + (hash ? ".hash" : "");
+ private String singleNumericField() {
+ return randomBoolean() ? "l_value" : "d_value";
}
private String multiNumericField(boolean hash) {
- return (randomBoolean() ? "l_values" : "d_values") + (hash ? ".hash" : "");
+ return randomBoolean() ? "l_values" : "d_values";
}
@Test
@@ -196,23 +165,9 @@ public class CardinalityIT extends ESIntegTestCase {
}
@Test
- public void singleValuedStringHashed() throws Exception {
- SearchResponse response = client().prepareSearch("idx").setTypes("type")
- .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value.hash"))
- .execute().actionGet();
-
- assertSearchResponse(response);
-
- Cardinality count = response.getAggregations().get("cardinality");
- assertThat(count, notNullValue());
- assertThat(count.getName(), equalTo("cardinality"));
- assertCount(count, numDocs);
- }
-
- @Test
public void singleValuedNumeric() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
- .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField(false)))
+ .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
.execute().actionGet();
assertSearchResponse(response);
@@ -229,7 +184,7 @@ public class CardinalityIT extends ESIntegTestCase {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery())
.addAggregation(
global("global").subAggregation(
- cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField(false))))
+ cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField())))
.execute().actionGet();
assertSearchResponse(searchResponse);
@@ -254,7 +209,7 @@ public class CardinalityIT extends ESIntegTestCase {
@Test
public void singleValuedNumericHashed() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
- .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField(true)))
+ .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
.execute().actionGet();
assertSearchResponse(response);
@@ -280,20 +235,6 @@ public class CardinalityIT extends ESIntegTestCase {
}
@Test
- public void multiValuedStringHashed() throws Exception {
- SearchResponse response = client().prepareSearch("idx").setTypes("type")
- .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_values.hash"))
- .execute().actionGet();
-
- assertSearchResponse(response);
-
- Cardinality count = response.getAggregations().get("cardinality");
- assertThat(count, notNullValue());
- assertThat(count.getName(), equalTo("cardinality"));
- assertCount(count, numDocs * 2);
- }
-
- @Test
public void multiValuedNumeric() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(multiNumericField(false)))
@@ -356,7 +297,7 @@ public class CardinalityIT extends ESIntegTestCase {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(
cardinality("cardinality").precisionThreshold(precisionThreshold).script(
- new Script("doc['" + singleNumericField(false) + "'].value")))
+ new Script("doc['" + singleNumericField() + "'].value")))
.execute().actionGet();
assertSearchResponse(response);
@@ -417,7 +358,7 @@ public class CardinalityIT extends ESIntegTestCase {
public void singleValuedNumericValueScript() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
.addAggregation(
- cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField(false))
+ cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField())
.script(new Script("_value")))
.execute().actionGet();
@@ -464,23 +405,4 @@ public class CardinalityIT extends ESIntegTestCase {
}
}
- @Test
- public void asSubAggHashed() throws Exception {
- SearchResponse response = client().prepareSearch("idx").setTypes("type")
- .addAggregation(terms("terms").field("str_value")
- .collectMode(randomFrom(SubAggCollectionMode.values()))
- .subAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_values.hash")))
- .execute().actionGet();
-
- assertSearchResponse(response);
-
- Terms terms = response.getAggregations().get("terms");
- for (Terms.Bucket bucket : terms.getBuckets()) {
- Cardinality count = bucket.getAggregations().get("cardinality");
- assertThat(count, notNullValue());
- assertThat(count.getName(), equalTo("cardinality"));
- assertCount(count, 2);
- }
- }
-
}