当前位置: 首页>>代码示例>>Golang>>正文


Golang api.Pretty函数代码示例

本文整理汇总了Golang中github.com/mattbaird/elastigo/api.Pretty函数的典型用法代码示例。如果您正苦于以下问题:Golang Pretty函数的具体用法?Golang Pretty怎么用?Golang Pretty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Pretty函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MGet

// Multi GET API allows to get multiple documents based on an index, type (optional) and id (and possibly routing).
// The response includes a docs array with all the fetched documents, each element similar in structure to a document
// provided by the get API.
// see http://www.elasticsearch.org/guide/reference/api/multi-get.html
func MGet(pretty bool, index string, _type string, req string) (MGetResponseContainer, error) {
	var url string
	var retval MGetResponseContainer
	if len(index) <= 0 {
		url = fmt.Sprintf("/_mget?%s", api.Pretty(pretty))
	}
	if len(_type) > 0 && len(index) > 0 {
		url = fmt.Sprintf("/%s/%s/_mget?%s", index, _type, api.Pretty(pretty))
	} else if len(index) > 0 {
		url = fmt.Sprintf("/%s/_mget?%s", index, api.Pretty(pretty))
	}
	body, err := api.DoCommand("GET", url, req)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	fmt.Println(body)
	return retval, err
}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:29,代码来源:mget.go

示例2: Exists

// Exists allows caller to check for the existance of a document using HEAD
func Exists(pretty bool, index string, _type string, id string) (bool, error) {

	var url string

	var response map[string]interface{}

	if len(_type) > 0 {
		url = fmt.Sprintf("/%s/%s/%s?fields=_id%s", index, _type, id, api.Pretty(pretty))
	} else {
		url = fmt.Sprintf("/%s/%s?fields=_id%s", index, id, api.Pretty(pretty))
	}

	req, err := api.ElasticSearchRequest("HEAD", url)

	if err != nil {
		fmt.Println(err)
	}

	httpStatusCode, _, err := req.Do(&response)

	if err != nil {
		return false, err
	}
	if httpStatusCode == 404 {
		return false, err
	} else {
		return true, err
	}
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:30,代码来源:get.go

示例3: Index

// The index API adds or updates a typed JSON document in a specific index, making it searchable.
// http://www.elasticsearch.org/guide/reference/api/index_.html
func Index(pretty bool, index string, _type string, id string, data interface{}) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	url = fmt.Sprintf("/%s/%s/%s?%s", index, _type, id, api.Pretty(pretty))
	var method string
	if id == "" {
		method = "POST"
	} else {
		method = "PUT"
	}

	body, err := api.DoCommand(method, url, data)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	//fmt.Println(body)
	return retval, err
}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:27,代码来源:index.go

示例4: ExistsIndex

// ExistsIndex allows caller to check for the existance of an index or a type using HEAD
func ExistsIndex(pretty bool, index string, _type string) (bool, error) {
	var url string
	if len(_type) > 0 {
		url = fmt.Sprintf("/%s/%s?%s", index, _type, api.Pretty(pretty))
	} else {
		url = fmt.Sprintf("/%s?%s", index, api.Pretty(pretty))
	}
	req, err := api.ElasticSearchRequest("HEAD", url)
	httpStatusCode, _, err := req.Do(nil)

	if err != nil {
		return false, err
	}
	if httpStatusCode == http.StatusOK {
		return true, err
	} else {
		return false, err
	}
}
开发者ID:nahap,项目名称:elastigo,代码行数:20,代码来源:get.go

示例5: SearchRequest

