小编Der*_*pos的帖子

ElasticSearch / Python 动态过滤器数量

我对编程很陌生,所以我的问题可能很愚蠢/容易做,但是:我需要根据用户输入在elasticsearch中创建多个过滤器

我的查询正文:

body = {
        "query": {
            "filtered": {
                "filter": {
                    "bool": {
                        "must": [
                            {"term": {name1: value1}},
                            {"term": {name2: value2}},
                            {"term": {name3: value3}},
                        ]
                    }
                }
            }
        },
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我需要有这些过滤器的动态数量

我尝试将查询构建到字符串中,然后在其中添加过滤器,但 es 不允许这样做,例如:

l = []
for i_type, name in convert.items():
    string = '{"term": {"' + i_type + '":"' + name + '"}},'
    l.append(string)
i_query = ''.join(l)
Run Code Online (Sandbox Code Playgroud)

当我在查询结构中使用列表/字符串时,我从服务器收到 404 错误

是否可以添加动态数量的过滤器?

python elasticsearch elasticsearch-plugin

4
推荐指数
1
解决办法
794
查看次数