gpt4 book ai didi

angularjs - 跨多个索引的 Elasticsearch 搜索 - 忽略不存在的索引

转载 作者:行者123 更新时间:2023-12-01 11:24:38 24 4
gpt4 key购买 nike

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

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

是否可以跨多个索引进行查询,忽略不存在的索引。例如这个 作品 :
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"], //this doesn't exist
],
...
});

我希望第二个示例仅从 25 日起返回文档。

最佳答案

如果您使用像 example-idex-2016-07-* 这样的通配符你不需要关心这个,ES 会找出匹配的索引。

如果你真的想枚举索引,你可以指定 ignoreUnavailable: true 在您的 search称呼:

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

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

关于angularjs - 跨多个索引的 Elasticsearch 搜索 - 忽略不存在的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38591187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com