-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathes_setup.go
105 lines (83 loc) · 1.92 KB
/
es_setup.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
_ "github.com/mattn/go-sqlite3"
)
var ES_PATH = "http://localhost:9200/"
func main() {
type Attachment struct {
Field string `json:"field"`
IndexedChars int64 `json:"indexed_chars"`
}
type Processors struct {
Attachment Attachment `json:"attachment"`
}
type AttachmentStruct struct {
Description string `json:"description"`
Processors []Processors `json:"processors"`
}
// Init Elasticsearch attachment
attachment := &AttachmentStruct{
Description: "Process documents",
Processors: []Processors{
Processors{
Attachment: Attachment{
Field: "thedata",
IndexedChars: -1,
},
},
},
}
fmt.Println(attachment)
b, err := json.Marshal(attachment)
CheckError(err)
fmt.Println(b)
PutJSON(ES_PATH+"_ingest/pipeline/attachment", b)
type Settings struct {
NumberOfShards int64 `json:"number_of_shards"`
NumberOfReplicas int64 `json:"number_of_replicas"`
}
type IndexStruct struct {
Settings Settings `json:"settings"`
}
// Init Elasticsearch index
index := &IndexStruct{
Settings{
NumberOfShards: 4,
NumberOfReplicas: 0,
},
}
b, err = json.Marshal(index)
CheckError(err)
fmt.Println(b)
PutJSON(ES_PATH+"lr_index", b)
// Open sqlite3 database
db, err := sql.Open("sqlite3", "./libreread.db")
CheckError(err)
stmt, err := db.Prepare("update user set full_text_search=? where id=?")
CheckError(err)
_, err = stmt.Exec(1, 1)
CheckError(err)
db.Close()
}
func CheckError(err error) {
if err != nil {
panic(err)
}
}
var myClient = &http.Client{Timeout: 10 * time.Second}
func PutJSON(url string, message []byte) {
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(message))
CheckError(err)
res, err := myClient.Do(req)
CheckError(err)
content, err := ioutil.ReadAll(res.Body)
CheckError(err)
fmt.Println(string(content))
}