How to create elasticsearch Index
This article mainly explains "how to create elasticsearch index". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to create an elasticsearch index.
Index view all indexes rst, _: = client.CatIndices () .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
[{"health": "yellow", "status": "open", "index": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ", "pri": "1", "rep": "3", "docs.count": "0", "docs.deleted": "0", "creation.date": "0" "creation.date.string": "," store.size ":" 208b "," pri.store.size ":" 208b "," completion.size ":"," pri.completion.size ":", "fielddata.memory_size": "," pri.fielddata.memory_size ":", "fielddata.evictions": "0" "pri.fielddata.evictions": "0", "query_cache.memory_size": "," pri.query_cache.memory_size ":", "query_cache.evictions": "0", "pri.query_cache.evictions": "0", "request_cache.memory_size": "," pri.request_cache.memory_size ":" "request_cache.evictions": "0", "pri.request_cache.evictions": "0", "request_cache.hit_count": "0", "pri.request_cache.hit_count": "0", "request_cache.miss_count": "0", "pri.request_cache.miss_count": "0", "flush.total": "0" "pri.flush.total": "0", "flush.total_time": "," pri.flush.total_time ":", "get.current": "0", "pri.get.current": "0", "get.time": "", "pri.get.time": "", "get.total": "0" "pri.get.total": "0", "get.exists_time": "," pri.get.exists_time ":", "get.exists_total": "0", "pri.get.exists_total": "0", "get.missing_time": "," pri.get.missing_time ":" "get.missing_total": "0", "pri.get.missing_total": "0", "indexing.delete_current": "0", "pri.indexing.delete_current": "0", "indexing.delete_time": "", "pri.indexing.delete_time": "," indexing.delete_total ":" 0 " "pri.indexing.delete_total": "0", "indexing.index_current": "0", "pri.indexing.index_current": "0", "indexing.index_time": "," pri.indexing.index_time ":"," indexing.index_total ":" 0 "," pri.indexing.index_total ":" 0 " "indexing.index_failed": "0", "pri.indexing.index_failed": "0", "merges.current": "0", "pri.merges.current": "0", "merges.current_docs": "0", "pri.merges.current_docs": "0", "merges.current_size": "" "pri.merges.current_size": "," merges.total ":" 0 "," pri.merges.total ":" 0 "," merges.total_docs ":" 0 "," pri.merges.total_docs ":" 0 "," merges.total_size ":", "pri.merges.total_size": "" "merges.total_time": "," pri.merges.total_time ":", "refresh.total": "0", "pri.refresh.total": "0", "refresh.external_total": "0", "pri.refresh.external_total": "0", "refresh.time": "", "pri.refresh.time": "" "refresh.external_time": "," pri.refresh.external_time ":", "refresh.listeners": "0", "pri.refresh.listeners": "0", "search.fetch_current": "0", "pri.search.fetch_current": "0", "search.fetch_time": "" "pri.search.fetch_time": "," search.fetch_total ":" 0 "," pri.search.fetch_total ":" 0 "," search.open_contexts ":" 0 "," pri.search.open_contexts ":" 0 "," search.query_current ":" 0 "," pri.search.query_current ":" 0 " "search.query_time": "," pri.search.query_time ":", "search.query_total": "0", "pri.search.query_total": "0", "search.scroll_current": "0", "pri.search.scroll_current": "0", "search.scroll_time": "" "pri.search.scroll_time": "," search.scroll_total ":" 0 "," pri.search.scroll_total ":" 0 "," search.throttled ":" false "," segments.count ":" 0 "," pri.segments.count ":" 0 "," segments.memory ":", "pri.segments.memory": "" "segments.index_writer_memory": "," pri.segments.index_writer_memory ":", "segments.version_map_memory": "," pri.segments.version_map_memory ":", "segments.fixed_bitset_memory": "", "pri.segments.fixed_bitset_memory": "," warmer.current ":" 0 " "pri.warmer.current": "0", "warmer.total": "0", "pri.warmer.total": "0", "warmer.total_time": "," pri.warmer.total_time ":", "suggest.current": "0", "pri.suggest.current": "0", "suggest.time": "" "pri.suggest.time": "," suggest.total ":" 0 "," pri.suggest.total ":" 0 "," memory.total ":"," pri.memory.total ":"}] View the index rst at the beginning of us, _: = client.CatIndices (). Index (" us* ") .Do (ctx) buf _: = json.Marshal (rst) fmt.Println (string (buf))
Return
Check the index information rst, _: = client.IndexGet ("user") .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"user": {"aliases": {}, "mappings": {"properties": {"name": {"type": "keyword"} "settings": {"index": {"creation_date": "1599207187635", "number_of_replicas": "1", "number_of_shards": "1", "provided_name": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ" "version": {"created": "7080099"}, "warmers": null}} View mappingrst, _: = client.GetMapping () .Index ("user") .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"user": {"mappings": {"properties": {"name": {"type": "keyword"} View settingsrst, _: = client.IndexGetSettings ("user") .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"user": {"settings": {"index": {"creation_date": "1599207187635", "number_of_replicas": "1", "number_of_shards": "1", "provided_name": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ" "version": {"created": "7080099"}} create index rst, _: = client.CreateIndex ("user") .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"acknowledged": true, "shards_acknowledged": true, "index": "user"} specify mapping and settingsbd: = `{"mappings": {"properties": {"name": {"type": "keyword"}, "settings": {"index": {"number_of_shards": 1 when creating the index "number_of_replicas": 2}} `rst, _: = client.CreateIndex ("user") .body (bd) .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"acknowledged": true, "shards_acknowledged": true, "index": "user"} create an index Then top mapping_, err: = client.CreateIndex ("user") .Do (ctx) if err! = nil {panic (err.Error ())} bd: = `{"properties": {"name": {"type": "keyword"}} `rst, _: = client.PutMapping (). Index ("user") .BodyString (bd) .Do (ctx) buf _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"acknowledged": true, "shards_acknowledged": false} automatically creates an index rst when creating a document, _: = client.Index (). Index ("user"). BodyJson (& User {Name: "noname1"}) .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"_ index": "user", "_ type": "_ doc", "_ id": "Y70mWHQBIsMSghaJdERa", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0} "_ primary_term": 1} modified number of copies bd: = `{"index": {"number_of_replicas": 3}} `rst, _: = client.IndexPutSettings ("user") .BodyString (bd) .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"acknowledged": true, "shards_acknowledged": false} modify the number of shards bd: = `{"index": {"number_of_shards": 2}} `rst, err: = client.IndexPutSettings ("user") .BodyString (bd) .Do (ctx) if err! = nil {fmt.Println (err.Error () return} buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
Elastic: Error 400 (Bad Request): Can't update non dynamic settings [[index.number_of_shards]] for open indices [[user/F4eP0Sq-S9a9pBJhN_eYVQ]] [type=illegal_argument_exception]
Description: the number of shards must be specified when the index is created and cannot be modified after creation. An error will be reported when you try to modify
Delete index rst, _: = client.DeleteIndex ("user") .Do (ctx) buf, _: = json.Marshal (rst) fmt.Println (string (buf))
Return
{"acknowledged": true} so far, I believe you have a deeper understanding of "how to create an elasticsearch index". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!