Golang Elasticsearch Docking problem

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Es bag

Gopkg.in/olivere/elastic.v3


Golang Operation ES Process, the definition of the content of the struct to write Es is always empty, and later found that the definition of struct first letter lowercase, Golang in the first letter lowercase for private, so can not be successfully written, changed to common.

Just study, not familiar with, make a record



Listen qnzses listen to project listen to Main.go
Package Listen Main

Import Listen (
Listen and listen to the "FMT"
Listen, listen, "Log."
Listen and listen to the "OS"

Listen, listen, "Database/sql."
Listen, listen, "time."

Listen to listen to "Github.com/go-sql-driver/mysql"
Listen, listen, "gopkg.in/olivere/elastic.v3."
)

var listens to the client and listens to *elastic. Client
var listen to db listen to *sql. Db

Type Listen ques listen to the struct listen {
Listen, listen, listen, qid, listen to the string.
Listen and listen to the title listen to the string
Listen to listen to added listen to string
Listen to listen to OrgID listen to string
}

Type Listen Ques2 listen to the struct listen {
Listen and listen to the content listen to the string
}

Func listen to init () listen {
Hear and hear the Var hear err listen to error
Listen to the client and listen to err listen = listen to elastic. Newclient (
Listen and listen and listen to elastic. SetUrl ("http://127.0.0.1:9200"),
Listen and listen and listen to elastic. Setsniff (False),
Listen and listen and listen to elastic. Sethealthcheckinterval (10*time. Second),
Listen and listen and listen to elastic. Setmaxretries (5),
Listen and listen and listen to elastic. Seterrorlog (log. New (OS. Stderr, listen to "elastic listen", listen to log. Lstdflags)),
Listen and listen and listen to elastic. Setinfolog (log. New (OS. Stdout, listen to "", listen to log. Lstdflags)))
Listen to hear if listen to err hear! = Listen Nil Listen {
Listen, listen, hear, hear, and listen to the FMT. PRINTLN (ERR)
Listen and Hear}
Listen and listen//Initialize MySQL
Listen to listen to the DB, listen to listen = listen to SQL. Open ("MySQL", listen "root:123456@tcp (127.0.0.1:3306)/YOUTH_QNZS")
Listen to listen to the db. Setmaxopenconns (2000)
Listen to listen to the db. Setmaxidleconns (1000)
Listen to listen to the db. Ping ()
}

Func listen to Main () listen {
Listen to listen to Quesrow listen: = Listen to Getfrommysql ()
Listen and listen to//FMT. Println (ques["Orgstrid"])
Listen to listen to//quescontent listen: = Listen to ques{qid: Listen to quesrow["q_id"], listen to the title: Listen to Quesrow["Q_title", listen to added: Listen to quesrow["q_added", listen to OrgID: Listen quesrow["OrgID"]}
Listen to hear quescontent listen: = Listen to ques2{content: Listen to quesrow["Q_title"]}
Hear and hear the FMT. Println (quescontent)
Listen to listen and listen to err: = Listen to the client. Index ().
Listen and listen and listen to the index ("Ikindex").
Listen to listen and listen to the type ("Fulltext").
Listen to hear and hear the ID (quesrow["q_id"]).
Listen, listen, listen, hear Bodyjson (quescontent).
Listen and listen and listen to the Refresh (true).
Listen, listen, listen, listen and listen.
Listen to hear if listen to err hear! = Listen Nil Listen {
Listen and listen/listen to the handle hear the error
Listen, listen, listen, listen and listen to panic (err)
Listen and Hear}

}

Func Listen Getfrommysql () listen to map[string]string listen {
Listen and listen to the record: = Listen make (map[string]string)
Listen to the rows and listen to err listen: = Listen to db. Query ("Select Listen * Listen from q_questions listen to limit listen 998, listen to 1")
Listen to defer listen to rows. Close ()
Listen and listen to//checkerr (err)
Listen to hear if listen to err hear! = Listen Nil Listen {
Listen, listen, hear, hear, and listen to the FMT. PRINTLN (ERR)
Listen, listen, listen, listen, hear the record.
Listen and Hear}

Listen to listen to columns, listen to listen: = Listen to Rows. Columns ()
Listen and listen Scanargs: = Listen to make ([]interface{}, listen to Len (columns))
Listen and listen to values: = Listen to make ([]interface{}, listen to Len (columns))
Listen to listen for listen J listen: = Listen range listen to values listen {
Listen, listen, listen, hear, hear, scanargs[j, listen to &values[j]
Listen and Hear}

Listen and listen for listen to rows. Next () Listen {
Listen and listen listen//save row data to the record dictionary
Listen to listen and listen to err listen = listen to rows. Scan (Scanargs ...)
Listen, listen, listen, hear for listen I, listen to col: = Listen range listen to the values
Listen, listen, hear, hear, hear, listen, hear, listen to the If listen to col. = Listen to nil hear {
Listen, listen, listen, listen, listen, listen, listen, hear, record[columns[i, listen to the string (Col. ([]byte))
Listen, listen, listen, hear, hear, listen.
Listen, listen, hear, hear, listen.
Listen and Hear}
Listen, listen, return, listen to the record.
}

/**
Listen * Listen from ES search
Listen * *
Func Listen Essearch () listen {
Listen to listen to termquery listen: = Listen to elastic. Newtermquery ("content", listening to "China")
Listen and listen to SearchResult, listen to err: = Listen to the client. Search ().
Listen and listen and listen to the index ("Ikindex"). Type ("Fulltext"). Listen//Listen to search listen in listen to index listen to "Twitter"
Listen, listen, listen, hear, hear, hear, hear, hear, listen, or listen to the Specify listen to the query
Listen and listen to//sort ("user", listen to True). Listen, listen, listen, listen, listen, hear, hear, hear, listen to, listen to the field, listen to ascending
Listen, listen, listen and hear from (0). Size (10). Listen/listen to take a listen to the documents 0-9
Listen, listen, listen and listen to Pretty (true). Listen and hear/listen to pretty listen to the request listen and listen to the response listen to JSON
Listen, listen, listen, listen, hear, hear, listen, hear, hear, listen, and listen to/listen to the Execute
Listen to hear if listen to err hear! = Listen Nil Listen {
Listen and listen/listen to the handle hear the error
Listen, listen, listen, listen and listen to panic (err)
Listen and Hear}

Listen to listen/listen to SearchResult listen to the is listen to the type listen to SearchResult listen and listen to returns listen to hits, listen to suggestions,
Listen to listen to and listen to all listen to kinds listen to the other listen to information hear from listen to Elasticsearch.
Hear and hear the FMT. Printf ("Query listen took listen to%d listen to milliseconds\n", listen to Searchresult.tookinmillis)
Hear and hear the FMT. Println (SearchResult.Hits.TotalHits)

Hear and hear the FMT. Println ("Hello Listen world!")
}


This article is from the "Big Hu Study Notes" blog, please be sure to keep this source http://zhixinhu.blog.51cto.com/3132199/1835287

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.