0

Below is an example of indices in Jan 2015, similar indices in other months/years. Indices are created based on date but it's not necessary to have indices for everyday.

abc-2015.01.01
abc-2015.01.04
abc-2015.01.14
abc-2015.01.28
abc-2015.01.31

I am trying to query all the existing indices in a time range, for example, all the indices in 2015, we may do curl -XGET 'http://localhost:9200/abc-2015*/_aliases/'

but how about querying From Jan 13,2015 to Feb, 28 2015? we may do curl -XGET 'http://localhost:9200/abc-2015-01*,abc-2015-02*/_aliases/'

However, it returns the indices outside of the range in Jan and Feb as well. What is the best way to query all the existing indices efficiently?

androidkc
  • 689
  • 2
  • 7
  • 16
  • Querying for `abc-2015.01*,abc-2015.02*` will only query outside the range in January (basically from 2015.01.01 to 2015.01.12). I did not understand how it queries out of range in the month of Feb. Your requirement is to search on all days in Feb. Can you please clarify? – bittusarkar Jun 18 '15 at 05:00
  • @bsarkar, you were right, only January is out of rang but not Feb. I thought I used not the last day of Feb as an example. sorry for the confusion. The requirement is to query all the existing indices in the time range given by users, which could be any. – androidkc Jun 18 '15 at 05:32
  • 1
    If you have control over your document structure, having a datetime field with index creation date as value might make your job easier. Filtering on the value of a field is a much better design than filtering on index name IMO. – bittusarkar Jun 18 '15 at 05:39
  • @bsarkar, we do have a dateime field for time range query. As cross indices search could be expensive, before getting into the actual time range search, we are trying to specify the indices in the url to improve the performance. For example, for querying the time range in [Jan 1st, 2015~ Jan 31,2015], it's expected that {localhost:9200/abc*/_search} slower than {localhost:9200/abc-2015.01*/_search} – androidkc Jun 18 '15 at 06:01
  • It won't be as expensive as you think. In fact, you can use the best of both options - Have a filtered query with range filter over the requested time range and query over only those indices whose month matches the requested time range. In this example, you can query over the indices `abc-2015.01.*` and `abc-2015.02.*` and the filtered query will have a range filter from 2015-01-13 to 2015-02-28. – bittusarkar Jun 18 '15 at 06:13

1 Answers1

1

The easiest way to query in indices between 2015-01-13 to 2015-02-28 AFAIK is as under: http://localhost:9200/abc-2015.01.13,abc-2015.01.14,abc-2015.01.15,abc-2015.01.16,abc-2015.01.17,abc-2015.01.18,abc-2015.01.19,abc-2015.01.2*,abc-2015.01.3*,abc-2015.02.*/_aliases/.

bittusarkar
  • 6,247
  • 3
  • 30
  • 50