Search in sources :

Example 1 with IndexConstraint

use of org.elasticsearch.action.fieldstats.IndexConstraint in project elasticsearch by elastic.

the class FieldStatsIntegrationIT method testIncompatibleFilter.

public void testIncompatibleFilter() throws Exception {
    assertAcked(prepareCreate("test1").addMapping("test", "value", "type=long"));
    indexRange("test1", -10, 100);
    try {
        client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MAX, LTE, "abc")).setLevel("indices").get();
        fail("exception should have been thrown, because value abc is incompatible");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("For input string: \"abc\""));
    }
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint)

Example 2 with IndexConstraint

use of org.elasticsearch.action.fieldstats.IndexConstraint in project elasticsearch by elastic.

the class FieldStatsIntegrationIT method testFieldStatsFiltering.

public void testFieldStatsFiltering() throws Exception {
    assertAcked(prepareCreate("test1").addMapping("test", "value", "type=long"));
    assertAcked(prepareCreate("test2").addMapping("test", "value", "type=long"));
    assertAcked(prepareCreate("test3").addMapping("test", "value", "type=long"));
    ensureGreen("test1", "test2", "test3");
    indexRange("test1", -10, 100);
    indexRange("test2", 101, 200);
    indexRange("test3", 201, 300);
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "200"), new IndexConstraint("value", MAX, LTE, "300")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMinValue(), equalTo(201L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMaxValue(), equalTo(300L));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MAX, LTE, "200")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(2));
    assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMaxValue(), equalTo(100L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(101L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(200L));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "100")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(2));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(101L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(200L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMinValue(), equalTo(201L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMaxValue(), equalTo(300L));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "-20"), new IndexConstraint("value", MAX, LT, "-10")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(0));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "-100"), new IndexConstraint("value", MAX, LTE, "-20")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(0));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "100"), new IndexConstraint("value", MAX, LTE, "200")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(101L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(200L));
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "150"), new IndexConstraint("value", MAX, LTE, "300")).setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMinValue(), equalTo(201L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMaxValue(), equalTo(300L));
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Example 3 with IndexConstraint

use of org.elasticsearch.action.fieldstats.IndexConstraint in project elasticsearch by elastic.

the class FieldStatsTests method testDateFiltering_optionalFormat.

public void testDateFiltering_optionalFormat() {
    createIndex("test1", Settings.EMPTY, "type", "value", "type=date,format=strict_date_optional_time");
    client().prepareIndex("test1", "type").setSource("value", "2014-01-01T00:00:00.000Z").get();
    createIndex("test2", Settings.EMPTY, "type", "value", "type=date,format=strict_date_optional_time");
    client().prepareIndex("test2", "type").setSource("value", "2014-01-02T00:00:00.000Z").get();
    client().admin().indices().prepareRefresh().get();
    DateTime dateTime1 = new DateTime(2014, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    DateTime dateTime2 = new DateTime(2014, 1, 2, 0, 0, 0, 0, DateTimeZone.UTC);
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, String.valueOf(dateTime1.getMillis()), "epoch_millis"), new IndexConstraint("value", MAX, LTE, String.valueOf(dateTime2.getMillis()), "epoch_millis")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), "2014-01-02T00:00:00.000Z");
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), "date");
    try {
        client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, String.valueOf(dateTime1.getMillis()), "xyz")).setLevel("indices").get();
        fail("IllegalArgumentException should have been thrown");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("Invalid format"));
    }
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) DateTime(org.joda.time.DateTime) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Example 4 with IndexConstraint

use of org.elasticsearch.action.fieldstats.IndexConstraint in project elasticsearch by elastic.

the class FieldStatsTests method testDateFiltering.

public void testDateFiltering() {
    DateTime dateTime1 = new DateTime(2014, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    String dateTime1Str = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().print(dateTime1);
    DateTime dateTime2 = new DateTime(2014, 1, 2, 0, 0, 0, 0, DateTimeZone.UTC);
    String dateTime2Str = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().print(dateTime2);
    createIndex("test1", Settings.EMPTY, "type", "value", "type=date", "value2", "type=date,index=false");
    client().prepareIndex("test1", "test").setSource("value", dateTime1Str, "value2", dateTime1Str).get();
    createIndex("test2", Settings.EMPTY, "type", "value", "type=date");
    client().prepareIndex("test2", "test").setSource("value", dateTime2Str).get();
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), dateTime1.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), dateTime2.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValueAsString(), dateTime1Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), dateTime2Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), "date");
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "2013-12-30T00:00:00.000Z"), new IndexConstraint("value", MAX, LTE, "2013-12-31T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "2013-12-31T00:00:00.000Z"), new IndexConstraint("value", MAX, LTE, "2014-01-01T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), dateTime1.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValueAsString(), dateTime1Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getDisplayType(), "date");
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "2014-01-01T00:00:00.000Z"), new IndexConstraint("value", MAX, LTE, "2014-01-02T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), dateTime2.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), dateTime2Str);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "2014-01-02T00:00:00.000Z"), new IndexConstraint("value", MAX, LTE, "2014-01-03T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "2014-01-01T23:00:00.000Z"), new IndexConstraint("value", MAX, LTE, "2014-01-02T01:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), dateTime2.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), dateTime2Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), "date");
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "2014-01-01T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), dateTime1.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), dateTime2.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValueAsString(), dateTime1Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), dateTime2Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), "date");
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MAX, LTE, "2014-01-02T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), dateTime1.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), dateTime2.getMillis());
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValueAsString(), dateTime1Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValueAsString(), dateTime2Str);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), "date");
    response = client().prepareFieldStats().setFields("value2").setIndexContraints(new IndexConstraint("value2", MAX, LTE, "2014-01-02T00:00:00.000Z")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Example 5 with IndexConstraint

use of org.elasticsearch.action.fieldstats.IndexConstraint in project elasticsearch by elastic.

the class FieldStatsTests method testNumberFiltering.

public void testNumberFiltering() {
    createIndex("test1", Settings.EMPTY, "type", "value", "type=long");
    client().prepareIndex("test1", "test").setSource("value", 1L).get();
    createIndex("test2", Settings.EMPTY, "type", "value", "type=long");
    client().prepareIndex("test2", "test").setSource("value", 3L).get();
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "-1"), new IndexConstraint("value", MAX, LTE, "0")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "0"), new IndexConstraint("value", MAX, LT, "1")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "0"), new IndexConstraint("value", MAX, LTE, "1")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "1"), new IndexConstraint("value", MAX, LTE, "2")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "1"), new IndexConstraint("value", MAX, LTE, "2")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "2"), new IndexConstraint("value", MAX, LTE, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "3"), new IndexConstraint("value", MAX, LTE, "4")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "3"), new IndexConstraint("value", MAX, LTE, "4")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "1"), new IndexConstraint("value", MAX, LTE, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "1"), new IndexConstraint("value", MAX, LT, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Aggregations

IndexConstraint (org.elasticsearch.action.fieldstats.IndexConstraint)5 FieldStatsResponse (org.elasticsearch.action.fieldstats.FieldStatsResponse)4 DateTime (org.joda.time.DateTime)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1