【问题标题】:filtering in python for elastic search在python中过滤以进行弹性搜索
【发布时间】:2019-01-29 00:37:30
【问题描述】:

我正在尝试过滤掉弹性搜索查询以创建熊猫数据框。我在应用过滤器的数据框中有两列“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].')

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

【问题讨论】:

    标签: python python-3.x python-2.7 elasticsearch elastic-stack


    【解决方案1】:

    试试下面的代码:-

    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" }}
                        ]
                    }
                }
            }
        }
      }
    )
    

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

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      相关资源
      最近更新 更多