{"id":13412416,"url":"https://github.com/mattbaird/elastigo","last_synced_at":"2025-03-14T18:31:22.847Z","repository":{"id":5026363,"uuid":"6185208","full_name":"mattbaird/elastigo","owner":"mattbaird","description":"A Go (golang) based Elasticsearch client library.","archived":false,"fork":false,"pushed_at":"2019-02-05T18:17:02.000Z","size":2979,"stargazers_count":942,"open_issues_count":69,"forks_count":239,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-03-07T18:51:05.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"iobridge/thingspeak","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattbaird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-12T04:19:59.000Z","updated_at":"2025-02-21T06:26:49.000Z","dependencies_parsed_at":"2022-09-17T04:42:24.980Z","dependency_job_id":null,"html_url":"https://github.com/mattbaird/elastigo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbaird%2Felastigo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbaird%2Felastigo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbaird%2Felastigo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbaird%2Felastigo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattbaird","download_url":"https://codeload.github.com/mattbaird/elastigo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243625119,"owners_count":20321235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:24.427Z","updated_at":"2025-03-14T18:31:22.796Z","avatar_url":"https://github.com/mattbaird.png","language":"Go","funding_links":[],"categories":["Database Drivers","数据库驱动程序","数据库驱动`连接和操作数据库工具`","Data Integration Frameworks","数据库驱动","NoSQL Databases","Generators","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","Search and Analytic Databases","检索及分析资料库","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"elastigo v2.0 \n-------------\n\n[![Build Status](https://drone.io/github.com/mattbaird/elastigo/status.png)](https://drone.io/github.com/mattbaird/elastigo)\n\nBig thanks to @alicebob for helping to get the drone.io CI working (note: the badge is being cached, known issue).\n\nA Go (Golang) based Elasticsearch client, implements core api for Indexing and searching.   \nGoDoc http://godoc.org/github.com/mattbaird/elastigo\n\n\nNOTE: Based on the great work from Jeremy Shute, Elastigo now supports multiple connections. We attempted to make this backwards compatible, however in the end it wasn't possible, so we tagged the older single connection code as v1.0 and started work on v2.0.\n\nIf you want to use v1.0, you can use a tool like GoDep to make that possible. See http://bit.ly/VLG2et for full details.\n\nThe godep tool saves the exact version of the dependencies you’re building your project against, which means that upstream modifications in third-party dependencies won’t break your build.\n\n```bash\ngo get github.com/tools/godep\n```\n\nNow, to pull in an existing project with godep:\n```bash\n\tgodep go get github.com/myuser/myproject\n```\n\nWhen your code compiles in your workspace, ala:\n\n```bash\ncd $HOME/gopath/src/github.com/myuser/myproject\n# hack hack hack\ngo build ./...\n```\n\nYou can freeze your dependencies thusly:\n\n```bash\ngodep save github.com/myuser/myproject\ngit add Godeps\n```\n\nThe godep tool will examine your code to find and save the transitive closure of your dependencies in the current directory, observing their versions.  If you want to restore or update these versions, see the documentation for the tool.\n\nNote, in particular, that if your current directory contains a group of binaries or packages, you may save all of them at once:\n\n```bash\ngodep save ./...\n```\n\nTo get the Chef based Vagrantfile working, be sure to pull like so::\n\n    # This will pull submodules.\n    git clone --recursive git@github.com:mattbaird/elastigo.git\n\nIt's easier to use the ElasticSearch provided Docker image found here: https://github.com/dockerfile/elasticsearch\n\nNon-persistent usage is:\n```bash\ndocker run -d -p 9200:9200 -p 9300:9300 dockerfile/elasticsearch\n```\n\nQuick Start with Docker\n=======================\nMake sure docker is installed. If you are running docker on a mac, you must expose ports 9200 and 9300. Shut down docker:\n```bash\nboot2docker stop\n```\nand run\n```bash\nfor i in {9200..9300}; do\n VBoxManage modifyvm \"boot2docker-vm\" --natpf1 \"tcp-port$i,tcp,,$i,,$i\";\n VBoxManage modifyvm \"boot2docker-vm\" --natpf1 \"udp-port$i,udp,,$i,,$i\";\ndone\n```\nThe following will allow you to get the code, and run the tests against your docker based non-persistent elasticsearch:\n\n```bash\ndocker run -d -p 9200:9200 -p 9300:9300 dockerfile/elasticsearch\ngit clone git@github.com:mattbaird/elastigo.git\ncd elastigo\ngo get -u ./...\ncd lib\ngo test -v -host localhost -loaddata\ncd ..\ngo test -v ./...\n```\n\nUsage Examples - Currently out of date, being rewritten for v2.0\n----------------------------------------------------------------\n\nAdding content to Elasticsearch\n-------------------------------\n\n```go\nimport \"github.com/mattbaird/elastigo/api\"\nimport \"github.com/mattbaird/elastigo/core\"\n\ntype Tweet struct {\n  User     string    `json:\"user\"`\n  Message  string    `json:\"message\"`\n}\n\n// Set the Elasticsearch Host to Connect to\napi.Domain = \"localhost\"\n// api.Port = \"9300\"\n\n// add single go struct entity\nresponse, _ := core.Index(\"twitter\", \"tweet\", \"1\", nil, Tweet{\"kimchy\", \"Search is cool\"})\n\n// you have bytes\ntw := Tweet{\"kimchy\", \"Search is cool part 2\"}\nbytesLine, err := json.Marshal(tw)\nresponse, _ := core.Index(\"twitter\", \"tweet\", \"2\", nil, bytesLine)\n\n// Bulk Indexing\nt := time.Now()\ncore.IndexBulk(\"twitter\", \"tweet\", \"3\", \u0026t, Tweet{\"kimchy\", \"Search is now cooler\"})\n\n// Search Using Raw json String\nsearchJson := `{\n    \"query\" : {\n        \"term\" : { \"user\" : \"kimchy\" }\n    }\n}`\nout, err := core.SearchRequest(true, \"twitter\", \"tweet\", searchJson, \"\")\nif len(out.Hits.Hits) == 1 {\n  fmt.Println(string(out.Hits.Hits[0].Source))\n}\n```\n\nA Faceted, ranged Search using the `Search DSL` :\n\n```go\nimport \"github.com/mattbaird/elastigo/api\"\nimport \"github.com/mattbaird/elastigo/core\"\n\n// Set the Elasticsearch Host to Connect to\napi.Domain = \"localhost\"\n// api.Port = \"9300\"\n\nout, err := Search(\"github\").Size(\"1\").Facet(\n  Facet().Fields(\"actor\").Size(\"500\"),\n).Query(\n  Query().Range(\n     Range().Field(\"created_at\").From(\"2012-12-10T15:00:00-08:00\").To(\"2012-12-10T15:10:00-08:00\"),\n  ).Search(\"add\"),\n).Result()\n```\n\nA Ranged Search using the `Search DSL` :\n\n```go\nout, err := Search(\"github\").Type(\"Issues\").Pretty().Query(\n  Query().Range(\n     Range().Field(\"created_at\").From(\"2012-12-10T15:00:00-08:00\").To(\"2012-12-10T15:10:00-08:00\"),\n  ).Search(\"add\"),\n).Result()\n```\n\nA Simple Search using the `Search DSL` :\n\n```go\nout, err := Search(\"github\").Type(\"Issues\").Size(\"100\").Search(\"add\").Result()\n```\n\nA Direct Search using the api :\n\n```go\nqry := map[string]interface{}{\n  \"query\":map[string]interface{}{\n     \"term\":map[string]string{\"user\": \"kimchy\"},\n  },\n}\ncore.SearchRequest(true, \"github\", \"Issues\", qry, \"\", 0)\n```\n\nA Direct Search using the query string Api :\n\n```go\ncore.SearchUri(\"github\", \"Issues\", \"user:kimchy\", \"\", 0)\n```\n\nA Filtered search `Search DSL` :\n\n```go\nout, err := Search(\"github\").Filter(\n  Filter().Exists(\"repository.name\"),\n).Result()\n```\n\nAdding content to Elasticsearch in Bulk\n----------------------------------------------\n\n```go\nimport \"github.com/mattbaird/elastigo/api\"\nimport \"github.com/mattbaird/elastigo/core\"\n\n// Set the Elasticsearch Host to Connect to\napi.Domain = \"localhost\"\n// api.Port = \"9300\"\n\nindexer := core.NewBulkIndexerErrors(10, 60)\ndone := make(chan bool)\nindexer.Run(done)\n\ngo func() {\n  for errBuf := range indexer.ErrorChannel {\n    // just blissfully print errors forever\n    fmt.Println(errBuf.Err)\n  }\n}()\nfor i := 0; i \u003c 20; i++ {\n  indexer.Index(\"twitter\", \"user\", strconv.Itoa(i), \"\", nil, `{\"name\":\"bob\"}`, false)\n}\ndone \u003c- true\n// Indexing might take a while. So make sure the program runs\n// a little longer when trying this in main.\n```\n\nstatus updates\n========================\n\n* *2014-07-09* Version 2.0 development started. Focused on multi-connection support, using Dial idiom.\n* *2014-5-21* Note: Drone.io tests are failing, I don't know why because the build and tests are working fine for me on my ubuntu box running the docker elasticsearch image. It's possible there is a timing issue. Any Ideas?\n* *2013-9-27* Fleshing out cluster and indices APIs, updated vagrant image to 0.90.3\n* *2013-7-10* Improvements/changes to bulk indexer (includes breaking changes to support TTL),\n         Search dsl supports And/Or/Not\n    * *SearchDsl* should still be considered beta at this\n         point, there will be minor breaking changes as more of the\n         elasticsearch feature set is implemented.\n* *2013-1-26* expansion of search dsl for greater coverage\n* *2012-12-30* new bulk indexing and search dsl\n* *2012-10-12* early in development, not ready for production yet.\n\nlicense\n=======\n    Copyright 2012 Matthew Baird, Aaron Raddon, Jeremy Shute and more!\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbaird%2Felastigo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattbaird%2Felastigo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbaird%2Felastigo/lists"}