Elasticsearch DSL查询——获取所有匹配的结果
Elasticsearch DSL query - Get all matching results
我正在尝试使用 DSL 查询来搜索索引。我有很多符合日志标准和时间戳范围的文档。
我正在传递日期并将其转换为纪元毫秒。
但我在 DSL 查询中指定了大小参数。
我看到的是,如果我指定 5000,它会提取时间范围内的 5000 条记录。但是指定时间范围内的记录数较多
如何检索与时间范围匹配的所有数据,以便我不需要指定大小?
我的 DSL 查询如下。
GET localhost:9200/_search
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
},
"size":5000
}
起始日期 = 1519842600000
截止日期 = 1520533800000
我无法进行扫描 API 或滚动模式工作,因为它也没有显示预期的结果。
我终于想出了一种方法来捕获点击次数,然后将其作为参数传递以提取数据。
GET localhost:9200/_count
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
}
}' > count_size.txt
size_count=`cat count_size.txt | cut -d "," -f1 | cut -d ":" -f2`
echo "Total hits matching this criteria is ${size_count}"
由此我得到 size_count 值。
如果此值小于10000,则提取该值,否则缩小提取时间范围。
GET localhost:9200/_search
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
},
"size":'"${size_count}"'
}
如果长时间需要大量数据,我需要 运行 使用一组不同的日期并将它们组合在一起以获得所需的总体报告。
这段完整的代码是shell脚本编写的,所以我可以更简单地使用它。
我正在尝试使用 DSL 查询来搜索索引。我有很多符合日志标准和时间戳范围的文档。
我正在传递日期并将其转换为纪元毫秒。
但我在 DSL 查询中指定了大小参数。
我看到的是,如果我指定 5000,它会提取时间范围内的 5000 条记录。但是指定时间范围内的记录数较多
如何检索与时间范围匹配的所有数据,以便我不需要指定大小?
我的 DSL 查询如下。
GET localhost:9200/_search
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
},
"size":5000
}
起始日期 = 1519842600000
截止日期 = 1520533800000
我无法进行扫描 API 或滚动模式工作,因为它也没有显示预期的结果。
我终于想出了一种方法来捕获点击次数,然后将其作为参数传递以提取数据。
GET localhost:9200/_count
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
}
}' > count_size.txt
size_count=`cat count_size.txt | cut -d "," -f1 | cut -d ":" -f2`
echo "Total hits matching this criteria is ${size_count}"
由此我得到 size_count 值。 如果此值小于10000,则提取该值,否则缩小提取时间范围。
GET localhost:9200/_search
{
"query": {
"bool": {
"must": [
{"match_phrase": {
"log": "SOME_VALUE"
}
},
{"range": {
"@timestamp": {
"gte": "'"${fromDate}"'",
"lte": "'"${toDate}"'",
"format": "epoch_millis"
}
}
}
]
}
},
"size":'"${size_count}"'
}
如果长时间需要大量数据,我需要 运行 使用一组不同的日期并将它们组合在一起以获得所需的总体报告。
这段完整的代码是shell脚本编写的,所以我可以更简单地使用它。