Merge pull request #22 from sasbury/master
Added support for Count requests
This commit is contained in:
commit
475a722fea
15
goes.go
15
goes.go
@ -210,6 +210,21 @@ func (c *Connection) Search(query map[string]interface{}, indexList []string, ty
|
|||||||
return r.Run()
|
return r.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Count executes a count query against an index, use the Count field in the response for the result
|
||||||
|
func (c *Connection) Count(query map[string]interface{}, indexList []string, typeList []string, extraArgs url.Values) (Response, error) {
|
||||||
|
r := Request{
|
||||||
|
Conn: c,
|
||||||
|
Query: query,
|
||||||
|
IndexList: indexList,
|
||||||
|
TypeList: typeList,
|
||||||
|
method: "POST",
|
||||||
|
api: "_count",
|
||||||
|
ExtraArgs: extraArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Run()
|
||||||
|
}
|
||||||
|
|
||||||
//Query runs a query against an index using the provided http method.
|
//Query runs a query against an index using the provided http method.
|
||||||
//This method can be used to execute a delete by query, just pass in "DELETE"
|
//This method can be used to execute a delete by query, just pass in "DELETE"
|
||||||
//for the HTTP method.
|
//for the HTTP method.
|
||||||
|
46
goes_test.go
46
goes_test.go
@ -722,6 +722,52 @@ func (s *GoesTestSuite) TestSearch(c *C) {
|
|||||||
c.Assert(response.Hits, DeepEquals, expectedHits)
|
c.Assert(response.Hits, DeepEquals, expectedHits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GoesTestSuite) TestCount(c *C) {
|
||||||
|
indexName := "testcount"
|
||||||
|
docType := "tweet"
|
||||||
|
docId := "1234"
|
||||||
|
source := map[string]interface{}{
|
||||||
|
"user": "foo",
|
||||||
|
"message": "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := NewConnection(ES_HOST, ES_PORT)
|
||||||
|
conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
_, err := conn.CreateIndex(indexName, map[string]interface{}{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
defer conn.DeleteIndex(indexName)
|
||||||
|
|
||||||
|
d := Document{
|
||||||
|
Index: indexName,
|
||||||
|
Type: docType,
|
||||||
|
Id: docId,
|
||||||
|
Fields: source,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Index(d, url.Values{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
_, err = conn.RefreshIndex(indexName)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
// I can feel my eyes bleeding
|
||||||
|
query := map[string]interface{}{
|
||||||
|
"query": map[string]interface{}{
|
||||||
|
"bool": map[string]interface{}{
|
||||||
|
"must": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"match_all": map[string]interface{}{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
response, err := conn.Count(query, []string{indexName}, []string{docType}, url.Values{})
|
||||||
|
|
||||||
|
c.Assert(response.Count, Equals, 1)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *GoesTestSuite) TestIndexStatus(c *C) {
|
func (s *GoesTestSuite) TestIndexStatus(c *C) {
|
||||||
indexName := "testindexstatus"
|
indexName := "testindexstatus"
|
||||||
conn := NewConnection(ES_HOST, ES_PORT)
|
conn := NewConnection(ES_HOST, ES_PORT)
|
||||||
|
@ -70,6 +70,7 @@ type Response struct {
|
|||||||
Type string `json:"_type"`
|
Type string `json:"_type"`
|
||||||
Version int `json:"_version"`
|
Version int `json:"_version"`
|
||||||
Found bool
|
Found bool
|
||||||
|
Count int
|
||||||
|
|
||||||
// Used by the _stats API
|
// Used by the _stats API
|
||||||
All All `json:"_all"`
|
All All `json:"_all"`
|
||||||
|
Loading…
Reference in New Issue
Block a user