nodejs elasticsearch查询默认行为
每天,我将数据(Time_Series)推向Elasticsearch。我创建了一个索引模式,并且我的索引具有名称:myIndex_ *,今天 *的日期(已设置了索引模式)。因此,一周后,我有:myIndex_2022-06-20
,myIndex_2022-06-21
... myIndex_2022-06-27
。
假设我的指数是索引产品的价格。因此,在每个myIndex _*
中,我得到了:
myindex_2022-06-26 is including many products prices like this:
{
"reference_code": "123456789",
"price": 10.00
},
...
myindex_2022-06-27:
{
"reference_code": "123456789",
"price": 12.00
},
我正在使用此查询来获取参考代码和相应的价格。而且效果很好。
const data = await elasticClient.search({
index: myindex_2022-06-27,
body: {
query: {
match: {
"reference_code": "123456789"
}
}
}
});
但是,我想查询一个查询,如果在2022-06-27的索引中,没有数据,则在上一个索引2022-06-26中检查,等等(直到EG 10X) 。
不确定,但是当我用myIndex_*替换MyIndex_2022-06-27时,似乎正在这样做(不确定这是默认行为)。
问题是,当我使用这种方式时,我从其他索引中获得了价格,但似乎使用了最古老的索引。我想取得最新的方式,从而相反。
我应该如何继续?
On a daily basis, I'm pushing data (time_series) to Elasticsearch. I created an index pattern, and my index have the name: myindex_* , where * is today date (an index pattern has been setup). Thus after a week, I have: myindex_2022-06-20
, myindex_2022-06-21
... myindex_2022-06-27
.
Let's assume my index is indexing products' prices. Thus inside each myindex_*
, I have got:
myindex_2022-06-26 is including many products prices like this:
{
"reference_code": "123456789",
"price": 10.00
},
...
myindex_2022-06-27:
{
"reference_code": "123456789",
"price": 12.00
},
I'm using this query to get the reference code and the corresponding prices. And it works great.
const data = await elasticClient.search({
index: myindex_2022-06-27,
body: {
query: {
match: {
"reference_code": "123456789"
}
}
}
});
But, I would like to have a query that if in the index of the date 2022-06-27, there is no data, then it checks, in the previous index 2022-06-26, and so on (until e.g. 10x).
Not sure, but it seems it's doing this when I replace myindex_2022-06-27 by myindex_* (not sure it's the default behaviour).
The issue is that when I'm using this way, I got prices from other index but it seems to use the oldest one. I would like to get the newest one instead, thus the opposite way.
How should I proceed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用索引通配符查询,则应返回文档列表,其中每个文档将以
_INDEX
和_id
的方式包含一些元字段。您可以按
_index
进行排序,以使弹性搜索返回列表中[0]位置的最新文档。If you query with index wildcard, it should return a list of documents, where every document will include some meta fields as
_index
and_id
.You can sort by
_index
, to make elastic search return the latest document at position [0] in your list.