ElasticsearchUtils { public static String getIndices(final String table) { return String.format("%s-%s-%s-*", getTableNamePrefix(), table, ElasticsearchUtils.TABLENAME_POSTFIX); } private  ElasticsearchUtils(); @VisibleForTesting static String getTableNamePrefix(); static void setTableNamePrefix(ElasticsearchConfig config); 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(); static void initializeMappings(Client client); static String getValidTableName(String table); static DateTime parseIndexDate(String index, String table); static String getTableNameFromIndex(String currentIndex); static String getTodayIndicesPattern(); static boolean isTimeFilterPresent(List<Filter> filters); static final String DOCUMENT_TYPE_NAME; static final String DOCUMENT_META_FIELD_NAME; static final String DOCUMENT_META_TIMESTAMP_FIELD_NAME; static final String TIME_FIELD; static final int DEFAULT_SUB_LIST_SIZE; }
@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); }