How to use delete method of conn Package

Best Gauge code snippet using conn.delete

goes_test.go

Source:goes_test.go Github

copy

Full Screen

...126 c.Assert(resp, DeepEquals, &Response{Status: 404, Error: "IndexMissingException[[foobar] missing]"})127}128func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) {129 conn := NewConnection(ES_HOST, ES_PORT)130 indexName := "testdeleteindexexistingindex"131 _, err := conn.CreateIndex(indexName, map[string]interface{}{})132 c.Assert(err, IsNil)133 resp, err := conn.DeleteIndex(indexName)134 c.Assert(err, IsNil)135 expectedResponse := &Response{136 Acknowledged: true,137 Status: 200,138 }139 resp.Raw = nil140 c.Assert(resp, DeepEquals, expectedResponse)141}142func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) {143 conn := NewConnection(ES_HOST, ES_PORT)144 indexName := "testupdateindex"145 _, err := conn.CreateIndex(indexName, map[string]interface{}{})146 c.Assert(err, IsNil)147 _, err = conn.UpdateIndexSettings(indexName, map[string]interface{}{148 "index": map[string]interface{}{149 "number_of_replicas": 0,150 },151 })152 c.Assert(err, IsNil)153 _, err = conn.DeleteIndex(indexName)154 c.Assert(err, IsNil)155}156func (s *GoesTestSuite) TestRefreshIndex(c *C) {157 conn := NewConnection(ES_HOST, ES_PORT)158 indexName := "testrefreshindex"159 _, err := conn.CreateIndex(indexName, map[string]interface{}{})160 c.Assert(err, IsNil)161 _, err = conn.RefreshIndex(indexName)162 c.Assert(err, IsNil)163 _, err = conn.DeleteIndex(indexName)164 c.Assert(err, IsNil)165}166func (s *GoesTestSuite) TestOptimize(c *C) {167 conn := NewConnection(ES_HOST, ES_PORT)168 indexName := "testoptimize"169 conn.DeleteIndex(indexName)170 _, err := conn.CreateIndex(indexName, map[string]interface{}{})171 c.Assert(err, IsNil)172 // we must wait for a bit otherwise ES crashes173 time.Sleep(1 * time.Second)174 response, err := conn.Optimize([]string{indexName}, url.Values{"max_num_segments": []string{"1"}})175 c.Assert(err, IsNil)176 c.Assert(response.All.Indices[indexName].Primaries["docs"].Count, Equals, 0)177 _, err = conn.DeleteIndex(indexName)178 c.Assert(err, IsNil)179}180func (s *GoesTestSuite) TestBulkSend(c *C) {181 indexName := "testbulkadd"182 docType := "tweet"183 tweets := []Document{184 {185 Id: "123",186 Index: indexName,187 Type: docType,188 BulkCommand: BULK_COMMAND_INDEX,189 Fields: map[string]interface{}{190 "user": "foo",191 "message": "some foo message",192 },193 },194 {195 Id: nil,196 Index: indexName,197 Type: docType,198 BulkCommand: BULK_COMMAND_INDEX,199 Fields: map[string]interface{}{200 "user": "bar",201 "message": "some bar message",202 },203 },204 }205 conn := NewConnection(ES_HOST, ES_PORT)206 conn.DeleteIndex(indexName)207 _, err := conn.CreateIndex(indexName, nil)208 c.Assert(err, IsNil)209 response, err := conn.BulkSend(tweets)210 i := Item{211 Id: "123",212 Type: docType,213 Version: 1,214 Index: indexName,215 Status: 201, //201 for indexing ( https://issues.apache.org/jira/browse/CONNECTORS-634 )216 }217 c.Assert(response.Items[0][BULK_COMMAND_INDEX], Equals, i)218 c.Assert(err, IsNil)219 _, err = conn.RefreshIndex(indexName)220 c.Assert(err, IsNil)221 var query = map[string]interface{}{222 "query": map[string]interface{}{223 "match_all": map[string]interface{}{},224 },225 }226 searchResults, err := conn.Search(query, []string{indexName}, []string{}, url.Values{})227 c.Assert(err, IsNil)228 var expectedTotal uint64 = 2229 c.Assert(searchResults.Hits.Total, Equals, expectedTotal)230 extraDocId := ""231 checked := 0232 for _, hit := range searchResults.Hits.Hits {233 if hit.Source["user"] == "foo" {234 c.Assert(hit.Id, Equals, "123")235 checked++236 }237 if hit.Source["user"] == "bar" {238 c.Assert(len(hit.Id) > 0, Equals, true)239 extraDocId = hit.Id240 checked++241 }242 }243 c.Assert(checked, Equals, 2)244 docToDelete := []Document{245 {246 Id: "123",247 Index: indexName,248 Type: docType,249 BulkCommand: BULK_COMMAND_DELETE,250 },251 {252 Id: extraDocId,253 Index: indexName,254 Type: docType,255 BulkCommand: BULK_COMMAND_DELETE,256 },257 }258 response, err = conn.BulkSend(docToDelete)259 i = Item{260 Id: "123",261 Type: docType,262 Version: 2,263 Index: indexName,264 Status: 200, //200 for updates265 }266 c.Assert(response.Items[0][BULK_COMMAND_DELETE], Equals, i)267 c.Assert(err, IsNil)268 _, err = conn.RefreshIndex(indexName)269 c.Assert(err, IsNil)270 searchResults, err = conn.Search(query, []string{indexName}, []string{}, url.Values{})271 c.Assert(err, IsNil)272 expectedTotal = 0273 c.Assert(searchResults.Hits.Total, Equals, expectedTotal)274 _, err = conn.DeleteIndex(indexName)275 c.Assert(err, IsNil)276}277func (s *GoesTestSuite) TestStats(c *C) {278 conn := NewConnection(ES_HOST, ES_PORT)279 indexName := "teststats"280 conn.DeleteIndex(indexName)281 _, err := conn.CreateIndex(indexName, map[string]interface{}{})282 c.Assert(err, IsNil)283 // we must wait for a bit otherwise ES crashes284 time.Sleep(1 * time.Second)285 response, err := conn.Stats([]string{indexName}, url.Values{})286 c.Assert(err, IsNil)287 c.Assert(response.All.Indices[indexName].Primaries["docs"].Count, Equals, 0)288 _, err = conn.DeleteIndex(indexName)289 c.Assert(err, IsNil)290}291func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {292 indexName := "testindexwithfieldsinstruct"293 docType := "tweet"294 docId := "1234"295 conn := NewConnection(ES_HOST, ES_PORT)296 // just in case297 conn.DeleteIndex(indexName)298 _, err := conn.CreateIndex(indexName, map[string]interface{}{})299 c.Assert(err, IsNil)300 defer conn.DeleteIndex(indexName)301 d := Document{302 Index: indexName,303 Type: docType,304 Id: docId,305 Fields: struct {306 user string307 message string308 }{309 "foo",310 "bar",311 },312 }313 extraArgs := make(url.Values, 1)314 extraArgs.Set("ttl", "86400000")315 response, err := conn.Index(d, extraArgs)316 c.Assert(err, IsNil)317 expectedResponse := &Response{318 Status: 201,319 Index: indexName,320 Id: docId,321 Type: docType,322 Version: 1,323 }324 response.Raw = nil325 c.Assert(response, DeepEquals, expectedResponse)326}327func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) {328 indexName := "testindexwithfieldsnotinmaporstruct"329 docType := "tweet"330 docId := "1234"331 conn := NewConnection(ES_HOST, ES_PORT)332 // just in case333 conn.DeleteIndex(indexName)334 _, err := conn.CreateIndex(indexName, map[string]interface{}{})335 c.Assert(err, IsNil)336 defer conn.DeleteIndex(indexName)337 d := Document{338 Index: indexName,339 Type: docType,340 Id: docId,341 Fields: "test",342 }343 extraArgs := make(url.Values, 1)344 extraArgs.Set("ttl", "86400000")345 _, err = conn.Index(d, extraArgs)346 c.Assert(err, Not(IsNil))347}348func (s *GoesTestSuite) TestIndexIdDefined(c *C) {349 indexName := "testindexiddefined"350 docType := "tweet"351 docId := "1234"352 conn := NewConnection(ES_HOST, ES_PORT)353 // just in case354 conn.DeleteIndex(indexName)355 _, err := conn.CreateIndex(indexName, map[string]interface{}{})356 c.Assert(err, IsNil)357 defer conn.DeleteIndex(indexName)358 d := Document{359 Index: indexName,360 Type: docType,361 Id: docId,362 Fields: map[string]interface{}{363 "user": "foo",364 "message": "bar",365 },366 }367 extraArgs := make(url.Values, 1)368 extraArgs.Set("ttl", "86400000")369 response, err := conn.Index(d, extraArgs)370 c.Assert(err, IsNil)371 expectedResponse := &Response{372 Status: 201,373 Index: indexName,374 Id: docId,375 Type: docType,376 Version: 1,377 }378 response.Raw = nil379 c.Assert(response, DeepEquals, expectedResponse)380}381func (s *GoesTestSuite) TestIndexIdNotDefined(c *C) {382 indexName := "testindexidnotdefined"383 docType := "tweet"384 conn := NewConnection(ES_HOST, ES_PORT)385 // just in case386 conn.DeleteIndex(indexName)387 _, err := conn.CreateIndex(indexName, map[string]interface{}{})388 c.Assert(err, IsNil)389 defer conn.DeleteIndex(indexName)390 d := Document{391 Index: indexName,392 Type: docType,393 Fields: map[string]interface{}{394 "user": "foo",395 "message": "bar",396 },397 }398 response, err := conn.Index(d, url.Values{})399 c.Assert(err, IsNil)400 c.Assert(response.Index, Equals, indexName)401 c.Assert(response.Type, Equals, docType)402 c.Assert(response.Version, Equals, 1)403 c.Assert(response.Id != "", Equals, true)404}405func (s *GoesTestSuite) TestDelete(c *C) {406 indexName := "testdelete"407 docType := "tweet"408 docId := "1234"409 conn := NewConnection(ES_HOST, ES_PORT)410 // just in case411 conn.DeleteIndex(indexName)412 _, err := conn.CreateIndex(indexName, map[string]interface{}{})413 c.Assert(err, IsNil)414 defer conn.DeleteIndex(indexName)415 d := Document{416 Index: indexName,417 Type: docType,418 Id: docId,419 Fields: map[string]interface{}{420 "user": "foo",421 },422 }423 _, err = conn.Index(d, url.Values{})424 c.Assert(err, IsNil)425 response, err := conn.Delete(d, url.Values{})426 c.Assert(err, IsNil)427 expectedResponse := &Response{428 Status: 200,429 Found: true,430 Index: indexName,431 Type: docType,432 Id: docId,433 // XXX : even after a DELETE the version number seems to be incremented434 Version: 2,435 }436 response.Raw = nil437 c.Assert(response, DeepEquals, expectedResponse)438 response, err = conn.Delete(d, url.Values{})439 c.Assert(err, IsNil)440 expectedResponse = &Response{441 Status: 404,442 Found: false,443 Index: indexName,444 Type: docType,445 Id: docId,446 // XXX : even after a DELETE the version number seems to be incremented447 Version: 3,448 }449 response.Raw = nil450 c.Assert(response, DeepEquals, expectedResponse)451}452func (s *GoesTestSuite) TestDeleteByQuery(c *C) {453 indexName := "testdeletebyquery"454 docType := "tweet"455 docId := "1234"456 conn := NewConnection(ES_HOST, ES_PORT)457 // just in case458 conn.DeleteIndex(indexName)459 _, err := conn.CreateIndex(indexName, map[string]interface{}{})460 c.Assert(err, IsNil)461 defer conn.DeleteIndex(indexName)462 d := Document{463 Index: indexName,464 Type: docType,465 Id: docId,466 Fields: map[string]interface{}{467 "user": "foo",468 },469 }470 _, err = conn.Index(d, url.Values{})471 c.Assert(err, IsNil)472 _, err = conn.RefreshIndex(indexName)473 c.Assert(err, IsNil)474 query := map[string]interface{}{475 "query": map[string]interface{}{476 "bool": map[string]interface{}{477 "must": []map[string]interface{}{478 {479 "match_all": map[string]interface{}{},480 },481 },482 },483 },484 }485 //should be 1 doc before delete by query486 response, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})487 c.Assert(err, IsNil)488 c.Assert(response.Hits.Total, Equals, uint64(1))489 response, err = conn.Query(query, []string{indexName}, []string{docType}, "DELETE", url.Values{})490 c.Assert(err, IsNil)491 expectedResponse := &Response{492 Status: 200,493 Found: false,494 Index: "",495 Type: "",496 Id: "",497 Version: 0,498 }499 response.Raw = nil500 c.Assert(response, DeepEquals, expectedResponse)501 //should be 0 docs after delete by query502 response, err = conn.Search(query, []string{indexName}, []string{docType}, url.Values{})503 c.Assert(err, IsNil)504 c.Assert(response.Hits.Total, Equals, uint64(0))505}506func (s *GoesTestSuite) TestGet(c *C) {507 indexName := "testget"508 docType := "tweet"509 docId := "111"510 source := map[string]interface{}{511 "f1": "foo",512 "f2": "foo",513 }514 conn := NewConnection(ES_HOST, ES_PORT)515 conn.DeleteIndex(indexName)516 _, err := conn.CreateIndex(indexName, map[string]interface{}{})517 c.Assert(err, IsNil)518 defer conn.DeleteIndex(indexName)519 d := Document{520 Index: indexName,521 Type: docType,522 Id: docId,523 Fields: source,524 }525 _, err = conn.Index(d, url.Values{})526 c.Assert(err, IsNil)527 response, err := conn.Get(indexName, docType, docId, url.Values{})528 c.Assert(err, IsNil)529 expectedResponse := &Response{530 Status: 200,531 Index: indexName,532 Type: docType,533 Id: docId,534 Version: 1,535 Found: true,536 Source: source,537 }538 response.Raw = nil539 c.Assert(response, DeepEquals, expectedResponse)540 fields := make(url.Values, 1)541 fields.Set("fields", "f1")542 response, err = conn.Get(indexName, docType, docId, fields)543 c.Assert(err, IsNil)544 expectedResponse = &Response{545 Status: 200,546 Index: indexName,547 Type: docType,548 Id: docId,549 Version: 1,550 Found: true,551 Fields: map[string]interface{}{552 "f1": []interface{}{"foo"},553 },554 }555 response.Raw = nil556 c.Assert(response, DeepEquals, expectedResponse)557}558func (s *GoesTestSuite) TestSearch(c *C) {559 indexName := "testsearch"560 docType := "tweet"561 docId := "1234"562 source := map[string]interface{}{563 "user": "foo",564 "message": "bar",565 }566 conn := NewConnection(ES_HOST, ES_PORT)567 conn.DeleteIndex(indexName)568 _, err := conn.CreateIndex(indexName, map[string]interface{}{})569 c.Assert(err, IsNil)570 defer conn.DeleteIndex(indexName)571 d := Document{572 Index: indexName,573 Type: docType,574 Id: docId,575 Fields: source,576 }577 _, err = conn.Index(d, url.Values{})578 c.Assert(err, IsNil)579 _, err = conn.RefreshIndex(indexName)580 c.Assert(err, IsNil)581 // I can feel my eyes bleeding582 query := map[string]interface{}{583 "query": map[string]interface{}{584 "bool": map[string]interface{}{585 "must": []map[string]interface{}{586 {587 "match_all": map[string]interface{}{},588 },589 },590 },591 },592 }593 response, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})594 expectedHits := Hits{595 Total: 1,596 MaxScore: 1.0,597 Hits: []Hit{598 {599 Index: indexName,600 Type: docType,601 Id: docId,602 Score: 1.0,603 Source: source,604 },605 },606 }607 c.Assert(response.Hits, DeepEquals, expectedHits)608}609func (s *GoesTestSuite) TestCount(c *C) {610 indexName := "testcount"611 docType := "tweet"612 docId := "1234"613 source := map[string]interface{}{614 "user": "foo",615 "message": "bar",616 }617 conn := NewConnection(ES_HOST, ES_PORT)618 conn.DeleteIndex(indexName)619 _, err := conn.CreateIndex(indexName, map[string]interface{}{})620 c.Assert(err, IsNil)621 defer conn.DeleteIndex(indexName)622 d := Document{623 Index: indexName,624 Type: docType,625 Id: docId,626 Fields: source,627 }628 _, err = conn.Index(d, url.Values{})629 c.Assert(err, IsNil)630 _, err = conn.RefreshIndex(indexName)631 c.Assert(err, IsNil)632 // I can feel my eyes bleeding633 query := map[string]interface{}{634 "query": map[string]interface{}{635 "bool": map[string]interface{}{636 "must": []map[string]interface{}{637 {638 "match_all": map[string]interface{}{},639 },640 },641 },642 },643 }644 response, err := conn.Count(query, []string{indexName}, []string{docType}, url.Values{})645 c.Assert(response.Count, Equals, 1)646}647func (s *GoesTestSuite) TestIndexStatus(c *C) {648 indexName := "testindexstatus"649 conn := NewConnection(ES_HOST, ES_PORT)650 conn.DeleteIndex(indexName)651 mapping := map[string]interface{}{652 "settings": map[string]interface{}{653 "index.number_of_shards": 1,654 "index.number_of_replicas": 1,655 },656 }657 _, err := conn.CreateIndex(indexName, mapping)658 c.Assert(err, IsNil)659 defer conn.DeleteIndex(indexName)660 // gives ES some time to do its job661 time.Sleep(1 * time.Second)662 _, err = conn.RefreshIndex(indexName)663 c.Assert(err, IsNil)664 response, err := conn.IndexStatus([]string{"testindexstatus"})665 c.Assert(err, IsNil)666 expectedShards := Shard{Total: 2, Successful: 1, Failed: 0}667 c.Assert(response.Shards, Equals, expectedShards)668 primarySizeInBytes := response.Indices[indexName].Index["primary_size_in_bytes"].(float64)669 sizeInBytes := response.Indices[indexName].Index["size_in_bytes"].(float64)670 refreshTotal := response.Indices[indexName].Refresh["total"].(float64)671 c.Assert(primarySizeInBytes > 0, Equals, true)672 c.Assert(sizeInBytes > 0, Equals, true)673 c.Assert(refreshTotal > 0, Equals, true)674 expectedIndices := map[string]IndexStatus{675 indexName: {676 Index: map[string]interface{}{677 "primary_size_in_bytes": primarySizeInBytes,678 "size_in_bytes": sizeInBytes,679 },680 Translog: map[string]uint64{681 "operations": 0,682 },683 Docs: map[string]uint64{684 "num_docs": 0,685 "max_doc": 0,686 "deleted_docs": 0,687 },688 Merges: map[string]interface{}{689 "current": float64(0),690 "current_docs": float64(0),691 "current_size_in_bytes": float64(0),692 "total": float64(0),693 "total_time_in_millis": float64(0),694 "total_docs": float64(0),695 "total_size_in_bytes": float64(0),696 },697 Refresh: map[string]interface{}{698 "total": refreshTotal,699 "total_time_in_millis": float64(0),700 },701 Flush: map[string]interface{}{702 "total": float64(0),703 "total_time_in_millis": float64(0),704 },705 },706 }707 c.Assert(response.Indices, DeepEquals, expectedIndices)708}709func (s *GoesTestSuite) TestScroll(c *C) {710 indexName := "testscroll"711 docType := "tweet"712 tweets := []Document{713 {714 Id: nil,715 Index: indexName,716 Type: docType,717 BulkCommand: BULK_COMMAND_INDEX,718 Fields: map[string]interface{}{719 "user": "foo",720 "message": "some foo message",721 },722 },723 {724 Id: nil,725 Index: indexName,726 Type: docType,727 BulkCommand: BULK_COMMAND_INDEX,728 Fields: map[string]interface{}{729 "user": "bar",730 "message": "some bar message",731 },732 },733 {734 Id: nil,735 Index: indexName,736 Type: docType,737 BulkCommand: BULK_COMMAND_INDEX,738 Fields: map[string]interface{}{739 "user": "foo",740 "message": "another foo message",741 },742 },743 }744 conn := NewConnection(ES_HOST, ES_PORT)745 mapping := map[string]interface{}{746 "settings": map[string]interface{}{747 "index.number_of_shards": 1,748 "index.number_of_replicas": 0,749 },750 }751 defer conn.DeleteIndex(indexName)752 _, err := conn.CreateIndex(indexName, mapping)753 c.Assert(err, IsNil)754 _, err = conn.BulkSend(tweets)755 c.Assert(err, IsNil)756 _, err = conn.RefreshIndex(indexName)757 c.Assert(err, IsNil)758 query := map[string]interface{}{759 "query": map[string]interface{}{760 "filtered": map[string]interface{}{761 "filter": map[string]interface{}{762 "term": map[string]interface{}{763 "user": "foo",764 },765 },766 },767 },768 }769 scan, err := conn.Scan(query, []string{indexName}, []string{docType}, "1m", 1)770 c.Assert(err, IsNil)771 c.Assert(len(scan.ScrollId) > 0, Equals, true)772 searchResults, err := conn.Scroll(scan.ScrollId, "1m")773 c.Assert(err, IsNil)774 // some data in first chunk775 c.Assert(searchResults.Hits.Total, Equals, uint64(2))776 c.Assert(len(searchResults.ScrollId) > 0, Equals, true)777 c.Assert(len(searchResults.Hits.Hits), Equals, 1)778 searchResults, err = conn.Scroll(searchResults.ScrollId, "1m")779 c.Assert(err, IsNil)780 // more data in second chunk781 c.Assert(searchResults.Hits.Total, Equals, uint64(2))782 c.Assert(len(searchResults.ScrollId) > 0, Equals, true)783 c.Assert(len(searchResults.Hits.Hits), Equals, 1)784 searchResults, err = conn.Scroll(searchResults.ScrollId, "1m")785 c.Assert(err, IsNil)786 // nothing in third chunk787 c.Assert(searchResults.Hits.Total, Equals, uint64(2))788 c.Assert(len(searchResults.ScrollId) > 0, Equals, true)789 c.Assert(len(searchResults.Hits.Hits), Equals, 0)790}791func (s *GoesTestSuite) TestAggregations(c *C) {792 indexName := "testaggs"793 docType := "tweet"794 tweets := []Document{795 {796 Id: nil,797 Index: indexName,798 Type: docType,799 BulkCommand: BULK_COMMAND_INDEX,800 Fields: map[string]interface{}{801 "user": "foo",802 "message": "some foo message",803 "age": 25,804 },805 },806 {807 Id: nil,808 Index: indexName,809 Type: docType,810 BulkCommand: BULK_COMMAND_INDEX,811 Fields: map[string]interface{}{812 "user": "bar",813 "message": "some bar message",814 "age": 30,815 },816 },817 {818 Id: nil,819 Index: indexName,820 Type: docType,821 BulkCommand: BULK_COMMAND_INDEX,822 Fields: map[string]interface{}{823 "user": "foo",824 "message": "another foo message",825 },826 },827 }828 conn := NewConnection(ES_HOST, ES_PORT)829 mapping := map[string]interface{}{830 "settings": map[string]interface{}{831 "index.number_of_shards": 1,832 "index.number_of_replicas": 0,833 },834 }835 defer conn.DeleteIndex(indexName)836 _, err := conn.CreateIndex(indexName, mapping)837 c.Assert(err, IsNil)838 _, err = conn.BulkSend(tweets)839 c.Assert(err, IsNil)840 _, err = conn.RefreshIndex(indexName)841 c.Assert(err, IsNil)842 query := map[string]interface{}{843 "aggs": map[string]interface{}{844 "user": map[string]interface{}{845 "terms": map[string]interface{}{846 "field": "user",847 "order": map[string]interface{}{848 "_term": "asc",849 },850 },851 "aggs": map[string]interface{}{852 "age": map[string]interface{}{853 "stats": map[string]interface{}{854 "field": "age",855 },856 },857 },858 },859 "age": map[string]interface{}{860 "stats": map[string]interface{}{861 "field": "age",862 },863 },864 },865 }866 resp, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})867 user, ok := resp.Aggregations["user"]868 c.Assert(ok, Equals, true)869 c.Assert(len(user.Buckets()), Equals, 2)870 c.Assert(user.Buckets()[0].Key(), Equals, "bar")871 c.Assert(user.Buckets()[1].Key(), Equals, "foo")872 barAge := user.Buckets()[0].Aggregation("age")873 c.Assert(barAge["count"], Equals, 1.0)874 c.Assert(barAge["sum"], Equals, 30.0)875 fooAge := user.Buckets()[1].Aggregation("age")876 c.Assert(fooAge["count"], Equals, 1.0)877 c.Assert(fooAge["sum"], Equals, 25.0)878 age, ok := resp.Aggregations["age"]879 c.Assert(ok, Equals, true)880 c.Assert(age["count"], Equals, 2.0)881 c.Assert(age["sum"], Equals, 25.0+30.0)882}883func (s *GoesTestSuite) TestPutMapping(c *C) {884 indexName := "testputmapping"885 docType := "tweet"886 conn := NewConnection(ES_HOST, ES_PORT)887 // just in case888 conn.DeleteIndex(indexName)889 _, err := conn.CreateIndex(indexName, map[string]interface{}{})890 c.Assert(err, IsNil)891 defer conn.DeleteIndex(indexName)892 d := Document{893 Index: indexName,894 Type: docType,895 Fields: map[string]interface{}{896 "user": "foo",897 "message": "bar",898 },899 }900 response, err := conn.Index(d, url.Values{})901 c.Assert(err, IsNil)902 mapping := map[string]interface{}{903 "tweet": map[string]interface{}{904 "properties": map[string]interface{}{905 "count": map[string]interface{}{906 "type": "integer",907 "index": "not_analyzed",908 "store": true,909 },910 },911 },912 }913 response, err = conn.PutMapping("tweet", mapping, []string{indexName})914 c.Assert(err, IsNil)915 c.Assert(response.Acknowledged, Equals, true)916 c.Assert(response.TimedOut, Equals, false)917}918func (s *GoesTestSuite) TestIndicesExist(c *C) {919 indices := []string{"testindicesexist"}920 conn := NewConnection(ES_HOST, ES_PORT)921 // just in case922 conn.DeleteIndex(indices[0])923 exists, err := conn.IndicesExist(indices)924 c.Assert(exists, Equals, false)925 _, err = conn.CreateIndex(indices[0], map[string]interface{}{})926 c.Assert(err, IsNil)927 defer conn.DeleteIndex(indices[0])928 time.Sleep(200 * time.Millisecond)929 exists, err = conn.IndicesExist(indices)930 c.Assert(exists, Equals, true)931 indices = append(indices, "nonexistent")932 exists, err = conn.IndicesExist(indices)933 c.Assert(exists, Equals, false)934}935func (s *GoesTestSuite) TestUpdate(c *C) {936 indexName := "testupdate"937 docType := "tweet"938 docId := "1234"939 conn := NewConnection(ES_HOST, ES_PORT)940 // just in case941 conn.DeleteIndex(indexName)942 _, err := conn.CreateIndex(indexName, map[string]interface{}{})943 c.Assert(err, IsNil)944 defer conn.DeleteIndex(indexName)945 d := Document{946 Index: indexName,947 Type: docType,948 Id: docId,949 Fields: map[string]interface{}{950 "user": "foo",951 "message": "bar",952 "counter": 1,953 },954 }955 extraArgs := make(url.Values, 1)956 response, err := conn.Index(d, extraArgs)957 c.Assert(err, IsNil)958 time.Sleep(200 * time.Millisecond)959 expectedResponse := &Response{960 Status: 201,961 Index: indexName,962 Id: docId,963 Type: docType,964 Version: 1,965 }966 response.Raw = nil967 c.Assert(response, DeepEquals, expectedResponse)968 // Now that we have an ordinary document indexed, try updating it969 query := map[string]interface{}{970 "script": "ctx._source.counter += count",971 "lang": "groovy",972 "params": map[string]interface{}{973 "count": 5,974 },975 "upsert": map[string]interface{}{976 "message": "candybar",977 "user": "admin",978 "counter": 1,979 },980 }981 response, err = conn.Update(d, query, extraArgs)982 if err != nil && strings.Contains(err.(*SearchError).Msg, "dynamic scripting") {983 c.Skip("Scripting is disabled on server, skipping this test")984 return985 }986 time.Sleep(200 * time.Millisecond)987 c.Assert(err, Equals, nil)988 response, err = conn.Get(indexName, docType, docId, url.Values{})989 c.Assert(err, Equals, nil)990 c.Assert(response.Source["counter"], Equals, float64(6))991 c.Assert(response.Source["user"], Equals, "foo")992 c.Assert(response.Source["message"], Equals, "bar")993 // Test another document, non-existent994 docId = "555"995 d.Id = docId996 response, err = conn.Update(d, query, extraArgs)997 c.Assert(err, Equals, nil)998 time.Sleep(200 * time.Millisecond)999 response, err = conn.Get(indexName, docType, docId, url.Values{})1000 c.Assert(err, Equals, nil)1001 c.Assert(response.Source["user"], Equals, "admin")1002 c.Assert(response.Source["message"], Equals, "candybar")1003}1004func (s *GoesTestSuite) TestGetMapping(c *C) {1005 indexName := "testmapping"1006 docType := "tweet"1007 conn := NewConnection(ES_HOST, ES_PORT)1008 // just in case1009 conn.DeleteIndex(indexName)1010 _, err := conn.CreateIndex(indexName, map[string]interface{}{})1011 c.Assert(err, IsNil)1012 defer conn.DeleteIndex(indexName)1013 time.Sleep(300 * time.Millisecond)1014 response, err := conn.GetMapping([]string{docType}, []string{indexName})1015 c.Assert(err, Equals, nil)1016 c.Assert(len(response.Raw), Equals, 0)1017 d := Document{1018 Index: indexName,1019 Type: docType,1020 Fields: map[string]interface{}{1021 "user": "foo",1022 "message": "bar",1023 },1024 }1025 response, err = conn.Index(d, url.Values{})1026 c.Assert(err, IsNil)1027 time.Sleep(200 * time.Millisecond)1028 response, err = conn.GetMapping([]string{docType}, []string{indexName})1029 c.Assert(err, Equals, nil)1030 c.Assert(len(response.Raw), Not(Equals), 0)1031}1032func (s *GoesTestSuite) TestDeleteMapping(c *C) {1033 indexName := "testdeletemapping"1034 docType := "tweet"1035 conn := NewConnection(ES_HOST, ES_PORT)1036 // just in case1037 conn.DeleteIndex(indexName)1038 _, err := conn.CreateIndex(indexName, map[string]interface{}{})1039 c.Assert(err, IsNil)1040 defer conn.DeleteIndex(indexName)1041 d := Document{1042 Index: indexName,1043 Type: docType,1044 Fields: map[string]interface{}{1045 "user": "foo",1046 "message": "bar",1047 },...

Full Screen

Full Screen

connection.go

Source:connection.go Github

copy

Full Screen

...166 }167 for k, c := range clientMap {168 if c.isDelete {169 c.disConnect()170 delete(clientMap, k)171 }172 }173 return nil174}175func UpdateRpcConnection(servers []string, pingFunc PingFunc) error {176 mapLock.Lock()177 defer mapLock.Unlock()178 for _, c := range clientMap {179 c.isDelete = true180 }181 for _, host := range servers {182 logger.Debug(host)183 c, ok := clientMap[host]184 logger.Debug(ok)185 if !ok {186 c = newConnection(host)187 go c.ping(pingFunc)188 clientMap[host] = c189 } else {190 c.isDelete = false191 }192 }193 logger.Debug(clientMap)194 for k, c := range clientMap {195 logger.Debug(c.isDelete)196 if c.isDelete {197 c.disConnect()198 delete(clientMap, k)199 }200 }201 return nil202}...

