ElasticsearchUtils { public static String[] getIndices(final String table) { return new String[]{String.format("%s-%s-%s-*", ElasticsearchUtils.TABLENAME_PREFIX, table, ElasticsearchUtils.TABLENAME_POSTFIX)}; }  static void setMapper(ObjectMapper mapper); static ObjectMapper getMapper(); static String getIndexPrefix(final String table); static String[] getIndices(final String table); static String[] getIndices(final String table, final ActionRequest request); @VisibleForTesting static String[] getIndices(final String table, final ActionRequest request, final Interval interval); static String getCurrentIndex(final String table, long timestamp); static PutIndexTemplateRequest getClusterTemplateMapping(IndicesAdminClient indicesAdminClient); static void initializeMappings(Client client); static String getValidTableName(String table); static boolean isIndexValidForTable(String index, String table); static boolean isIndexEligibleForDeletion(String index, Table table); static String getTableNameFromIndex(String currentIndex); static final String TYPE_NAME; static final String TABLENAME_PREFIX; static final String TABLENAME_POSTFIX; static final DateTimeFormatter DATE_TIME_FORMATTER; }
@Test public void testGetIndicesLastSameSDay() throws Exception { TestRequest request = new TestRequest(); LastFilter filter = new LastFilter(); filter.setDuration(Duration.minutes(10)); filter.setCurrentTime(TEST_CURRENT_TIME); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{"foxtrot-test-table-04-4-2015"}, indexes); }
@Test public void testGetIndicesLastLastDays() throws Exception { TestRequest request = new TestRequest(); LastFilter filter = new LastFilter(); filter.setDuration(Duration.days(2)); filter.setCurrentTime(TEST_CURRENT_TIME); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{ "foxtrot-test-table-02-4-2015", "foxtrot-test-table-03-4-2015", "foxtrot-test-table-04-4-2015"}, indexes); }
@Test public void testGetIndicesBetween() throws Exception { TestRequest request = new TestRequest(); BetweenFilter filter = new BetweenFilter(); filter.setTemporal(true); filter.setFrom(1427997600000L); filter.setTo(1428001200000L); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{ "foxtrot-test-table-02-4-2015", "foxtrot-test-table-03-4-2015"}, indexes); }
@Test public void testGetIndicesGreaterThan() throws Exception { TestRequest request = new TestRequest(); GreaterThanFilter filter = new GreaterThanFilter(); filter.setTemporal(true); filter.setValue(1427997600000L); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{ "foxtrot-test-table-02-4-2015", "foxtrot-test-table-03-4-2015", "foxtrot-test-table-04-4-2015"}, indexes); }
@Test public void testGetIndicesGreaterEquals() throws Exception { TestRequest request = new TestRequest(); GreaterEqualFilter filter = new GreaterEqualFilter(); filter.setTemporal(true); filter.setValue(1427997600000L); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{ "foxtrot-test-table-02-4-2015", "foxtrot-test-table-03-4-2015", "foxtrot-test-table-04-4-2015"}, indexes); }
@Test public void testGetIndicesLessThan() throws Exception { TestRequest request = new TestRequest(); LessThanFilter filter = new LessThanFilter(); filter.setTemporal(true); filter.setValue(1427997600000L); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{"foxtrot-test-table-*"}, indexes); }
@Test public void testGetIndicesLessThanEquals() throws Exception { TestRequest request = new TestRequest(); LessThanFilter filter = new LessThanFilter(); filter.setTemporal(true); filter.setValue(1427997600000L); request.setFilters(Collections.<Filter>singletonList(filter)); String indexes[] = ElasticsearchUtils.getIndices("test", request, new PeriodSelector(request.getFilters()).analyze(TEST_CURRENT_TIME)); System.out.println(Arrays.toString(indexes)); Assert.assertArrayEquals(new String[]{"foxtrot-test-table-*"}, indexes); }