简体   繁体   English

对具有某些日期范围的索引进行弹性搜索查询

[英]Elastic search query on indices with some date range

I have below scenario:我有以下场景:

I have following indices in elastic search.我在弹性搜索中有以下索引。

  • index-2016.04.10索引-2016.04.10
  • index-2016.04.11索引-2016.04.11
  • index-2016.04.12索引-2016.04.12
  • index-2016.04.15索引-2016.04.15
  • index-2016.04.16索引-2016.04.16
  • index-2016.04.18索引-2016.04.18

Now suppose , I want to search some data in elastic search between dates - 2016.04.11 to 2016.04.16.现在假设,我想在日期之间的弹性搜索中搜索一些数据 - 2016.04.11 到 2016.04.16。 My questions are:我的问题是:

  1. Do we have any way to run a single query and define some filter parameters so that the search will happen only in the indices between these two dates ?我们有没有办法运行单个查询并定义一些过滤器参数,以便仅在这两个日期之间的索引中进行搜索?

  2. If not, then how can we optimize the search query If we need to search the data in some range of indices ?如果不是,那么我们如何优化搜索查询 如果我们需要在某个索引范围内搜索数据?

  3. Java implementation. Java 实现。

Please help..请帮忙..

I see two options.我看到两个选项。

You specify indexes when you search such as您在搜索时指定索引,例如

GET /index-2016.04.10,index-2016.04.11,index-2016.04.12/_search?ignore_unavailable=true
{
    "query": {
        yourquery
    }
}

Or Filter in query (But this approach could be slow, and depends on amount of indexes could throw shard exception, since you will query all indexes which match pattern)或在查询中过滤(但这种方法可能很慢,并且取决于索引的数量可能会引发分片异常,因为您将查询与模式匹配的所有索引)

GET /index-*/_search
{
    "query": {
        "terms" : {
            "_index" : ["index1", "index2"]
        }
    }
}

I assume you will be indexing data in the past like last 7, 14, 30 days: so in this case i would definitely go with first approach, do index name calculation in your app我假设您将像过去 7、14、30 天一样索引过去的数据:所以在这种情况下,我肯定会采用第一种方法,在您的应用程序中进行索引名称计算

UPDATE 1: To prevent error for non existing indicies you can set flag ignore_unavailable更新 1:为了防止不存在的索引出错,您可以设置标志ignore_unavailable

UPDATE 2: Well i you need to do search in the past one of the solution could be haveing an agregation job.更新 2:嗯,我需要在过去进行搜索,解决方案之一可能是进行聚合工作。

In ES there is reindex api在 ES 中有reindex api

POST _reindex
{
  "source": {
    "index": ["twitter", "blog"]
  },
  "dest": {
    "index": "all_together"
  }
}

You will have daily index up to 7 days.您将拥有最多 7 天的每日索引。 Then on Monday 0:0 you aggregate data to weekly index.然后在星期一 0:0 将数据聚合到每周索引。

You will have weekly up to 5 indexes.您每周将拥有多达 5 个索引。 Again last day of the month you reindex to monthly index.再次重新索引到月度索引的当月最后一天。

In query you combine multiple approach by providing which indexes you want to search and query filter.在查询中,您可以通过提供要搜索的索引和查询过滤器来组合多种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM