1

I am trying to filter out the elastic search query to create a pandas dataframe. I have two columns "type" and "api" in the dataframe on which iam applying filter. When I am applying one column as condition it is working fine..:-

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

But when i am applying multiple condition like below :-

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

I am getting the below error :-

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

Can someone help me here like how i can put multiple filtering in elastic search.

1 Answer 1

2

Try the below code:-

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

And in the same way keep adding your filters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.