在 python 中过滤以进行弹性搜索

filtering in python for elastic search

我正在尝试过滤掉弹性搜索查询以创建 pandas 数据框。我在应用过滤器的数据框中有两列 "type" 和 "api"。当我应用一列作为条件时,它工作正常..:-

result_dict = es.search(index="logstash-2018.08.11-alias", 
              body={"from": 0, "size": 10000,"query": 
              {"term" : {"type":"vx_apache_json"}}})

但是当我应用如下多个条件时:-

result_dict = es.search(index="logstash-2018.08.11-alias", body={"from": 0, "size": 1000,"queries": [
        { "term" : {"type" :"vx_apache_json"}},
        { "term" : {"api" :"viv_signin.php"}}
      ]})

我收到以下错误:-

RequestError: RequestError(400, 'parsing_exception', 'Unknown key for a START_ARRAY in [queries].')

有人可以帮助我吗,比如我如何在弹性搜索中进行多重过滤。

试试下面的代码:-

result_dict = es.search(index="logstash-2018.08.11-alias", body={"from": 0, "size": 1000,"query": {
        "constant_score" : {
            "filter" : {
                 "bool" : {
                    "must" : [
                        { "term" : { "type" :"vx_apache_json" } }, 
                        {"term"  :{ "api" :"viv_signin.php" }}
                    ]
                }
            }
        }
    }
  }
)

并以同样的方式继续添加您的过滤器。