弹性搜索跨多个索引搜索 - 忽略不存在的索引 [英] Elasticsearch search across multiple indexes - ignore non-existing indexes

查看:159
本文介绍了弹性搜索跨多个索引搜索 - 忽略不存在的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹性集群,我的索引包含当前的日期 - 例如:

  example-idex-20167-26 - >存在
example-idex-2016-07-25 - >存在
example-idex-2016-07-24 - >不存在(周末)
...

是否可以跨多个查询索引,忽略不存在的索引。例如这个 WORKS

  return elastic.search({
index:[
example-idex-2016-07-26,
example-idex-2016-07-25],
],
...
} );

而这个抛出一个404

  return elastic.search({
index:[
example-idex-2016-07-25,
example-idex-2016-07-24],//这不存在
],
...
});

我希望第二个例子只能从第25页返回文档。

解决方案

如果您使用通配符,例如 example-idex-2016-07 - * ,则不需要关心这个和ES将找出匹配的指标。



如果您真的想枚举索引,您可以指定搜索中的多重index.htmlrel =nofollow> ignoreUnavailable:true

  return elastic.search({
index:[
example-idex-chalk7- 25,
example-idex-2016-07-24],//这不存在
],
ignoreUnavailable:true,
...
});

或者,您也可以使用索引别名并仅查询该别名。创建新的索引时,您还将该别名添加到索引。好的是,您的客户端代码不需要更改,并且将始终仅查询别名,即隐式具有该别名的所有索引。


I have elastic cluster where my indexes contain the current date - e.g:

example-idex-2016-07-26 --> exists
example-idex-2016-07-25 --> exists
example-idex-2016-07-24 --> doesn't exist (weekend)
...

Is it possible to query across multiple indexes, ignoring ones that don't exist. For example this WORKS:

return elastic.search({
        index: [
            "example-idex-2016-07-26",
            "example-idex-2016-07-25"],
        ],
        ...
});

Whereas this throws back a 404:

return elastic.search({
        index: [
            "example-idex-2016-07-25",
            "example-idex-2016-07-24"], //this doesn't exist
        ],
        ...
});

I would expect the second example to return documents from 25th only.

解决方案

If you use a wildcard like example-idex-2016-07-* you don't need to care about this and ES will figure out the matching indices.

If you really want to enumerate indices you can specify ignoreUnavailable: true in your search call:

return elastic.search({
        index: [
            "example-idex-2016-07-25",
            "example-idex-2016-07-24"], //this doesn't exist
        ],
        ignoreUnavailable: true,
        ...
});

Alternatively, you can also use index aliases and query only that alias. When creating a new index, you also add that alias to the index. The good thing about this is that your client code doesn't need to be changed and will always only query the alias, i.e. implicitly all indices having that alias.

这篇关于弹性搜索跨多个索引搜索 - 忽略不存在的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