Full Screen

Full Screen

member.go

Source:member.go Github

copy

Full Screen

...29}30func realnameApplyStatusKey(mid int64) string {31 return fmt.Sprintf("realname_apply_%d", mid)32}33// DelMoralCache delete moral cache.34func (d *Dao) DelMoralCache(c context.Context, mid int64) (err error) {35 key := d.moralKey(mid)36 conn := d.memberMemcache.Get(c)37 defer conn.Close()38 if err = conn.Delete(key); err != nil {39 if err == memcache.ErrNotFound {40 err = nil41 return42 }43 log.Error("conn.Delete(%s) error(%v)", key, err)44 }45 return46}47// DelBaseInfoCache delete baseInfo cache.48func (d *Dao) DelBaseInfoCache(c context.Context, mid int64) (err error) {49 key := d.mcBaseKey(mid)50 conn := d.memberMemcache.Get(c)51 defer conn.Close()52 if err = conn.Delete(key); err != nil {53 if err == memcache.ErrNotFound {54 err = nil55 return56 }57 log.Error("conn.Delete(%s) error(%v)", key, err)58 }59 return60}61// DelInfoCache delete account info from cache.62func (d *Dao) DelInfoCache(c context.Context, mid int64) (err error) {63 conn := d.memberMemcache.Get(c)64 err = conn.Delete(keyInfo(mid))65 conn.Close()66 if err == memcache.ErrNotFound {67 err = nil68 }69 return70}71// SetExpCache set user exp cache.72func (d *Dao) SetExpCache(c context.Context, mid, exp int64) (err error) {73 conn := d.memberMemcache.Get(c)74 defer conn.Close()75 if err = conn.Set(&memcache.Item{76 Key: expKey(mid),77 Value: []byte(strconv.FormatInt(exp, 10)),78 Expiration: _expExpire,79 }); err != nil {80 log.Error("setexpcache mid %d err %v ", mid, err)81 }82 return83}84// DelExpCache set user exp cache.85func (d *Dao) DelExpCache(c context.Context, mid int64) error {86 conn := d.memberMemcache.Get(c)87 defer conn.Close()88 if err := conn.Delete(expKey(mid)); err != nil {89 if err == memcache.ErrNotFound {90 return nil91 }92 return errors.WithStack(err)93 }94 return nil95}96// DeleteRealnameCache delete all realname cache97func (d *Dao) DeleteRealnameCache(c context.Context, mid int64) (err error) {98 var (99 key1 = realnameInfoKey(mid)100 key2 = realnameApplyStatusKey(mid)101 conn = d.memberMemcache.Get(c)102 )103 defer conn.Close()104 if err = conn.Delete(key1); err != nil {105 if err != memcache.ErrNotFound {106 err = errors.Wrapf(err, "conn.Delete(%s)", key1)107 return108 }109 err = nil110 }...

