【问题标题】:Python API for Elastic Search - Getting 10000 in response every time用于弹性搜索的 Python API - 每次响应 10000
【发布时间】:2019-12-28 00:10:23
【问题描述】:
client = Elasticsearch([host1, host2], http_auth=(user, password), scheme="http", port=port)
response = client.search(index="complats*", body={"from": 0, "size": 10000, "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "query": "tags:\"prod\" AND severity:\"INFO\" AND service:\"abc-service\" AND msg:\"* is processed\"",
                            "fields": [],
                            "type": "best_fields",
                            "default_operator": "or",
                            "max_determinized_states": 10000,
                            "enable_position_increments": "true",
                            "fuzziness": "AUTO",
                            "fuzzy_prefix_length": 0,
                            "fuzzy_max_expansions": 50,
                            "phrase_slop": 0,
                            "escape": "false",
                            "auto_generate_synonyms_phrase_query": "true",
                            "fuzzy_transpositions": "true",
                            "boost": 1.0
                        }
                    },
                    {
                        "range": {
                            "@timestamp": {
                                "from": "now-{}s".format((now.minute + 1) * 60),
                                "to": "now",
                                "include_lower": "true",
                                "include_upper": "true",
                                "boost": 1.0
                            }
                        }
                    }
                ],
                "adjust_pure_negative": "true",
                "boost": 1.0
            }
        }})
value = response['hits']['total']['value']
print(value)

上述查询成功连接到elasticsearch,但每次都返回错误的值或10000。这里有什么问题?我在某处读过python中的elasticsearch模块有一个错误,它的最大值为10000。还有其他人遇到过这个问题吗?如果是,你是如何解决的? 提前致谢!

【问题讨论】:

  • 更改“max_determinized_states”:10000 没有帮助,它仍然返回相同的值。

标签: python elasticsearch kibana


【解决方案1】:

这不是 python 库错误,不能返回超过 10000 个结果是从 lucene 继承的设置。如果您需要更多结果,您应该使用search_after 查询进行分页,或使用scroll 查询进行单次重度搜索,这取决于您的用例。查看我的回复here 以查看使用 python 实现这些查询的示例

【讨论】:

    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-08
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    相关资源
    最近更新 更多