Elasticsearch:访问由 filebeat 创建的多个索引
Elasticsearch: Accessing multiple indices created by filebeat
我使用的是 Elasticsearch 6.8,我无法在单个查询中访问多个索引。我读过 documentation and also previous questions,但出于某种原因我无法理解。
我认为设置相当标准。我有一个 filebeat 将日志推送到 elasticsearch。没有真正适应标准配置,所以 filebeat 每天都在创建一个新索引。我可以很好地查询每个索引以获取一天的所有结果:
# works, returns data from filebeat-6.1.2-2019.12.20
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# works, returns data from filebeat-6.1.2-2019.12.19
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
我现在正在尝试在一个查询中查询多个索引,一次获取不止一天的数据,但我总是只从索引文件beat-6.1.2.-2019.12 中获取数据。 19、不管我做什么。
# comma-separated list of indeces, nope.
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20,filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# _all, nope.
curl -X GET "https://whatever:9200/_all/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# just not specifying an index, nope nope nope.
curl -X GET "https://whatever:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
因为这应该根据我找到的所有资源工作,我觉得我错过了一些非常明显的东西。
FWIW,我来自 python 库 elasticsearch-dsl,在那里我遇到了完全相同的问题,但我在这个例子中使用了 curl,因为它是最通用的事情。因此,如果有人在这方面有答案,也将非常欢迎。
也许这只是您需要指定的尺寸。默认情况下,搜索查询 10 个结果。您是否尝试过增加此值?
您可以尝试在请求中的 "query" 之前添加 "size":"10000"。
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20,filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size":"10000",
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
我使用的是 Elasticsearch 6.8,我无法在单个查询中访问多个索引。我读过 documentation and also previous questions,但出于某种原因我无法理解。
我认为设置相当标准。我有一个 filebeat 将日志推送到 elasticsearch。没有真正适应标准配置,所以 filebeat 每天都在创建一个新索引。我可以很好地查询每个索引以获取一天的所有结果:
# works, returns data from filebeat-6.1.2-2019.12.20
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# works, returns data from filebeat-6.1.2-2019.12.19
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
我现在正在尝试在一个查询中查询多个索引,一次获取不止一天的数据,但我总是只从索引文件beat-6.1.2.-2019.12 中获取数据。 19、不管我做什么。
# comma-separated list of indeces, nope.
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20,filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# _all, nope.
curl -X GET "https://whatever:9200/_all/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
# just not specifying an index, nope nope nope.
curl -X GET "https://whatever:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}
'
因为这应该根据我找到的所有资源工作,我觉得我错过了一些非常明显的东西。
FWIW,我来自 python 库 elasticsearch-dsl,在那里我遇到了完全相同的问题,但我在这个例子中使用了 curl,因为它是最通用的事情。因此,如果有人在这方面有答案,也将非常欢迎。
也许这只是您需要指定的尺寸。默认情况下,搜索查询 10 个结果。您是否尝试过增加此值?
您可以尝试在请求中的 "query" 之前添加 "size":"10000"。
curl -X GET "https://whatever:9200/filebeat-6.1.2-2019.12.20,filebeat-6.1.2-2019.12.19/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size":"10000",
"query": {
"wildcard" : {
"nginx.access.url" : "/something/*"
}
}
}