@@ -47,15 +47,15 @@ func Example() {
47
47
// Handle error
48
48
panic (err )
49
49
}
50
- fmt .Printf ("Elasticsearch returned with code %d and version %s" , code , info .Version .Number )
50
+ fmt .Printf ("Elasticsearch returned with code %d and version %s\n " , code , info .Version .Number )
51
51
52
52
// Getting the ES version number is quite common, so there's a shortcut
53
53
esversion , err := client .ElasticsearchVersion ("http://127.0.0.1:9200" )
54
54
if err != nil {
55
55
// Handle error
56
56
panic (err )
57
57
}
58
- fmt .Printf ("Elasticsearch version %s" , esversion )
58
+ fmt .Printf ("Elasticsearch version %s\n " , esversion )
59
59
60
60
// Use the IndexExists service to check if a specified index exists.
61
61
exists , err := client .IndexExists ("twitter" ).Do (context .Background ())
@@ -65,7 +65,46 @@ func Example() {
65
65
}
66
66
if ! exists {
67
67
// Create a new index.
68
- createIndex , err := client .CreateIndex ("twitter" ).Do (context .Background ())
68
+ mapping := `
69
+ {
70
+ "settings":{
71
+ "number_of_shards":1,
72
+ "number_of_replicas":0
73
+ },
74
+ "mappings":{
75
+ "_default_": {
76
+ "_all": {
77
+ "enabled": true
78
+ }
79
+ },
80
+ "tweet":{
81
+ "properties":{
82
+ "user":{
83
+ "type":"keyword"
84
+ },
85
+ "message":{
86
+ "type":"text",
87
+ "store": true,
88
+ "fielddata": true
89
+ },
90
+ "retweets":{
91
+ "type":"long"
92
+ },
93
+ "tags":{
94
+ "type":"keyword"
95
+ },
96
+ "location":{
97
+ "type":"geo_point"
98
+ },
99
+ "suggest_field":{
100
+ "type":"completion"
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ `
107
+ createIndex , err := client .CreateIndex ("twitter" ).Body (mapping ).Do (context .Background ())
69
108
if err != nil {
70
109
// Handle error
71
110
panic (err )
@@ -178,7 +217,7 @@ func Example() {
178
217
179
218
// Update a tweet by the update API of Elasticsearch.
180
219
// We just increment the number of retweets.
181
- script := elastic .NewScript ("ctx._source.retweets += num" ).Param ("num" , 1 )
220
+ script := elastic .NewScript ("ctx._source.retweets += params. num" ).Param ("num" , 1 )
182
221
update , err := client .Update ().Index ("twitter" ).Type ("tweet" ).Id ("1" ).
183
222
Script (script ).
184
223
Upsert (map [string ]interface {}{"retweets" : 0 }).
0 commit comments