首页 > 解决方案 > 如何在弹性搜索中查询特定的索引列表

问题描述

我正在创建基于日期的弹性索引,例如-logs-2017-06-10、logs-2018-07-10、logs-2019-06-11,日期后缀可以是任何有效日期。

如何将我的搜索查询限制为仅搜索特定日期索引。

例如,如果我想在 2018 年 6 月 9 日到 2018 年 6 月 11 日之间进行搜索,那么只有下面提到的索引应该针对我的查询进行搜索

logs-2018-06-09, logs-2018-06-10 and logs-2018-06-11

我尝试了通配符 * 但在这里没有帮助。

logs-2018-06-*logs-2018-06-01 to logs-2018-06-30将在不是我查询的索引中搜索。

我怎么能只限制它 logs-2018-06-09,logs-2018-06-10 and logs-2018-06-11

标签: elasticsearch

解决方案


GET /_search
{
    "query": {
        "indices" : {
            "indices" : ["index1", "index2"],
            "query" : { "term" : { "tag" : "wow" } },
            "no_match_query" : { "term" : { "tag" : "kow" } }
        }
    }
}

来自:https ://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-indices-query.html


推荐阅读