【问题标题】:Elasticsearch: Accessing multiple indices created by filebeatElasticsearch:访问由 filebeat 创建的多个索引
【发布时间】:2019-12-20 08:44:55
【问题描述】:

我使用的是 Elasticsearch 6.8,但无法在单个查询中访问多个索引。我读过documentation 和以前的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,因为它是最通用的事情。所以如果有人有这个方向的答案,这也将非常受欢迎。

【问题讨论】:

    标签: elasticsearch filebeat elasticsearch-dsl elasticsearch-6


    【解决方案1】:

    也许这只是您需要指定的大小。默认情况下,搜索查询 10 结果。您是否尝试增加此值?

    您可以尝试在请求中的“查询”之前添加“大小”:“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/*"
            }
        }
    }
    

    【讨论】:

    • 是的,就是这样。我知道这将是愚蠢/明显的事情。非常感谢!
    猜你喜欢
    • 2019-02-04
    • 2021-04-25
    • 2022-01-18
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2018-09-01
    • 1970-01-01
    相关资源
    最近更新 更多