Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 217c9db

Browse files
committed
Fix type in tests
1 parent 844c7cb commit 217c9db

128 files changed

Lines changed: 1597 additions & 646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml.off

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ services:
1212
- docker
1313
before_install:
1414
- sudo sysctl -w vm.max_map_count=262144
15-
- docker run --rm -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:6.0.0-beta2 elasticsearch -Expack.security.enabled=false -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_
15+
- docker run --rm -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:6.0.0-rc1 elasticsearch -Expack.security.enabled=false -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_
1616
- sleep 30

CHANGELOG-6.0.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,7 @@ Only use `true` or `false` for boolean values, not `0` or `1` or `on` or `off`.
1212

1313
## Single Type Indices
1414

15-
Notice that 6.0 will default to single type indices, i.e. you may not use multiple
16-
types when e.g. adding an index with a mapping.
17-
18-
To enable multiple indices, specify index.mapping.single_type : false. Example:
19-
20-
```
21-
{
22-
"settings":{
23-
"number_of_shards":1,
24-
"number_of_replicas":0,
25-
"index.mapping.single_type" : false
26-
},
27-
"mappings":{
28-
"tweet":{
29-
"properties":{
30-
...
31-
}
32-
},
33-
"comment":{
34-
"_parent": {
35-
"type": "tweet"
36-
}
37-
},
38-
"order":{
39-
"properties":{
40-
...
41-
}
42-
}
43-
}
44-
}
45-
```
15+
Notice that 6.0 and future versions will default to single type indices, i.e. you may not use multiple types when e.g. adding an index with a mapping.
16+
17+
See [here for details](https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_what_are_mapping_types).
4618

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Andrew Dunham [@andrew-d](https://github.com/andrew-d)
2020
Andrew Gaul [@andrewgaul](https://github.com/andrewgaul)
2121
Andy Walker [@alaska](https://github.com/alaska)
2222
Arquivei [@arquivei](https://github.com/arquivei)
23+
arthurgustin [@arthurgustin](https://github.com/arthurgustin)
2324
Benjamin Fernandes [@LotharSee](https://github.com/LotharSee)
2425
Benjamin Zarzycki [@kf6nux](https://github.com/kf6nux)
2526
Braden Bassingthwaite [@bbassingthwaite-va](https://github.com/bbassingthwaite-va)
@@ -109,4 +110,5 @@ Wyndham Blanton [@wyndhblb](https://github.com/wyndhblb)
109110
Yarden Bar [@ayashjorden](https://github.com/ayashjorden)
110111
zakthomas [@zakthomas](https://github.com/zakthomas)
111112
singham [@zhaochenxiao90](https://github.com/zhaochenxiao90)
113+
@林 [@zplzpl](https://github.com/zplzpl)
112114
Roman Colohanin [@zuzmic](https://github.com/zuzmic)

README.md

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -121,101 +121,9 @@ The client connects to Elasticsearch on `http://127.0.0.1:9200` by default.
121121
You typically create one client for your app. Here's a complete example of
122122
creating a client, creating an index, adding a document, executing a search etc.
123123

124-
```go
125-
// Create a context
126-
ctx := context.Background()
127-
128-
// Create a client
129-
client, err := elastic.NewClient()
130-
if err != nil {
131-
// Handle error
132-
panic(err)
133-
}
134-
135-
// Create an index
136-
_, err = client.CreateIndex("twitter").Do(ctx)
137-
if err != nil {
138-
// Handle error
139-
panic(err)
140-
}
141-
142-
// Add a document to the index
143-
tweet := Tweet{User: "olivere", Message: "Take Five"}
144-
_, err = client.Index().
145-
Index("twitter").
146-
Type("tweet").
147-
Id("1").
148-
BodyJson(tweet).
149-
Refresh("true").
150-
Do(ctx)
151-
if err != nil {
152-
// Handle error
153-
panic(err)
154-
}
155-
156-
// Search with a term query
157-
termQuery := elastic.NewTermQuery("user", "olivere")
158-
searchResult, err := client.Search().
159-
Index("twitter"). // search in index "twitter"
160-
Query(termQuery). // specify the query
161-
Sort("user", true). // sort by "user" field, ascending
162-
From(0).Size(10). // take documents 0-9
163-
Pretty(true). // pretty print request and response JSON
164-
Do(ctx) // execute
165-
if err != nil {
166-
// Handle error
167-
panic(err)
168-
}
169-
170-
// searchResult is of type SearchResult and returns hits, suggestions,
171-
// and all kinds of other information from Elasticsearch.
172-
fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis)
173-
174-
// Each is a convenience function that iterates over hits in a search result.
175-
// It makes sure you don't need to check for nil values in the response.
176-
// However, it ignores errors in serialization. If you want full control
177-
// over iterating the hits, see below.
178-
var ttyp Tweet
179-
for _, item := range searchResult.Each(reflect.TypeOf(ttyp)) {
180-
if t, ok := item.(Tweet); ok {
181-
fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
182-
}
183-
}
184-
// TotalHits is another convenience function that works even when something goes wrong.
185-
fmt.Printf("Found a total of %d tweets\n", searchResult.TotalHits())
186-
187-
// Here's how you iterate through results with full control over each step.
188-
if searchResult.Hits.TotalHits > 0 {
189-
fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits)
190-
191-
// Iterate through results
192-
for _, hit := range searchResult.Hits.Hits {
193-
// hit.Index contains the name of the index
194-
195-
// Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
196-
var t Tweet
197-
err := json.Unmarshal(*hit.Source, &t)
198-
if err != nil {
199-
// Deserialization failed
200-
}
201-
202-
// Work with tweet
203-
fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
204-
}
205-
} else {
206-
// No hits
207-
fmt.Print("Found no tweets\n")
208-
}
209-
210-
// Delete the index again
211-
_, err = client.DeleteIndex("twitter").Do(ctx)
212-
if err != nil {
213-
// Handle error
214-
panic(err)
215-
}
216-
```
124+
An example is available [here](https://olivere.github.io/elastic/).
217125

218-
Here's a [link to a complete working example](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263).
126+
Here's a [link to a complete working example for v3](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263).
219127

220128
See the [wiki](https://github.com/olivere/elastic/wiki) for more details.
221129

bulk.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ func (s *BulkService) Do(ctx context.Context) (*BulkResponse, error) {
234234
}
235235

236236
// Get response
237-
res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
237+
res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
238+
Method: "POST",
239+
Path: path,
240+
Params: params,
241+
Body: body,
242+
ContentType: "application/x-ndjson",
243+
})
238244
if err != nil {
239245
return nil, err
240246
}
@@ -304,10 +310,12 @@ type BulkResponseItem struct {
304310
Type string `json:"_type,omitempty"`
305311
Id string `json:"_id,omitempty"`
306312
Version int64 `json:"_version,omitempty"`
307-
Status int `json:"status,omitempty"`
308313
Result string `json:"result,omitempty"`
314+
Shards *shardsInfo `json:"_shards,omitempty"`
315+
SeqNo int64 `json:"_seq_no,omitempty"`
316+
PrimaryTerm int64 `json:"_primary_term,omitempty"`
317+
Status int `json:"status,omitempty"`
309318
ForcedRefresh bool `json:"forced_refresh,omitempty"`
310-
Found bool `json:"found,omitempty"`
311319
Error *ErrorDetails `json:"error,omitempty"`
312320
}
313321

bulk_delete_request_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ func TestBulkDeleteRequestSerialization(t *testing.T) {
1515
}{
1616
// #0
1717
{
18-
Request: NewBulkDeleteRequest().Index("index1").Type("tweet").Id("1"),
18+
Request: NewBulkDeleteRequest().Index("index1").Type("doc").Id("1"),
1919
Expected: []string{
20-
`{"delete":{"_id":"1","_index":"index1","_type":"tweet"}}`,
20+
`{"delete":{"_id":"1","_index":"index1","_type":"doc"}}`,
2121
},
2222
},
2323
// #1
2424
{
25-
Request: NewBulkDeleteRequest().Index("index1").Type("tweet").Id("1").Parent("2"),
25+
Request: NewBulkDeleteRequest().Index("index1").Type("doc").Id("1").Parent("2"),
2626
Expected: []string{
27-
`{"delete":{"_id":"1","_index":"index1","_parent":"2","_type":"tweet"}}`,
27+
`{"delete":{"_id":"1","_index":"index1","_parent":"2","_type":"doc"}}`,
2828
},
2929
},
3030
// #2
3131
{
32-
Request: NewBulkDeleteRequest().Index("index1").Type("tweet").Id("1").Routing("3"),
32+
Request: NewBulkDeleteRequest().Index("index1").Type("doc").Id("1").Routing("3"),
3333
Expected: []string{
34-
`{"delete":{"_id":"1","_index":"index1","_routing":"3","_type":"tweet"}}`,
34+
`{"delete":{"_id":"1","_index":"index1","_routing":"3","_type":"doc"}}`,
3535
},
3636
},
3737
}
@@ -58,7 +58,7 @@ func TestBulkDeleteRequestSerialization(t *testing.T) {
5858
var bulkDeleteRequestSerializationResult string
5959

6060
func BenchmarkBulkDeleteRequestSerialization(b *testing.B) {
61-
r := NewBulkDeleteRequest().Index(testIndexName).Type("tweet").Id("1")
61+
r := NewBulkDeleteRequest().Index(testIndexName).Type("doc").Id("1")
6262
var s string
6363
for n := 0; n < b.N; n++ {
6464
s = r.String()

bulk_index_request_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,55 @@ func TestBulkIndexRequestSerialization(t *testing.T) {
1616
}{
1717
// #0
1818
{
19-
Request: NewBulkIndexRequest().Index("index1").Type("tweet").Id("1").
19+
Request: NewBulkIndexRequest().Index("index1").Type("doc").Id("1").
2020
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
2121
Expected: []string{
22-
`{"index":{"_id":"1","_index":"index1","_type":"tweet"}}`,
22+
`{"index":{"_id":"1","_index":"index1","_type":"doc"}}`,
2323
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
2424
},
2525
},
2626
// #1
2727
{
28-
Request: NewBulkIndexRequest().OpType("create").Index("index1").Type("tweet").Id("1").
28+
Request: NewBulkIndexRequest().OpType("create").Index("index1").Type("doc").Id("1").
2929
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
3030
Expected: []string{
31-
`{"create":{"_id":"1","_index":"index1","_type":"tweet"}}`,
31+
`{"create":{"_id":"1","_index":"index1","_type":"doc"}}`,
3232
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
3333
},
3434
},
3535
// #2
3636
{
37-
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("tweet").Id("1").
37+
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("doc").Id("1").
3838
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
3939
Expected: []string{
40-
`{"index":{"_id":"1","_index":"index1","_type":"tweet"}}`,
40+
`{"index":{"_id":"1","_index":"index1","_type":"doc"}}`,
4141
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
4242
},
4343
},
4444
// #3
4545
{
46-
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("tweet").Id("1").RetryOnConflict(42).
46+
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("doc").Id("1").RetryOnConflict(42).
4747
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
4848
Expected: []string{
49-
`{"index":{"_id":"1","_index":"index1","_retry_on_conflict":42,"_type":"tweet"}}`,
49+
`{"index":{"_id":"1","_index":"index1","_retry_on_conflict":42,"_type":"doc"}}`,
5050
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
5151
},
5252
},
5353
// #4
5454
{
55-
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("tweet").Id("1").Pipeline("my_pipeline").
55+
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("doc").Id("1").Pipeline("my_pipeline").
5656
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
5757
Expected: []string{
58-
`{"index":{"_id":"1","_index":"index1","_type":"tweet","pipeline":"my_pipeline"}}`,
58+
`{"index":{"_id":"1","_index":"index1","_type":"doc","pipeline":"my_pipeline"}}`,
5959
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
6060
},
6161
},
6262
// #5
6363
{
64-
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("tweet").Id("1").TTL("1m").
64+
Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("doc").Id("1").TTL("1m").
6565
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
6666
Expected: []string{
67-
`{"index":{"_id":"1","_index":"index1","_ttl":"1m","_type":"tweet"}}`,
67+
`{"index":{"_id":"1","_index":"index1","_ttl":"1m","_type":"doc"}}`,
6868
`{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
6969
},
7070
},
@@ -92,7 +92,7 @@ func TestBulkIndexRequestSerialization(t *testing.T) {
9292
var bulkIndexRequestSerializationResult string
9393

9494
func BenchmarkBulkIndexRequestSerialization(b *testing.B) {
95-
r := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("1").
95+
r := NewBulkIndexRequest().Index(testIndexName).Type("doc").Id("1").
9696
Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)})
9797
var s string
9898
for n := 0; n < b.N; n++ {

bulk_processor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestBulkProcessorBasedOnFlushInterval(t *testing.T) {
126126

127127
for i := 1; i <= numDocs; i++ {
128128
tweet := tweet{User: "olivere", Message: fmt.Sprintf("%d. %s", i, randomString(rand.Intn(64)))}
129-
request := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id(fmt.Sprintf("%d", i)).Doc(tweet)
129+
request := NewBulkIndexRequest().Index(testIndexName).Type("doc").Id(fmt.Sprintf("%d", i)).Doc(tweet)
130130
p.Add(request)
131131
}
132132

@@ -209,7 +209,7 @@ func TestBulkProcessorClose(t *testing.T) {
209209

210210
for i := 1; i <= numDocs; i++ {
211211
tweet := tweet{User: "olivere", Message: fmt.Sprintf("%d. %s", i, randomString(rand.Intn(64)))}
212-
request := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id(fmt.Sprintf("%d", i)).Doc(tweet)
212+
request := NewBulkIndexRequest().Index(testIndexName).Type("doc").Id(fmt.Sprintf("%d", i)).Doc(tweet)
213213
p.Add(request)
214214
}
215215

@@ -275,7 +275,7 @@ func TestBulkProcessorFlush(t *testing.T) {
275275

276276
for i := 1; i <= numDocs; i++ {
277277
tweet := tweet{User: "olivere", Message: fmt.Sprintf("%d. %s", i, randomString(rand.Intn(64)))}
278-
request := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id(fmt.Sprintf("%d", i)).Doc(tweet)
278+
request := NewBulkIndexRequest().Index(testIndexName).Type("doc").Id(fmt.Sprintf("%d", i)).Doc(tweet)
279279
p.Add(request)
280280
}
281281

@@ -356,7 +356,7 @@ func testBulkProcessor(t *testing.T, numDocs int, svc *BulkProcessorService) {
356356

357357
for i := 1; i <= numDocs; i++ {
358358
tweet := tweet{User: "olivere", Message: fmt.Sprintf("%07d. %s", i, randomString(1+rand.Intn(63)))}
359-
request := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id(fmt.Sprintf("%d", i)).Doc(tweet)
359+
request := NewBulkIndexRequest().Index(testIndexName).Type("doc").Id(fmt.Sprintf("%d", i)).Doc(tweet)
360360
p.Add(request)
361361
}
362362

0 commit comments

Comments
 (0)