@dhruvdutt/

Appbase.io - Go - search - date

Go

Date query to get houses that are available between certain dates

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9479402622409228","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAogICJzdHJpbmdzIgogICJuZXQvaHR0cCIKICAiaW8vaW91dGlsIgogICJlbmNvZGluZy9qc29uIgogICJieXRlcyIKICAiZm10IgopCgpmdW5jIG1haW4oKSB7CgogIHVybCA6PSAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9ob3VzaW5nLWRlbW8vbGlzdGluZy9fc2VhcmNoIgoKICBwYXlsb2FkIDo9IHN0cmluZ3MuTmV3UmVhZGVyKGB7CiAgICAicXVlcnkiOiB7CiAgICAgICJib29sIjogewogICAgICAgICJtdXN0IjogWwogICAgICAgICAgewogICAgICAgICAgICAicmFuZ2UiOiB7CiAgICAgICAgICAgICAgImRhdGVfZnJvbSI6IHsKICAgICAgICAgICAgICAgICJndCI6IDIwMTcwMTAxCiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9LAogICAgICAgICAgewogICAgICAgICAgICAicmFuZ2UiOiB7CiAgICAgICAgICAgICAgImRhdGVfdG8iOiB7CiAgICAgICAgICAgICAgICAibHQiOiAyMDE3MDQzMAogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIF0KICAgICAgfQogICAgfQogIH1gKQoKICByZXEsIF8gOj0gaHR0cC5OZXdSZXF1ZXN0KCJQT1NUIiwgdXJsLCBwYXlsb2FkKQoKICByZXEuSGVhZGVyLkFkZCgiQXV0aG9yaXphdGlvbiIsICJCYXNpYyBXVzVEWjFaM2IzcFdPbVU1WldNMVkySXdMVFU0WkRndE5HSmlNQzFpWVdSakxXRmpZV1kzTWpZMk5qRm1NUT09IikKICByZXEuSGVhZGVyLkFkZCgiQ29udGVudC1UeXBlIiwgImFwcGxpY2F0aW9uL2pzb24iKQoKICByZXMsIF8gOj0gaHR0cC5EZWZhdWx0Q2xpZW50LkRvKHJlcSkKCiAgZGVmZXIgcmVzLkJvZHkuQ2xvc2UoKQogIGJvZHksIF8gOj0gaW91dGlsLlJlYWRBbGwocmVzLkJvZHkpCgogIC8vIHByZXR0aWZ5CiAgdmFyIHByZXR0eUpTT04gYnl0ZXMuQnVmZmVyCiAgZXJyb3IgOj0ganNvbi5JbmRlbnQoJnByZXR0eUpTT04sIGJvZHksICIiLCAiXHQiKQogIGlmIGVycm9yICE9IG5pbCB7CiAgICBmbXQuUHJpbnRsbigiSlNPTiBwYXJzZSBlcnJvcjogIiwgZXJyb3IpCiAgICByZXR1cm4KICB9CgogIGZtdC5QcmludGxuKHN0cmluZyhwcmV0dHlKU09OLkJ5dGVzKCkpKQoKfQ=="},"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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main

import (
  "strings"
  "net/http"
  "io/ioutil"
  "encoding/json"
  "bytes"
  "fmt"
)

func main() {

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

  payload := strings.NewReader(`{
    "query": {
      "bool": {
        "must": [
          {
            "range": {
              "date_from": {
                "gt": 20170101
              }
            }
          },
          {
            "range": {
              "date_to": {
                "lt": 20170430
              }
            }
          }
        ]
      }
    }
  }`)

  req, _ := http.NewRequest("POST", url, payload)

  req.Header.Add("Authorization", "Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==")
  req.Header.Add("Content-Type", "application/json")

  res, _ := http.DefaultClient.Do(req)

  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  // prettify
  var prettyJSON bytes.Buffer
  error := json.Indent(&prettyJSON, body, "", "\t")
  if error != nil {
    fmt.Println("JSON parse error: ", error)
    return
  }

  fmt.Println(string(prettyJSON.Bytes()))

}