gpt4 book ai didi

coffeescript - 如何在 ElasticSearch 中组合多个查询

转载 作者:行者123 更新时间:2023-11-29 02:44:45 25 4
gpt4 key购买 nike

此处供引用的是代码。我正在尝试制作一个记录到 elasticsearch 的 hubot 插件,然后使用 hubot 命令搜索这些日志。

https://gist.github.com/4050748

我正在尝试检索匹配两个查询的记录。

{ 
query: {
match: {
user: "SomeUsername"
},
range: {
date: {
from: (Date.now() - 3600)
}
}
},
size: 50
}

我期待:

  • 最多 50 条记录
  • 具有给定用户的记录
  • 最近一小时的记录

我得到了:

  • 最多 10 条记录
  • 具有给定用户的记录
  • 从任何时候

如何获取过去一小时内某个用户名的所有记录?我需要将 match_all 与过滤器一起使用吗?我正在尝试的是不受支持的吗?

在 SQL 中它会是这样的:

Select (*) from messages where user_name = ? and time > ?

最佳答案

对于任何偶然发现这个问题并想知道在 ElasticSearch 中结合匹配和范围查询是什么样子的人,这个例子看起来像

curl 'localhost:9200/<index>/_search?pretty=true' -d '{
"query" : {
"bool": {
"must": [
{
"match": {
"user": "SomeUsername"
}
},
{
"range" : {
"date": {
"gt": "now-1h"
}
}
}
]
}
}
}'

关于coffeescript - 如何在 ElasticSearch 中组合多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13352146/

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