// Performs a very basic search on an index via the request URI API.
//
// params:
//   @pretty:  bool for pretty reply or not, a parameter to elasticsearch
//   @index:  the elasticsearch index
//   @_type:  optional ("" if not used) search specific type in this index
//   @query:  this can be one of 3 types:
//              1)  string value that is valid elasticsearch
//              2)  io.Reader that can be set in body (also valid elasticsearch string syntax..)
//              3)  other type marshalable to json (also valid elasticsearch json)
//
//   out, err := SearchRequest(true, "github","",qryType ,"", 0)
//
// http://www.elasticsearch.org/guide/reference/api/search/uri-request.html
func SearchRequest(pretty bool, index string, _type string, query interface{}, scroll string, scan int) (SearchResult, error) {
	var uriVal string
	var retval SearchResult
	if len(_type) > 0 && _type != "*" {
		uriVal = fmt.Sprintf("/%s/%s/_search?%s%s%s", index, _type, api.Pretty(pretty), api.Scroll(scroll), api.Scan(scan))
	} else {
		uriVal = fmt.Sprintf("/%s/_search?%s%s%s", index, api.Pretty(pretty), api.Scroll(scroll), api.Scan(scan))
	}
	body, err := api.DoCommand("POST", uriVal, query)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal([]byte(body), &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	return retval, err
}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:35,代码来源:search.go

示例6: Health

// The cluster health API allows to get a very simple status on the health of the cluster.
// see http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html
// TODO: implement wait_for_status, timeout, wait_for_relocating_shards, wait_for_nodes
// TODO: implement level (Can be one of cluster, indices or shards. Controls the details level of the health
// information returned. Defaults to cluster.)
func Health(pretty bool, indices ...string) (ClusterHealthResponse, error) {
	var url string
	var retval ClusterHealthResponse
	if len(indices) > 0 {
		url = fmt.Sprintf("/_cluster/health/%s?%s", strings.Join(indices, ","), api.Pretty(pretty))
	} else {
		url = fmt.Sprintf("/_cluster/health?%s", api.Pretty(pretty))
	}
	body, err := api.DoCommand("GET", url, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	//fmt.Println(body)
	return retval, err
}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:27,代码来源:health.go

示例7: Get

// Get allows caller to get a typed JSON document from the index based on its id.
// GET - retrieves the doc
// HEAD - checks for existence of the doc
// http://www.elasticsearch.org/guide/reference/api/get.html
// TODO: make this implement an interface
func Get(pretty bool, index string, _type string, id string) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	if len(_type) > 0 {
		url = fmt.Sprintf("/%s/%s/%s?%s", index, _type, id, api.Pretty(pretty))
	} else {
		url = fmt.Sprintf("/%s/%s?%s", index, id, api.Pretty(pretty))
	}
	body, err := api.DoCommand("GET", url, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	//fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:27,代码来源:get.go

示例8: Status

// Status lists status details of all indices or the specified index.
// http://www.elasticsearch.org/guide/reference/api/admin-indices-status.html
func Status(pretty bool, indices ...string) (api.BaseResponse, error) {
	var retval api.BaseResponse
	var url string
	if len(indices) > 0 {
		url = fmt.Sprintf("/%s/_status?%s", strings.Join(indices, ","), api.Pretty(pretty))

	} else {
		url = fmt.Sprintf("/_status?%s", api.Pretty(pretty))
	}
	body, err := api.DoCommand("GET", url, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:24,代码来源:status.go

示例9: Explain

// Explain computes a score explanation for a query and a specific document.
// This can give useful feedback whether a document matches or didn’t match a specific query.
// This feature is available from version 0.19.9 and up.
// see http://www.elasticsearch.org/guide/reference/api/explain.html
func Explain(pretty bool, index string, _type string, id string, query string) (api.Match, error) {
	var url string
	var retval api.Match
	if len(_type) > 0 {
		url = fmt.Sprintf("/%s/%s/_explain?%s", index, _type, api.Pretty(pretty))
	} else {
		url = fmt.Sprintf("/%s/_explain?%s", index, api.Pretty(pretty))
	}
	body, err := api.DoCommand("GET", url, query)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:26,代码来源:explain.go

示例10: Update

// Update updates a document based on a script provided. The operation gets the document
// (collocated with the shard) from the index, runs the script (with optional script language and parameters),
// and index back the result (also allows to delete, or ignore the operation). It uses versioning to make sure
// no updates have happened during the “get” and “reindex”. (available from 0.19 onwards).
// Note, this operation still means full reindex of the document, it just removes some network roundtrips
// and reduces chances of version conflicts between the get and the index. The _source field need to be enabled
// for this feature to work.
//
// http://www.elasticsearch.org/guide/reference/api/update.html
// TODO: finish this, it's fairly complex
func Update(pretty bool, index string, _type string, id string, data interface{}) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	url = fmt.Sprintf("/%s/%s/%s/_update?%s", index, _type, id, api.Pretty(pretty))
	body, err := api.DoCommand("POST", url, data)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	return retval, err
}
开发者ID:nahap,项目名称:elastigo,代码行数:27,代码来源:update.go

示例11: Percolate

func Percolate(pretty bool, index string, _type string, name string, doc string) (api.Match, error) {
	var url string
	var retval api.Match
	url = fmt.Sprintf("/%s/%s/_percolate?%s", index, _type, api.Pretty(pretty))
	body, err := api.DoCommand("GET", url, doc)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:18,代码来源:percolate.go

示例12: RegisterPercolate

// RegisterPercolate allows the caller to register queries against an index, and then send percolate requests which include a doc, and
// getting back the queries that match on that doc out of the set of registered queries.
// Think of it as the reverse operation of indexing and then searching. Instead of sending docs, indexing them,
// and then running queries. One sends queries, registers them, and then sends docs and finds out which queries
// match that doc.
// see http://www.elasticsearch.org/guide/reference/api/percolate.html
func RegisterPercolate(pretty bool, index string, name string, query api.Query) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	url = fmt.Sprintf("/_percolator/%s/%s?%s", index, name, api.Pretty(pretty))
	body, err := api.DoCommand("PUT", url, query)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:24,代码来源:percolate.go

示例13: Delete

// Delete API allows to delete a typed JSON document from a specific index based on its id.
// http://www.elasticsearch.org/guide/reference/api/delete.html
// todo: add routing and versioning support
func Delete(pretty bool, index string, _type string, id string, version int, routing string) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	url = fmt.Sprintf("/%s/%s/%s?%s", index, _type, id, api.Pretty(pretty))
	body, err := api.DoCommand("DELETE", url, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	//fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:21,代码来源:delete.go

示例14: Count

// Count allows the caller to easily execute a query and get the number of matches for that query.
// It can be executed across one or more indices and across one or more types.
// The query can either be provided using a simple query string as a parameter,
// or using the Query DSL defined within the request body.
// http://www.elasticsearch.org/guide/reference/api/count.html
// TODO: take parameters.
// currently not working against 0.19.10
func Count(pretty bool, index string, _type string) (CountResponse, error) {
	var url string
	var retval CountResponse
	url = fmt.Sprintf("/%s/%s/_count?%s", index, _type, api.Pretty(pretty))
	body, err := api.DoCommand("GET", url, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	//fmt.Println(body)
	return retval, err
}
开发者ID:reedobrien,项目名称:elastigo,代码行数:25,代码来源:count.go

示例15: MoreLikeThis

// The more like this (mlt) API allows to get documents that are “like” a specified document.
// http://www.elasticsearch.org/guide/reference/api/more-like-this.html
func MoreLikeThis(pretty bool, index string, _type string, id string, query MoreLikeThisQuery) (api.BaseResponse, error) {
	var url string
	var retval api.BaseResponse
	url = fmt.Sprintf("/%s/%s/%s/_mlt?%s", index, _type, id, api.Pretty(pretty))
	body, err := api.DoCommand("GET", url, query)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	fmt.Println(body)
	return retval, err
}
开发者ID:penguinxr2,项目名称:elastigo,代码行数:20,代码来源:moreLikeThis.go


注:本文中的github.com/mattbaird/elastigo/api.Pretty函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。