Full Screen

Full Screen

delete

Using AI Code Generation

copy

Full Screen

1func main() {2 conn, err := net.Dial("tcp", "localhost:8080")3 if err != nil {4 panic(err)5 }6 defer conn.Close()7 if err != nil {8 panic(err)9 }10 req.Write(conn)11 res, err := http.ReadResponse(bufio.NewReader(conn), req)12 if err != nil {13 panic(err)14 }15 fmt.Println(res.Status)16 fmt.Println(res.Header)17 fmt.Println(res.Body)18}19func main() {20 conn, err := net.Dial("tcp", "localhost:8080")21 if err != nil {22 panic(err)23 }24 defer conn.Close()25 if err != nil {26 panic(err)27 }28 req.Write(conn)29 res, err := http.ReadResponse(bufio.NewReader(conn), req)30 if err != nil {31 panic(err)32 }33 fmt.Println(res.Status)34 fmt.Println(res.Header)35 fmt.Println(res.Body)36}37func main() {38 conn, err := net.Dial("tcp", "localhost:8080")39 if err != nil {40 panic(err)41 }42 defer conn.Close()43 if err != nil {44 panic(err)45 }46 req.Write(conn)47 res, err := http.ReadResponse(bufio.NewReader(conn), req)48 if err != nil {49 panic(err)50 }51 fmt.Println(res.Status)52 fmt.Println(res.Header)53 fmt.Println(res.Body)54}55func main() {56 conn, err := net.Dial("tcp", "localhost:8080")57 if err != nil {58 panic(err)59 }60 defer conn.Close()61 if err != nil {62 panic(err)63 }64 req.Write(conn)65 res, err := http.ReadResponse(bufio.NewReader(conn),

Full Screen

Full Screen

delete

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn := &conn{}4 conn.Delete(1)5}6import (7func main() {8 conn := &conn{}9 conn.Delete(1)10}11import (12func main() {13 conn := &conn{}14 conn.Delete(1)15}16import (17func main() {18 conn := &conn{}19 conn.Delete(1)20}21import (22func main() {23 conn := &conn{}24 conn.Delete(1)25}26import (27func main() {28 conn := &conn{}29 conn.Delete(1)30}31import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful