@dhruvdutt/

Appbase.io - Python - search - compound

Python 2.7

Complex query combining two conditions together

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8353684026311032","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJlcXVlc3RzCmltcG9ydCBqc29uCmltcG9ydCBkZW1qc29uCgp1cmwgPSAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9ob3VzaW5nLWRlbW8vbGlzdGluZy9fc2VhcmNoIgoKcGF5bG9hZCA9IGRlbWpzb24uZW5jb2RlKHsKICAicXVlcnkiOiB7CiAgICAiYm9vbCI6IHsKICAgICAgIm11c3QiOiBbCiAgICAgICAgewogICAgICAgICAgIm1hdGNoIjogewogICAgICAgICAgICAicm9vbV90eXBlIjogInByaXZhdGUiCiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICB7CiAgICAgICAgICAicmFuZ2UiOiB7CiAgICAgICAgICAgICJwcmljZSI6IHsKICAgICAgICAgICAgICAiZ3RlIjogOTUsCiAgICAgICAgICAgICAgImx0ZSI6IDEwMAogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICBdCiAgICB9CiAgfQp9KQoKaGVhZGVycyA9IHsKICAnQXV0aG9yaXphdGlvbic6ICJCYXNpYyBXVzVEWjFaM2IzcFdPbVU1WldNMVkySXdMVFU0WkRndE5HSmlNQzFpWVdSakxXRmpZV1kzTWpZMk5qRm1NUT09IiwKICAnQ29udGVudC1UeXBlJzogImFwcGxpY2F0aW9uL2pzb24iCn0KCnJlc3BvbnNlID0gcmVxdWVzdHMucmVxdWVzdCgiUE9TVCIsIHVybCwgZGF0YT1wYXlsb2FkLCBoZWFkZXJzPWhlYWRlcnMpCgpwYXJzZWQgPSBqc29uLmxvYWRzKHJlc3BvbnNlLnRleHQpCnByaW50IGpzb24uZHVtcHMocGFyc2VkLCBpbmRlbnQ9Miwgc29ydF9rZXlzPVRydWUp"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import json
import demjson

url = "https://scalr.api.appbase.io/housing-demo/listing/_search"

payload = demjson.encode({
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "room_type": "private"
          }
        },
        {
          "range": {
            "price": {
              "gte": 95,
              "lte": 100
            }
          }
        }
      ]
    }
  }
})

headers = {
  'Authorization': "Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==",
  'Content-Type': "application/json"
}

response = requests.request("POST", url, data=payload, headers=headers)

parsed = json.loads(response.text)
print json.dumps(parsed, indent=2, sort_keys=True)