diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 7009c84eed..71f1d4daf7 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -1,7 +1,7 @@
{
"ImportPath": "k8s.io/heapster",
"GoVersion": "go1.6",
- "GodepVersion": "v60",
+ "GodepVersion": "v67",
"Packages": [
"./..."
],
@@ -47,15 +47,20 @@
},
{
"ImportPath": "github.com/davecgh/go-spew/spew",
- "Rev": "3e6e67c4dcea3ac2f25fd4731abc0e1deaf36216"
+ "Rev": "5215b55f46b2b919f50a1df0eaa5886afe4e3b3d"
},
{
- "ImportPath": "github.com/docker/docker/pkg/mount",
- "Comment": "v1.4.1-4831-g0f5c9d3",
- "Rev": "0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d"
+ "ImportPath": "github.com/docker/distribution/digest",
+ "Comment": "v2.4.0-rc.1-38-gcd27f17",
+ "Rev": "cd27f179f2c10c5d300e6d09025b538c475b0d51"
},
{
- "ImportPath": "github.com/docker/docker/pkg/parsers",
+ "ImportPath": "github.com/docker/distribution/reference",
+ "Comment": "v2.4.0-rc.1-38-gcd27f17",
+ "Rev": "cd27f179f2c10c5d300e6d09025b538c475b0d51"
+ },
+ {
+ "ImportPath": "github.com/docker/docker/pkg/mount",
"Comment": "v1.4.1-4831-g0f5c9d3",
"Rev": "0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d"
},
@@ -81,11 +86,12 @@
},
{
"ImportPath": "github.com/ghodss/yaml",
- "Rev": "4fb5c728a37b361a1e971a3bb3d785fcc96b6ef5"
+ "Rev": "73d445a93680fa1a78ae23a5839bad48f32ba1ee"
},
{
"ImportPath": "github.com/gogo/protobuf/proto",
- "Rev": "33a491225609b307cd96dc6a1c3ad484a2ac5f3e"
+ "Comment": "v0.1-125-g82d16f7",
+ "Rev": "82d16f734d6d871204a3feb1a73cb220cc92574c"
},
{
"ImportPath": "github.com/golang/glog",
@@ -106,7 +112,7 @@
},
{
"ImportPath": "github.com/google/gofuzz",
- "Rev": "95919286de1ca5a30261fac83b070e736286aae8"
+ "Rev": "bbcb9da2d746f8bdbd6a936686a0a6067ada0ec5"
},
{
"ImportPath": "github.com/hashicorp/go-msgpack/codec",
@@ -127,8 +133,8 @@
},
{
"ImportPath": "github.com/imdario/mergo",
- "Comment": "0.1.3-10-g67b9c0a",
- "Rev": "67b9c0a23d7ee9dcbcd44cd7ece4bf15ef6f4d26"
+ "Comment": "0.1.3-8-g6633656",
+ "Rev": "6633656539c1639d9d78127b7d47c622b5d7b6dc"
},
{
"ImportPath": "github.com/influxdb/influxdb/client",
@@ -182,6 +188,16 @@
"ImportPath": "github.com/mitchellh/mapstructure",
"Rev": "d2dd0262208475919e1a362f675cfc0e7c10e905"
},
+ {
+ "ImportPath": "github.com/olivere/elastic",
+ "Comment": "v2.0.20-25-g758ce50",
+ "Rev": "758ce508aa9f5ed43b19c7a8f2705f5a0605e0f4"
+ },
+ {
+ "ImportPath": "github.com/olivere/elastic/uritemplates",
+ "Comment": "v2.0.20-25-g758ce50",
+ "Rev": "758ce508aa9f5ed43b19c7a8f2705f5a0605e0f4"
+ },
{
"ImportPath": "github.com/opencontainers/runc/libcontainer/cgroups",
"Comment": "v0.0.7",
@@ -212,7 +228,7 @@
},
{
"ImportPath": "github.com/pborman/uuid",
- "Rev": "cccd189d45f7ac3368a0d127efb7f4d08ae0b655"
+ "Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
},
{
"ImportPath": "github.com/prometheus/client_golang/model",
@@ -295,7 +311,7 @@
},
{
"ImportPath": "github.com/spf13/pflag",
- "Rev": "5a13a75b13d132dc7d07dd19fd260257cd9c0290"
+ "Rev": "08b1a584251b5b62f458943640fc8ebd4d50aaa5"
},
{
"ImportPath": "github.com/stretchr/objx",
@@ -315,7 +331,7 @@
},
{
"ImportPath": "github.com/ugorji/go/codec",
- "Rev": "f1f1a805ed361a0e078bb537e4ea78cd37dcf065"
+ "Rev": "f4485b318aadd133842532f841dc205a8e339d74"
},
{
"ImportPath": "golang.org/x/crypto/bcrypt",
@@ -327,31 +343,31 @@
},
{
"ImportPath": "golang.org/x/net/context",
- "Rev": "6acef71eb69611914f7a30939ea9f6e194c78172"
+ "Rev": "c2528b2dd8352441850638a8bb678c2ad056fd3e"
},
{
"ImportPath": "golang.org/x/net/context/ctxhttp",
- "Rev": "6acef71eb69611914f7a30939ea9f6e194c78172"
+ "Rev": "c2528b2dd8352441850638a8bb678c2ad056fd3e"
},
{
"ImportPath": "golang.org/x/oauth2",
- "Rev": "2baa8a1b9338cf13d9eeb27696d761155fa480be"
+ "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
},
{
"ImportPath": "golang.org/x/oauth2/google",
- "Rev": "2baa8a1b9338cf13d9eeb27696d761155fa480be"
+ "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
},
{
"ImportPath": "golang.org/x/oauth2/internal",
- "Rev": "2baa8a1b9338cf13d9eeb27696d761155fa480be"
+ "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
},
{
"ImportPath": "golang.org/x/oauth2/jws",
- "Rev": "2baa8a1b9338cf13d9eeb27696d761155fa480be"
+ "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
},
{
"ImportPath": "golang.org/x/oauth2/jwt",
- "Rev": "2baa8a1b9338cf13d9eeb27696d761155fa480be"
+ "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9"
},
{
"ImportPath": "google.golang.org/api/cloudmonitoring/v2beta2",
@@ -374,411 +390,525 @@
"Rev": "40e8982bc18ef49b340c9da2c2bd9d49f94befcd"
},
{
- "ImportPath": "google.golang.org/appengine",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "google.golang.org/cloud/compute/metadata",
+ "Rev": "702c65bd88b55b1b69f4bd200b881ae0eab6538c"
},
{
- "ImportPath": "google.golang.org/appengine/internal",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "google.golang.org/cloud/internal",
+ "Rev": "702c65bd88b55b1b69f4bd200b881ae0eab6538c"
},
{
- "ImportPath": "google.golang.org/appengine/internal/app_identity",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "gopkg.in/inf.v0",
+ "Rev": "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4"
},
{
- "ImportPath": "google.golang.org/appengine/internal/base",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "gopkg.in/yaml.v2",
+ "Rev": "a83829b6f1293c91addabc89d0571c246397bbf4"
},
{
- "ImportPath": "google.golang.org/appengine/internal/datastore",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "k8s.io/kubernetes/pkg/api",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "google.golang.org/appengine/internal/log",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/endpoints",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "google.golang.org/appengine/internal/modules",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/errors",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "google.golang.org/appengine/internal/remote_api",
- "Rev": "54bf9150c922186bfc45a00bf9dfcb91a5063275"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/install",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "google.golang.org/cloud/compute/metadata",
- "Rev": "702c65bd88b55b1b69f4bd200b881ae0eab6538c"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/meta",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "google.golang.org/cloud/internal",
- "Rev": "702c65bd88b55b1b69f4bd200b881ae0eab6538c"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/pod",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "gopkg.in/v2/yaml",
- "Rev": "d466437aa4adc35830964cffc5b5f262c63ddcb4"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/resource",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/service",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/errors",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/unversioned",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/unversioned/validation",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/meta",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/util",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/resource",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/v1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/unversioned",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/api/validation",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/util",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/apimachinery",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/v1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/apimachinery/registered",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/api/validation",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/apps",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/apimachinery",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/apps/install",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/apimachinery/registered",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/authentication.k8s.io",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/authentication.k8s.io/install",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/authentication.k8s.io/v1beta1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/authorization",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/authorization/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/authorization/v1beta1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/autoscaling",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/autoscaling/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/autoscaling/v1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/batch",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/batch/install",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/batch/v1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/batch/v2alpha1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/componentconfig",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/componentconfig/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/extensions",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/extensions/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/extensions/v1beta1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/metrics",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/metrics/install",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/apis/metrics/v1alpha1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/policy",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/policy/install",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/apis/policy/v1alpha1",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/auth/authenticator",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/auth/user",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/capabilities",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/cache",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/metrics",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/client/restclient",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/transport",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/client/typed/discovery",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned/auth",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned/clientcmd",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/v1",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/conversion",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/conversion/queryparams",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/fields",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/stats",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/kubelet/client",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/kubelet/qos",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/labels",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/master/ports",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/runtime",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer/json",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer/protobuf",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer/recognizer",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer/streaming",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/runtime/serializer/versioning",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/types",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/crypto",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/errors",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/flowcontrol",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/framer",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/hash",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/homedir",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/integer",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/intstr",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/json",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/net",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
+ },
+ {
+ "ImportPath": "k8s.io/kubernetes/pkg/util/net/sets",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/parsers",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/rand",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/runtime",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/sets",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/testing",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/validation",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/validation/field",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/wait",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/util/yaml",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/version",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/pkg/watch",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/pkg/watch/json",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/pkg/watch/versioned",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
"ImportPath": "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/x509",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "k8s.io/kubernetes/third_party/forked/reflect",
- "Comment": "v1.2.0-alpha.7-1055-g644d651",
- "Rev": "644d651c690774376112cd3f257af0308e95a392"
+ "ImportPath": "k8s.io/kubernetes/plugin/pkg/client/auth",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "speter.net/go/exp/math/dec/inf",
- "Rev": "42ca6cd68aa922bc3f32f1e056e61b65945d9ad7"
+ "ImportPath": "k8s.io/kubernetes/plugin/pkg/client/auth/gcp",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
},
{
- "ImportPath": "github.com/olivere/elastic",
- "Rev": "758ce508aa9f5ed43b19c7a8f2705f5a0605e0f4"
+ "ImportPath": "k8s.io/kubernetes/third_party/forked/reflect",
+ "Comment": "v1.3.0-alpha.3-802-g4bb30e0",
+ "Rev": "4bb30e00978219640215ac04e84caf5bf398be92"
}
]
}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/.gitignore b/Godeps/_workspace/src/github.com/olivere/elastic/.gitignore
new file mode 100644
index 0000000000..3bf973ee50
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/olivere/elastic/.gitignore
@@ -0,0 +1,29 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+*.exe
+
+/generator
+/cluster-test/cluster-test
+/cluster-test/*.log
+/cluster-test/es-chaos-monkey
+/spec
+/tmp
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/alias_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/alias_test.go
deleted file mode 100644
index 45bf7980e0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/alias_test.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-const (
- testAliasName = "elastic-test-alias"
-)
-
-func TestAliasLifecycle(t *testing.T) {
- var err error
-
- client := setupTestClientAndCreateIndex(t)
-
- // Some tweets
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "sandrae", Message: "Cycling is fun."}
- tweet3 := tweet{User: "olivere", Message: "Another unrelated topic."}
-
- // Add tweets to first index
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Add tweets to second index
- _, err = client.Index().Index(testIndexName2).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Flush
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- /*
- // Alias should not yet exist
- aliasesResult1, err := client.Aliases().Do()
- if err != nil {
- t.Fatal(err)
- }
- if len(aliasesResult1.Indices) != 0 {
- t.Errorf("expected len(AliasesResult.Indices) = %d; got %d", 0, len(aliasesResult1.Indices))
- }
- */
-
- // Add both indices to a new alias
- aliasCreate, err := client.Alias().
- Add(testIndexName, testAliasName).
- Add(testIndexName2, testAliasName).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if !aliasCreate.Acknowledged {
- t.Errorf("expected AliasResult.Acknowledged %v; got %v", true, aliasCreate.Acknowledged)
- }
-
- // Search should return all 3 tweets
- matchAll := NewMatchAllQuery()
- searchResult1, err := client.Search().Index(testAliasName).Query(&matchAll).Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult1.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult1.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult1.Hits.TotalHits)
- }
-
- /*
- // Alias should return both indices
- aliasesResult2, err := client.Aliases().Do()
- if err != nil {
- t.Fatal(err)
- }
- if len(aliasesResult2.Indices) != 2 {
- t.Errorf("expected len(AliasesResult.Indices) = %d; got %d", 2, len(aliasesResult2.Indices))
- }
- */
-
- // Remove first index should remove two tweets, so should only yield 1
- aliasRemove1, err := client.Alias().
- Remove(testIndexName, testAliasName).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if !aliasRemove1.Acknowledged {
- t.Errorf("expected AliasResult.Acknowledged %v; got %v", true, aliasRemove1.Acknowledged)
- }
-
- searchResult2, err := client.Search().Index(testAliasName).Query(&matchAll).Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult2.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult2.Hits.TotalHits != 1 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 1, searchResult2.Hits.TotalHits)
- }
-
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/aliases_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/aliases_test.go
deleted file mode 100644
index 5d3949cb15..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/aliases_test.go
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestAliases(t *testing.T) {
- var err error
-
- client := setupTestClientAndCreateIndex(t)
-
- // Some tweets
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "sandrae", Message: "Cycling is fun."}
- tweet3 := tweet{User: "olivere", Message: "Another unrelated topic."}
-
- // Add tweets to first index
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
- // Add tweets to second index
- _, err = client.Index().Index(testIndexName2).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Flush
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Alias should not yet exist
- aliasesResult1, err := client.Aliases().
- Indices(testIndexName, testIndexName2).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if len(aliasesResult1.Indices) != 2 {
- t.Errorf("expected len(AliasesResult.Indices) = %d; got %d", 2, len(aliasesResult1.Indices))
- }
- for indexName, indexDetails := range aliasesResult1.Indices {
- if len(indexDetails.Aliases) != 0 {
- t.Errorf("expected len(AliasesResult.Indices[%s].Aliases) = %d; got %d", indexName, 0, len(indexDetails.Aliases))
- }
- }
-
- // Add both indices to a new alias
- aliasCreate, err := client.Alias().
- Add(testIndexName, testAliasName).
- Add(testIndexName2, testAliasName).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if !aliasCreate.Acknowledged {
- t.Errorf("expected AliasResult.Acknowledged %v; got %v", true, aliasCreate.Acknowledged)
- }
-
- // Alias should now exist
- aliasesResult2, err := client.Aliases().
- Indices(testIndexName, testIndexName2).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if len(aliasesResult2.Indices) != 2 {
- t.Errorf("expected len(AliasesResult.Indices) = %d; got %d", 2, len(aliasesResult2.Indices))
- }
- for indexName, indexDetails := range aliasesResult2.Indices {
- if len(indexDetails.Aliases) != 1 {
- t.Errorf("expected len(AliasesResult.Indices[%s].Aliases) = %d; got %d", indexName, 1, len(indexDetails.Aliases))
- }
- }
-
- // Check the reverse function:
- indexInfo1, found := aliasesResult2.Indices[testIndexName]
- if !found {
- t.Errorf("expected info about index %s = %v; got %v", testIndexName, true, found)
- }
- aliasFound := indexInfo1.HasAlias(testAliasName)
- if !aliasFound {
- t.Errorf("expected alias %s to include index %s; got %v", testAliasName, testIndexName, aliasFound)
- }
-
- // Check the reverse function:
- indexInfo2, found := aliasesResult2.Indices[testIndexName2]
- if !found {
- t.Errorf("expected info about index %s = %v; got %v", testIndexName, true, found)
- }
- aliasFound = indexInfo2.HasAlias(testAliasName)
- if !aliasFound {
- t.Errorf("expected alias %s to include index %s; got %v", testAliasName, testIndexName2, aliasFound)
- }
-
- // Remove first index should remove two tweets, so should only yield 1
- aliasRemove1, err := client.Alias().
- Remove(testIndexName, testAliasName).
- //Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if !aliasRemove1.Acknowledged {
- t.Errorf("expected AliasResult.Acknowledged %v; got %v", true, aliasRemove1.Acknowledged)
- }
-
- // Alias should now exist only for index 2
- aliasesResult3, err := client.Aliases().Indices(testIndexName, testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if len(aliasesResult3.Indices) != 2 {
- t.Errorf("expected len(AliasesResult.Indices) = %d; got %d", 2, len(aliasesResult3.Indices))
- }
- for indexName, indexDetails := range aliasesResult3.Indices {
- if indexName == testIndexName {
- if len(indexDetails.Aliases) != 0 {
- t.Errorf("expected len(AliasesResult.Indices[%s].Aliases) = %d; got %d", indexName, 0, len(indexDetails.Aliases))
- }
- } else if indexName == testIndexName2 {
- if len(indexDetails.Aliases) != 1 {
- t.Errorf("expected len(AliasesResult.Indices[%s].Aliases) = %d; got %d", indexName, 1, len(indexDetails.Aliases))
- }
- } else {
- t.Errorf("got index %s", indexName)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_delete_request_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/bulk_delete_request_test.go
deleted file mode 100644
index 73abfcd40d..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_delete_request_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestBulkDeleteRequestSerialization(t *testing.T) {
- tests := []struct {
- Request BulkableRequest
- Expected []string
- }{
- // #0
- {
- Request: NewBulkDeleteRequest().Index("index1").Type("tweet").Id("1"),
- Expected: []string{
- `{"delete":{"_id":"1","_index":"index1","_type":"tweet"}}`,
- },
- },
- }
-
- for i, test := range tests {
- lines, err := test.Request.Source()
- if err != nil {
- t.Fatalf("case #%d: expected no error, got: %v", i, err)
- }
- if lines == nil {
- t.Fatalf("case #%d: expected lines, got nil", i)
- }
- if len(lines) != len(test.Expected) {
- t.Fatalf("case #%d: expected %d lines, got %d", i, len(test.Expected), len(lines))
- }
- for j, line := range lines {
- if line != test.Expected[j] {
- t.Errorf("case #%d: expected line #%d to be %s, got: %s", i, j, test.Expected[j], line)
- }
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_index_request_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/bulk_index_request_test.go
deleted file mode 100644
index 271347e305..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_index_request_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
- "time"
-)
-
-func TestBulkIndexRequestSerialization(t *testing.T) {
- tests := []struct {
- Request BulkableRequest
- Expected []string
- }{
- // #0
- {
- Request: NewBulkIndexRequest().Index("index1").Type("tweet").Id("1").
- Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
- Expected: []string{
- `{"index":{"_id":"1","_index":"index1","_type":"tweet"}}`,
- `{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
- },
- },
- // #1
- {
- Request: NewBulkIndexRequest().OpType("create").Index("index1").Type("tweet").Id("1").
- Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
- Expected: []string{
- `{"create":{"_id":"1","_index":"index1","_type":"tweet"}}`,
- `{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
- },
- },
- // #2
- {
- Request: NewBulkIndexRequest().OpType("index").Index("index1").Type("tweet").Id("1").
- Doc(tweet{User: "olivere", Created: time.Date(2014, 1, 18, 23, 59, 58, 0, time.UTC)}),
- Expected: []string{
- `{"index":{"_id":"1","_index":"index1","_type":"tweet"}}`,
- `{"user":"olivere","message":"","retweets":0,"created":"2014-01-18T23:59:58Z"}`,
- },
- },
- }
-
- for i, test := range tests {
- lines, err := test.Request.Source()
- if err != nil {
- t.Fatalf("case #%d: expected no error, got: %v", i, err)
- }
- if lines == nil {
- t.Fatalf("case #%d: expected lines, got nil", i)
- }
- if len(lines) != len(test.Expected) {
- t.Fatalf("case #%d: expected %d lines, got %d", i, len(test.Expected), len(lines))
- }
- for j, line := range lines {
- if line != test.Expected[j] {
- t.Errorf("case #%d: expected line #%d to be %s, got: %s", i, j, test.Expected[j], line)
- }
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/bulk_test.go
deleted file mode 100644
index 6bfb82c30d..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_test.go
+++ /dev/null
@@ -1,370 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestBulk(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "sandrae", Message: "Dancing all night long. Yeah."}
-
- index1Req := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("1").Doc(tweet1)
- index2Req := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("2").Doc(tweet2)
- delete1Req := NewBulkDeleteRequest().Index(testIndexName).Type("tweet").Id("1")
-
- bulkRequest := client.Bulk()
- bulkRequest = bulkRequest.Add(index1Req)
- bulkRequest = bulkRequest.Add(index2Req)
- bulkRequest = bulkRequest.Add(delete1Req)
-
- if bulkRequest.NumberOfActions() != 3 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 3, bulkRequest.NumberOfActions())
- }
-
- bulkResponse, err := bulkRequest.Do()
- if err != nil {
- t.Fatal(err)
- }
- if bulkResponse == nil {
- t.Errorf("expected bulkResponse to be != nil; got nil")
- }
-
- if bulkRequest.NumberOfActions() != 0 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 0, bulkRequest.NumberOfActions())
- }
-
- // Document with Id="1" should not exist
- exists, err := client.Exists().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Errorf("expected exists %v; got %v", false, exists)
- }
-
- // Document with Id="2" should exist
- exists, err = client.Exists().Index(testIndexName).Type("tweet").Id("2").Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Errorf("expected exists %v; got %v", true, exists)
- }
-
- // Update
- updateDoc := struct {
- Retweets int `json:"retweets"`
- }{
- 42,
- }
- update1Req := NewBulkUpdateRequest().Index(testIndexName).Type("tweet").Id("2").Doc(&updateDoc)
- bulkRequest = client.Bulk()
- bulkRequest = bulkRequest.Add(update1Req)
-
- if bulkRequest.NumberOfActions() != 1 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 1, bulkRequest.NumberOfActions())
- }
-
- bulkResponse, err = bulkRequest.Do()
- if err != nil {
- t.Fatal(err)
- }
- if bulkResponse == nil {
- t.Errorf("expected bulkResponse to be != nil; got nil")
- }
-
- if bulkRequest.NumberOfActions() != 0 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 0, bulkRequest.NumberOfActions())
- }
-
- // Document with Id="1" should have a retweets count of 42
- doc, err := client.Get().Index(testIndexName).Type("tweet").Id("2").Do()
- if err != nil {
- t.Fatal(err)
- }
- if doc == nil {
- t.Fatal("expected doc to be != nil; got nil")
- }
- if !doc.Found {
- t.Fatalf("expected doc to be found; got found = %v", doc.Found)
- }
- if doc.Source == nil {
- t.Fatal("expected doc source to be != nil; got nil")
- }
- var updatedTweet tweet
- err = json.Unmarshal(*doc.Source, &updatedTweet)
- if err != nil {
- t.Fatal(err)
- }
- if updatedTweet.Retweets != 42 {
- t.Errorf("expected updated tweet retweets = %v; got %v", 42, updatedTweet.Retweets)
- }
-}
-
-func TestBulkWithIndexSetOnClient(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "sandrae", Message: "Dancing all night long. Yeah."}
-
- index1Req := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("1").Doc(tweet1)
- index2Req := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("2").Doc(tweet2)
- delete1Req := NewBulkDeleteRequest().Index(testIndexName).Type("tweet").Id("1")
-
- bulkRequest := client.Bulk().Index(testIndexName).Type("tweet")
- bulkRequest = bulkRequest.Add(index1Req)
- bulkRequest = bulkRequest.Add(index2Req)
- bulkRequest = bulkRequest.Add(delete1Req)
-
- if bulkRequest.NumberOfActions() != 3 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 3, bulkRequest.NumberOfActions())
- }
-
- bulkResponse, err := bulkRequest.Do()
- if err != nil {
- t.Fatal(err)
- }
- if bulkResponse == nil {
- t.Errorf("expected bulkResponse to be != nil; got nil")
- }
-
- // Document with Id="1" should not exist
- exists, err := client.Exists().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Errorf("expected exists %v; got %v", false, exists)
- }
-
- // Document with Id="2" should exist
- exists, err = client.Exists().Index(testIndexName).Type("tweet").Id("2").Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Errorf("expected exists %v; got %v", true, exists)
- }
-}
-
-func TestBulkRequestsSerialization(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "sandrae", Message: "Dancing all night long. Yeah."}
-
- index1Req := NewBulkIndexRequest().Index(testIndexName).Type("tweet").Id("1").Doc(tweet1)
- index2Req := NewBulkIndexRequest().OpType("create").Index(testIndexName).Type("tweet").Id("2").Doc(tweet2)
- delete1Req := NewBulkDeleteRequest().Index(testIndexName).Type("tweet").Id("1")
- update2Req := NewBulkUpdateRequest().Index(testIndexName).Type("tweet").Id("2").
- Doc(struct {
- Retweets int `json:"retweets"`
- }{
- Retweets: 42,
- })
-
- bulkRequest := client.Bulk()
- bulkRequest = bulkRequest.Add(index1Req)
- bulkRequest = bulkRequest.Add(index2Req)
- bulkRequest = bulkRequest.Add(delete1Req)
- bulkRequest = bulkRequest.Add(update2Req)
-
- if bulkRequest.NumberOfActions() != 4 {
- t.Errorf("expected bulkRequest.NumberOfActions %d; got %d", 4, bulkRequest.NumberOfActions())
- }
-
- expected := `{"index":{"_id":"1","_index":"` + testIndexName + `","_type":"tweet"}}
-{"user":"olivere","message":"Welcome to Golang and Elasticsearch.","retweets":0,"created":"0001-01-01T00:00:00Z"}
-{"create":{"_id":"2","_index":"` + testIndexName + `","_type":"tweet"}}
-{"user":"sandrae","message":"Dancing all night long. Yeah.","retweets":0,"created":"0001-01-01T00:00:00Z"}
-{"delete":{"_id":"1","_index":"` + testIndexName + `","_type":"tweet"}}
-{"update":{"_id":"2","_index":"` + testIndexName + `","_type":"tweet"}}
-{"doc":{"retweets":42}}
-`
- got, err := bulkRequest.bodyAsString()
- if err != nil {
- t.Fatalf("expected no error, got: %v", err)
- }
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-
- // Run the bulk request
- bulkResponse, err := bulkRequest.Do()
- if err != nil {
- t.Fatal(err)
- }
- if bulkResponse == nil {
- t.Errorf("expected bulkResponse to be != nil; got nil")
- }
- if bulkResponse.Took == 0 {
- t.Errorf("expected took to be > 0; got %d", bulkResponse.Took)
- }
- if bulkResponse.Errors {
- t.Errorf("expected errors to be %v; got %v", false, bulkResponse.Errors)
- }
- if len(bulkResponse.Items) != 4 {
- t.Fatalf("expected 4 result items; got %d", len(bulkResponse.Items))
- }
-
- // Indexed actions
- indexed := bulkResponse.Indexed()
- if indexed == nil {
- t.Fatal("expected indexed to be != nil; got nil")
- }
- if len(indexed) != 1 {
- t.Fatalf("expected len(indexed) == %d; got %d", 1, len(indexed))
- }
- if indexed[0].Id != "1" {
- t.Errorf("expected indexed[0].Id == %s; got %s", "1", indexed[0].Id)
- }
- if indexed[0].Status != 201 {
- t.Errorf("expected indexed[0].Status == %d; got %d", 201, indexed[0].Status)
- }
-
- // Created actions
- created := bulkResponse.Created()
- if created == nil {
- t.Fatal("expected created to be != nil; got nil")
- }
- if len(created) != 1 {
- t.Fatalf("expected len(created) == %d; got %d", 1, len(created))
- }
- if created[0].Id != "2" {
- t.Errorf("expected created[0].Id == %s; got %s", "2", created[0].Id)
- }
- if created[0].Status != 201 {
- t.Errorf("expected created[0].Status == %d; got %d", 201, created[0].Status)
- }
-
- // Deleted actions
- deleted := bulkResponse.Deleted()
- if deleted == nil {
- t.Fatal("expected deleted to be != nil; got nil")
- }
- if len(deleted) != 1 {
- t.Fatalf("expected len(deleted) == %d; got %d", 1, len(deleted))
- }
- if deleted[0].Id != "1" {
- t.Errorf("expected deleted[0].Id == %s; got %s", "1", deleted[0].Id)
- }
- if deleted[0].Status != 200 {
- t.Errorf("expected deleted[0].Status == %d; got %d", 200, deleted[0].Status)
- }
- if !deleted[0].Found {
- t.Errorf("expected deleted[0].Found == %v; got %v", true, deleted[0].Found)
- }
-
- // Updated actions
- updated := bulkResponse.Updated()
- if updated == nil {
- t.Fatal("expected updated to be != nil; got nil")
- }
- if len(updated) != 1 {
- t.Fatalf("expected len(updated) == %d; got %d", 1, len(updated))
- }
- if updated[0].Id != "2" {
- t.Errorf("expected updated[0].Id == %s; got %s", "2", updated[0].Id)
- }
- if updated[0].Status != 200 {
- t.Errorf("expected updated[0].Status == %d; got %d", 200, updated[0].Status)
- }
- if updated[0].Version != 2 {
- t.Errorf("expected updated[0].Version == %d; got %d", 2, updated[0].Version)
- }
-
- // Succeeded actions
- succeeded := bulkResponse.Succeeded()
- if succeeded == nil {
- t.Fatal("expected succeeded to be != nil; got nil")
- }
- if len(succeeded) != 4 {
- t.Fatalf("expected len(succeeded) == %d; got %d", 4, len(succeeded))
- }
-
- // ById
- id1Results := bulkResponse.ById("1")
- if id1Results == nil {
- t.Fatal("expected id1Results to be != nil; got nil")
- }
- if len(id1Results) != 2 {
- t.Fatalf("expected len(id1Results) == %d; got %d", 2, len(id1Results))
- }
- if id1Results[0].Id != "1" {
- t.Errorf("expected id1Results[0].Id == %s; got %s", "1", id1Results[0].Id)
- }
- if id1Results[0].Status != 201 {
- t.Errorf("expected id1Results[0].Status == %d; got %d", 201, id1Results[0].Status)
- }
- if id1Results[0].Version != 1 {
- t.Errorf("expected id1Results[0].Version == %d; got %d", 1, id1Results[0].Version)
- }
- if id1Results[1].Id != "1" {
- t.Errorf("expected id1Results[1].Id == %s; got %s", "1", id1Results[1].Id)
- }
- if id1Results[1].Status != 200 {
- t.Errorf("expected id1Results[1].Status == %d; got %d", 200, id1Results[1].Status)
- }
- if id1Results[1].Version != 2 {
- t.Errorf("expected id1Results[1].Version == %d; got %d", 2, id1Results[1].Version)
- }
-}
-
-func TestFailedBulkRequests(t *testing.T) {
- js := `{
- "took" : 2,
- "errors" : true,
- "items" : [ {
- "index" : {
- "_index" : "elastic-test",
- "_type" : "tweet",
- "_id" : "1",
- "_version" : 1,
- "status" : 201
- }
- }, {
- "create" : {
- "_index" : "elastic-test",
- "_type" : "tweet",
- "_id" : "2",
- "_version" : 1,
- "status" : 423,
- "error" : "Locked"
- }
- }, {
- "delete" : {
- "_index" : "elastic-test",
- "_type" : "tweet",
- "_id" : "1",
- "_version" : 2,
- "status" : 404,
- "found" : false
- }
- }, {
- "update" : {
- "_index" : "elastic-test",
- "_type" : "tweet",
- "_id" : "2",
- "_version" : 2,
- "status" : 200
- }
- } ]
-}`
-
- var resp BulkResponse
- err := json.Unmarshal([]byte(js), &resp)
- if err != nil {
- t.Fatal(err)
- }
- failed := resp.Failed()
- if len(failed) != 2 {
- t.Errorf("expected %d failed items; got: %d", 2, len(failed))
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_update_request_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/bulk_update_request_test.go
deleted file mode 100644
index 1d4ebafa50..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/bulk_update_request_test.go
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestBulkUpdateRequestSerialization(t *testing.T) {
- tests := []struct {
- Request BulkableRequest
- Expected []string
- }{
- // #0
- {
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").Doc(struct {
- Counter int64 `json:"counter"`
- }{
- Counter: 42,
- }),
- Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_type":"tweet"}}`,
- `{"doc":{"counter":42}}`,
- },
- },
- // #1
- {
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").
- RetryOnConflict(3).
- DocAsUpsert(true).
- Doc(struct {
- Counter int64 `json:"counter"`
- }{
- Counter: 42,
- }),
- Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"tweet"}}`,
- `{"doc":{"counter":42},"doc_as_upsert":true}`,
- },
- },
- // #2
- {
- Request: NewBulkUpdateRequest().Index("index1").Type("tweet").Id("1").
- RetryOnConflict(3).
- Script(`ctx._source.retweets += param1`).
- ScriptLang("js").
- ScriptParams(map[string]interface{}{"param1": 42}).
- Upsert(struct {
- Counter int64 `json:"counter"`
- }{
- Counter: 42,
- }),
- Expected: []string{
- `{"update":{"_id":"1","_index":"index1","_retry_on_conflict":3,"_type":"tweet","upsert":{"counter":42}}}`,
- `{"lang":"js","params":{"param1":42},"script":"ctx._source.retweets += param1"}`,
- },
- },
- }
-
- for i, test := range tests {
- lines, err := test.Request.Source()
- if err != nil {
- t.Fatalf("case #%d: expected no error, got: %v", i, err)
- }
- if lines == nil {
- t.Fatalf("case #%d: expected lines, got nil", i)
- }
- if len(lines) != len(test.Expected) {
- t.Fatalf("case #%d: expected %d lines, got %d", i, len(test.Expected), len(lines))
- }
- for j, line := range lines {
- if line != test.Expected[j] {
- t.Errorf("case #%d: expected line #%d to be %s, got: %s", i, j, test.Expected[j], line)
- }
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/canonicalize_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/canonicalize_test.go
deleted file mode 100644
index ada2ff22d0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/canonicalize_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "reflect"
- "testing"
-)
-
-func TestCanonicalize(t *testing.T) {
- tests := []struct {
- Input []string
- Output []string
- }{
- {
- Input: []string{"http://127.0.0.1/"},
- Output: []string{"http://127.0.0.1"},
- },
- {
- Input: []string{"http://127.0.0.1:9200/", "gopher://golang.org/", "http://127.0.0.1:9201"},
- Output: []string{"http://127.0.0.1:9200", "http://127.0.0.1:9201"},
- },
- {
- Input: []string{"http://user:secret@127.0.0.1/path?query=1#fragment"},
- Output: []string{"http://user:secret@127.0.0.1"},
- },
- {
- Input: []string{"https://somewhere.on.mars:9999/path?query=1#fragment"},
- Output: []string{"https://somewhere.on.mars:9999"},
- },
- }
-
- for _, test := range tests {
- got := canonicalize(test.Input...)
- if !reflect.DeepEqual(got, test.Output) {
- t.Errorf("expected %v; got: %v", test.Output, got)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/clear_scroll_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/clear_scroll_test.go
deleted file mode 100644
index c251fc2d84..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/clear_scroll_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- _ "net/http"
- "testing"
-)
-
-func TestClearScroll(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- res, err := client.Scroll(testIndexName).Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Errorf("expected results != nil; got nil")
- }
- if res.ScrollId == "" {
- t.Errorf("expected scrollId in results; got %q", res.ScrollId)
- }
-
- // Search should succeed
- _, err = client.Scroll(testIndexName).Size(1).ScrollId(res.ScrollId).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Clear scroll id
- clearScrollRes, err := client.ClearScroll().ScrollId(res.ScrollId).Do()
- if err != nil {
- t.Fatal(err)
- }
- if clearScrollRes == nil {
- t.Error("expected results != nil; got nil")
- }
-
- // Search result should fail
- _, err = client.Scroll(testIndexName).Size(1).ScrollId(res.ScrollId).Do()
- if err == nil {
- t.Fatalf("expected scroll to fail")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/client_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/client_test.go
deleted file mode 100644
index 8a15de62ff..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/client_test.go
+++ /dev/null
@@ -1,692 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "bytes"
- "encoding/json"
- "log"
- "net/http"
- "regexp"
- "strings"
- "testing"
- "time"
-)
-
-func findConn(s string, slice ...*conn) (int, bool) {
- for i, t := range slice {
- if s == t.URL() {
- return i, true
- }
- }
- return -1, false
-}
-
-// -- NewClient --
-
-func TestClientDefaults(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
- if client.healthcheckEnabled != true {
- t.Errorf("expected health checks to be enabled, got: %v", client.healthcheckEnabled)
- }
- if client.healthcheckTimeoutStartup != DefaultHealthcheckTimeoutStartup {
- t.Errorf("expected health checks timeout on startup = %v, got: %v", DefaultHealthcheckTimeoutStartup, client.healthcheckTimeoutStartup)
- }
- if client.healthcheckTimeout != DefaultHealthcheckTimeout {
- t.Errorf("expected health checks timeout = %v, got: %v", DefaultHealthcheckTimeout, client.healthcheckTimeout)
- }
- if client.healthcheckInterval != DefaultHealthcheckInterval {
- t.Errorf("expected health checks interval = %v, got: %v", DefaultHealthcheckInterval, client.healthcheckInterval)
- }
- if client.snifferEnabled != true {
- t.Errorf("expected sniffing to be enabled, got: %v", client.snifferEnabled)
- }
- if client.snifferTimeoutStartup != DefaultSnifferTimeoutStartup {
- t.Errorf("expected sniffer timeout on startup = %v, got: %v", DefaultSnifferTimeoutStartup, client.snifferTimeoutStartup)
- }
- if client.snifferTimeout != DefaultSnifferTimeout {
- t.Errorf("expected sniffer timeout = %v, got: %v", DefaultSnifferTimeout, client.snifferTimeout)
- }
- if client.snifferInterval != DefaultSnifferInterval {
- t.Errorf("expected sniffer interval = %v, got: %v", DefaultSnifferInterval, client.snifferInterval)
- }
- if client.basicAuth != false {
- t.Errorf("expected no basic auth; got: %v", client.basicAuth)
- }
- if client.basicAuthUsername != "" {
- t.Errorf("expected no basic auth username; got: %q", client.basicAuthUsername)
- }
- if client.basicAuthPassword != "" {
- t.Errorf("expected no basic auth password; got: %q", client.basicAuthUsername)
- }
- if client.sendGetBodyAs != "GET" {
- t.Errorf("expected sendGetBodyAs to be GET; got: %q", client.sendGetBodyAs)
- }
-}
-
-func TestClientWithoutURL(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
- // Two things should happen here:
- // 1. The client starts sniffing the cluster on DefaultURL
- // 2. The sniffing process should find (at least) one node in the cluster, i.e. the DefaultURL
- if len(client.conns) == 0 {
- t.Fatalf("expected at least 1 node in the cluster, got: %d (%v)", len(client.conns), client.conns)
- }
- if !isTravis() {
- if _, found := findConn(DefaultURL, client.conns...); !found {
- t.Errorf("expected to find node with default URL of %s in %v", DefaultURL, client.conns)
- }
- }
-}
-
-func TestClientWithSingleURL(t *testing.T) {
- client, err := NewClient(SetURL("http://localhost:9200"))
- if err != nil {
- t.Fatal(err)
- }
- // Two things should happen here:
- // 1. The client starts sniffing the cluster on DefaultURL
- // 2. The sniffing process should find (at least) one node in the cluster, i.e. the DefaultURL
- if len(client.conns) == 0 {
- t.Fatalf("expected at least 1 node in the cluster, got: %d (%v)", len(client.conns), client.conns)
- }
- if !isTravis() {
- if _, found := findConn(DefaultURL, client.conns...); !found {
- t.Errorf("expected to find node with default URL of %s in %v", DefaultURL, client.conns)
- }
- }
-}
-
-func TestClientWithMultipleURLs(t *testing.T) {
- client, err := NewClient(SetURL("http://localhost:9200", "http://localhost:9201"))
- if err != nil {
- t.Fatal(err)
- }
- // The client should sniff both URLs, but only localhost:9200 should return nodes.
- if len(client.conns) != 1 {
- t.Fatalf("expected exactly 1 node in the local cluster, got: %d (%v)", len(client.conns), client.conns)
- }
- if !isTravis() {
- if client.conns[0].URL() != DefaultURL {
- t.Errorf("expected to find node with default URL of %s in %v", DefaultURL, client.conns)
- }
- }
-}
-
-func TestClientWithBasicAuth(t *testing.T) {
- client, err := NewClient(SetBasicAuth("user", "secret"))
- if err != nil {
- t.Fatal(err)
- }
- if client.basicAuth != true {
- t.Errorf("expected basic auth; got: %v", client.basicAuth)
- }
- if got, want := client.basicAuthUsername, "user"; got != want {
- t.Errorf("expected basic auth username %q; got: %q", want, got)
- }
- if got, want := client.basicAuthPassword, "secret"; got != want {
- t.Errorf("expected basic auth password %q; got: %q", want, got)
- }
-}
-
-func TestClientSniffSuccess(t *testing.T) {
- client, err := NewClient(SetURL("http://localhost:19200", "http://localhost:9200"))
- if err != nil {
- t.Fatal(err)
- }
- // The client should sniff both URLs, but only localhost:9200 should return nodes.
- if len(client.conns) != 1 {
- t.Fatalf("expected exactly 1 node in the local cluster, got: %d (%v)", len(client.conns), client.conns)
- }
-}
-
-func TestClientSniffFailure(t *testing.T) {
- _, err := NewClient(SetURL("http://localhost:19200", "http://localhost:19201"))
- if err == nil {
- t.Fatalf("expected cluster to fail with no nodes found")
- }
-}
-
-func TestClientSniffDisabled(t *testing.T) {
- client, err := NewClient(SetSniff(false), SetURL("http://localhost:9200", "http://localhost:9201"))
- if err != nil {
- t.Fatal(err)
- }
- // The client should not sniff, so it should have two connections.
- if len(client.conns) != 2 {
- t.Fatalf("expected 2 nodes, got: %d (%v)", len(client.conns), client.conns)
- }
- // Make two requests, so that both connections are being used
- for i := 0; i < len(client.conns); i++ {
- client.Flush().Do()
- }
- // The first connection (localhost:9200) should now be okay.
- if i, found := findConn("http://localhost:9200", client.conns...); !found {
- t.Fatalf("expected connection to %q to be found", "http://localhost:9200")
- } else {
- if conn := client.conns[i]; conn.IsDead() {
- t.Fatal("expected connection to be alive, but it is dead")
- }
- }
- // The second connection (localhost:9201) should now be marked as dead.
- if i, found := findConn("http://localhost:9201", client.conns...); !found {
- t.Fatalf("expected connection to %q to be found", "http://localhost:9201")
- } else {
- if conn := client.conns[i]; !conn.IsDead() {
- t.Fatal("expected connection to be dead, but it is alive")
- }
- }
-}
-
-func TestClientHealthcheckStartupTimeout(t *testing.T) {
- start := time.Now()
- _, err := NewClient(SetURL("http://localhost:9299"), SetHealthcheckTimeoutStartup(5*time.Second))
- duration := time.Now().Sub(start)
- if err != ErrNoClient {
- t.Fatal(err)
- }
- if duration < 5*time.Second {
- t.Fatalf("expected a timeout in more than 5 seconds; got: %v", duration)
- }
-}
-
-// -- Start and stop --
-
-func TestClientStartAndStop(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
-
- running := client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-
- // Stop
- client.Stop()
- running = client.IsRunning()
- if running {
- t.Fatalf("expected background processes to be stopped; got: %v", running)
- }
-
- // Stop again => no-op
- client.Stop()
- running = client.IsRunning()
- if running {
- t.Fatalf("expected background processes to be stopped; got: %v", running)
- }
-
- // Start
- client.Start()
- running = client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-
- // Start again => no-op
- client.Start()
- running = client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-}
-
-func TestClientStartAndStopWithSnifferAndHealthchecksDisabled(t *testing.T) {
- client, err := NewClient(SetSniff(false), SetHealthcheck(false))
- if err != nil {
- t.Fatal(err)
- }
-
- running := client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-
- // Stop
- client.Stop()
- running = client.IsRunning()
- if running {
- t.Fatalf("expected background processes to be stopped; got: %v", running)
- }
-
- // Stop again => no-op
- client.Stop()
- running = client.IsRunning()
- if running {
- t.Fatalf("expected background processes to be stopped; got: %v", running)
- }
-
- // Start
- client.Start()
- running = client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-
- // Start again => no-op
- client.Start()
- running = client.IsRunning()
- if !running {
- t.Fatalf("expected background processes to run; got: %v", running)
- }
-}
-
-// -- Sniffing --
-
-func TestClientSniffNode(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
-
- ch := make(chan []*conn)
- go func() { ch <- client.sniffNode(DefaultURL) }()
-
- select {
- case nodes := <-ch:
- if len(nodes) != 1 {
- t.Fatalf("expected %d nodes; got: %d", 1, len(nodes))
- }
- pattern := `http:\/\/[\d\.]+:9200`
- matched, err := regexp.MatchString(pattern, nodes[0].URL())
- if err != nil {
- t.Fatal(err)
- }
- if !matched {
- t.Fatalf("expected node URL pattern %q; got: %q", pattern, nodes[0].URL())
- }
- case <-time.After(2 * time.Second):
- t.Fatal("expected no timeout in sniff node")
- break
- }
-}
-
-func TestClientSniffOnDefaultURL(t *testing.T) {
- client, _ := NewClient()
- if client == nil {
- t.Fatal("no client returned")
- }
-
- ch := make(chan error, 1)
- go func() {
- ch <- client.sniff(DefaultSnifferTimeoutStartup)
- }()
-
- select {
- case err := <-ch:
- if err != nil {
- t.Fatalf("expected sniff to succeed; got: %v", err)
- }
- if len(client.conns) != 1 {
- t.Fatalf("expected %d nodes; got: %d", 1, len(client.conns))
- }
- pattern := `http:\/\/[\d\.]+:9200`
- matched, err := regexp.MatchString(pattern, client.conns[0].URL())
- if err != nil {
- t.Fatal(err)
- }
- if !matched {
- t.Fatalf("expected node URL pattern %q; got: %q", pattern, client.conns[0].URL())
- }
- case <-time.After(2 * time.Second):
- t.Fatal("expected no timeout in sniff")
- break
- }
-}
-
-// -- Selector --
-
-func TestClientSelectConnHealthy(t *testing.T) {
- client, err := NewClient(
- SetSniff(false),
- SetHealthcheck(false),
- SetURL("http://127.0.0.1:9200", "http://127.0.0.1:9201"))
- if err != nil {
- t.Fatal(err)
- }
-
- // Both are healthy, so we should get both URLs in round-robin
- client.conns[0].MarkAsHealthy()
- client.conns[1].MarkAsHealthy()
-
- // #1: Return 1st
- c, err := client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[0].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[0].URL())
- }
- // #2: Return 2nd
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[1].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[1].URL())
- }
- // #3: Return 1st
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[0].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[0].URL())
- }
-}
-
-func TestClientSelectConnHealthyAndDead(t *testing.T) {
- client, err := NewClient(
- SetSniff(false),
- SetHealthcheck(false),
- SetURL("http://127.0.0.1:9200", "http://127.0.0.1:9201"))
- if err != nil {
- t.Fatal(err)
- }
-
- // 1st is healthy, second is dead
- client.conns[0].MarkAsHealthy()
- client.conns[1].MarkAsDead()
-
- // #1: Return 1st
- c, err := client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[0].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[0].URL())
- }
- // #2: Return 1st again
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[0].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[0].URL())
- }
- // #3: Return 1st again and again
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[0].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[0].URL())
- }
-}
-
-func TestClientSelectConnDeadAndHealthy(t *testing.T) {
- client, err := NewClient(
- SetSniff(false),
- SetHealthcheck(false),
- SetURL("http://127.0.0.1:9200", "http://127.0.0.1:9201"))
- if err != nil {
- t.Fatal(err)
- }
-
- // 1st is dead, 2nd is healthy
- client.conns[0].MarkAsDead()
- client.conns[1].MarkAsHealthy()
-
- // #1: Return 2nd
- c, err := client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[1].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[1].URL())
- }
- // #2: Return 2nd again
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[1].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[1].URL())
- }
- // #3: Return 2nd again and again
- c, err = client.next()
- if err != nil {
- t.Fatal(err)
- }
- if c.URL() != client.conns[1].URL() {
- t.Fatalf("expected %s; got: %s", c.URL(), client.conns[1].URL())
- }
-}
-
-func TestClientSelectConnAllDead(t *testing.T) {
- client, err := NewClient(
- SetSniff(false),
- SetHealthcheck(false),
- SetURL("http://127.0.0.1:9200", "http://127.0.0.1:9201"))
- if err != nil {
- t.Fatal(err)
- }
-
- // Both are dead
- client.conns[0].MarkAsDead()
- client.conns[1].MarkAsDead()
-
- // #1: Return ErrNoClient
- c, err := client.next()
- if err != ErrNoClient {
- t.Fatal(err)
- }
- if c != nil {
- t.Fatalf("expected no connection; got: %v", c)
- }
- // #2: Return ErrNoClient again
- c, err = client.next()
- if err != ErrNoClient {
- t.Fatal(err)
- }
- if c != nil {
- t.Fatalf("expected no connection; got: %v", c)
- }
- // #3: Return ErrNoClient again and again
- c, err = client.next()
- if err != ErrNoClient {
- t.Fatal(err)
- }
- if c != nil {
- t.Fatalf("expected no connection; got: %v", c)
- }
-}
-
-// -- ElasticsearchVersion --
-
-func TestElasticsearchVersion(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
- version, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if version == "" {
- t.Errorf("expected a version number, got: %q", version)
- }
-}
-
-// -- IndexNames --
-
-func TestIndexNames(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
- names, err := client.IndexNames()
- if err != nil {
- t.Fatal(err)
- }
- if len(names) == 0 {
- t.Fatalf("expected some index names, got: %d", len(names))
- }
- var found bool
- for _, name := range names {
- if name == testIndexName {
- found = true
- break
- }
- }
- if !found {
- t.Fatalf("expected to find index %q; got: %v", testIndexName, found)
- }
-}
-
-// -- PerformRequest --
-
-func TestPerformRequest(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
- res, err := client.PerformRequest("GET", "/", nil, nil)
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected response to be != nil")
- }
-
- ret := new(PingResult)
- if err := json.Unmarshal(res.Body, ret); err != nil {
- t.Fatalf("expected no error on decode; got: %v", err)
- }
- if ret.Status != 200 {
- t.Errorf("expected HTTP status 200; got: %d", ret.Status)
- }
-}
-
-func TestPerformRequestWithLogger(t *testing.T) {
- var w bytes.Buffer
- out := log.New(&w, "LOGGER ", log.LstdFlags)
-
- client, err := NewClient(SetInfoLog(out))
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := client.PerformRequest("GET", "/", nil, nil)
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected response to be != nil")
- }
-
- ret := new(PingResult)
- if err := json.Unmarshal(res.Body, ret); err != nil {
- t.Fatalf("expected no error on decode; got: %v", err)
- }
- if ret.Status != 200 {
- t.Errorf("expected HTTP status 200; got: %d", ret.Status)
- }
-
- got := w.String()
- pattern := `^LOGGER \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} GET http://.*/ \[status:200, request:\d+\.\d{3}s\]\n`
- matched, err := regexp.MatchString(pattern, got)
- if err != nil {
- t.Fatalf("expected log line to match %q; got: %v", pattern, err)
- }
- if !matched {
- t.Errorf("expected log line to match %q; got: %v", pattern, got)
- }
-}
-
-func TestPerformRequestWithLoggerAndTracer(t *testing.T) {
- var lw bytes.Buffer
- lout := log.New(&lw, "LOGGER ", log.LstdFlags)
-
- var tw bytes.Buffer
- tout := log.New(&tw, "TRACER ", log.LstdFlags)
-
- client, err := NewClient(SetInfoLog(lout), SetTraceLog(tout))
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := client.PerformRequest("GET", "/", nil, nil)
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected response to be != nil")
- }
-
- ret := new(PingResult)
- if err := json.Unmarshal(res.Body, ret); err != nil {
- t.Fatalf("expected no error on decode; got: %v", err)
- }
- if ret.Status != 200 {
- t.Errorf("expected HTTP status 200; got: %d", ret.Status)
- }
-
- lgot := lw.String()
- if lgot == "" {
- t.Errorf("expected logger output; got: %q", lgot)
- }
-
- tgot := tw.String()
- if tgot == "" {
- t.Errorf("expected tracer output; got: %q", tgot)
- }
-}
-
-// failingTransport will run a fail callback if it sees a given URL path prefix.
-type failingTransport struct {
- path string // path prefix to look for
- fail func(*http.Request) (*http.Response, error) // call when path prefix is found
- next http.RoundTripper // next round-tripper (use http.DefaultTransport if nil)
-}
-
-// RoundTrip implements a failing transport.
-func (tr *failingTransport) RoundTrip(r *http.Request) (*http.Response, error) {
- if strings.HasPrefix(r.URL.Path, tr.path) && tr.fail != nil {
- return tr.fail(r)
- }
- if tr.next != nil {
- return tr.next.RoundTrip(r)
- }
- return http.DefaultTransport.RoundTrip(r)
-}
-
-// CancelRequest is required in a http.Transport to support timeouts.
-func (tr *failingTransport) CancelRequest(req *http.Request) {
-}
-
-func TestPerformRequestWithMaxRetries(t *testing.T) {
- var numFailedReqs int
- fail := func(r *http.Request) (*http.Response, error) {
- numFailedReqs += 1
- return &http.Response{Request: r, StatusCode: 400}, nil
- }
-
- // Run against a failing endpoint and see if PerformRequest
- // retries correctly.
- tr := &failingTransport{path: "/fail", fail: fail}
- httpClient := &http.Client{Transport: tr}
-
- client, err := NewClient(SetHttpClient(httpClient), SetMaxRetries(5))
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := client.PerformRequest("GET", "/fail", nil, nil)
- if err == nil {
- t.Fatal("expected error")
- }
- if res != nil {
- t.Fatal("expected no response")
- }
- // Connection should be marked as dead after it failed
- if numFailedReqs != 5 {
- t.Errorf("expected %d failed requests; got: %d", 5, numFailedReqs)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/Makefile b/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/Makefile
deleted file mode 100644
index cc6261db5f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-.PHONY: build run-omega-cluster-test
-
-default: build
-
-build:
- go build cluster-test.go
-
-run-omega-cluster-test:
- go run -race cluster-test.go \
- -nodes=http://192.168.2.65:8200,http://192.168.2.64:8200 \
- -n=5 \
- -retries=5 \
- -sniff=true -sniffer=10s \
- -healthcheck=true -healthchecker=5s \
- -errorlog=errors.log
-
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/README.md b/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/README.md
deleted file mode 100644
index f10748cc2e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/README.md
+++ /dev/null
@@ -1,63 +0,0 @@
-# Cluster Test
-
-This directory contains a program you can use to test a cluster.
-
-Here's how:
-
-First, install a cluster of Elasticsearch nodes. You can install them on
-different computers, or start several nodes on a single machine.
-
-Build cluster-test by `go build cluster-test.go` (or build with `make`).
-
-Run `./cluster-test -h` to get a list of flags:
-
-```sh
-$ ./cluster-test -h
-Usage of ./cluster-test:
- -errorlog="": error log file
- -healthcheck=true: enable or disable healthchecks
- -healthchecker=1m0s: healthcheck interval
- -index="twitter": name of ES index to use
- -infolog="": info log file
- -n=5: number of goroutines that run searches
- -nodes="": comma-separated list of ES URLs (e.g. 'http://192.168.2.10:9200,http://192.168.2.11:9200')
- -retries=0: number of retries
- -sniff=true: enable or disable sniffer
- -sniffer=15m0s: sniffer interval
- -tracelog="": trace log file
-```
-
-Example:
-
-```sh
-$ ./cluster-test -nodes=http://127.0.0.1:9200,http://127.0.0.1:9201,http://127.0.0.1:9202 -n=5 -index=twitter -retries=5 -sniff=true -sniffer=10s -healthcheck=true -healthchecker=5s -errorlog=error.log
-```
-
-The above example will create an index and start some search jobs on the
-cluster defined by http://127.0.0.1:9200, http://127.0.0.1:9201,
-and http://127.0.0.1:9202.
-
-* It will create an index called `twitter` on the cluster (`-index=twitter`)
-* It will run 5 search jobs in parallel (`-n=5`).
-* It will retry failed requests 5 times (`-retries=5`).
-* It will sniff the cluster periodically (`-sniff=true`).
-* It will sniff the cluster every 10 seconds (`-sniffer=10s`).
-* It will perform health checks periodically (`-healthcheck=true`).
-* It will perform health checks on the nodes every 5 seconds (`-healthchecker=5s`).
-* It will write an error log file (`-errorlog=error.log`).
-
-If you want to test Elastic with nodes going up and down, you can use a
-chaos monkey script like this and run it on the nodes of your cluster:
-
-```sh
-#!/bin/bash
-while true
-do
- echo "Starting ES node"
- elasticsearch -d -Xmx4g -Xms1g -Des.config=elasticsearch.yml -p es.pid
- sleep `jot -r 1 10 300` # wait for 10-300s
- echo "Stopping ES node"
- kill -TERM `cat es.pid`
- sleep `jot -r 1 10 60` # wait for 10-60s
-done
-```
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/cluster-test.go b/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/cluster-test.go
deleted file mode 100644
index 401232d242..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster-test/cluster-test.go
+++ /dev/null
@@ -1,357 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package main
-
-import (
- "encoding/json"
- "errors"
- "flag"
- "fmt"
- "log"
- "math/rand"
- "os"
- "runtime"
- "strings"
- "sync/atomic"
- "time"
-
- "github.com/olivere/elastic"
-)
-
-type Tweet struct {
- User string `json:"user"`
- Message string `json:"message"`
- Retweets int `json:"retweets"`
- Image string `json:"image,omitempty"`
- Created time.Time `json:"created,omitempty"`
- Tags []string `json:"tags,omitempty"`
- Location string `json:"location,omitempty"`
- Suggest *elastic.SuggestField `json:"suggest_field,omitempty"`
-}
-
-var (
- nodes = flag.String("nodes", "", "comma-separated list of ES URLs (e.g. 'http://192.168.2.10:9200,http://192.168.2.11:9200')")
- n = flag.Int("n", 5, "number of goroutines that run searches")
- index = flag.String("index", "twitter", "name of ES index to use")
- errorlogfile = flag.String("errorlog", "", "error log file")
- infologfile = flag.String("infolog", "", "info log file")
- tracelogfile = flag.String("tracelog", "", "trace log file")
- retries = flag.Int("retries", elastic.DefaultMaxRetries, "number of retries")
- sniff = flag.Bool("sniff", elastic.DefaultSnifferEnabled, "enable or disable sniffer")
- sniffer = flag.Duration("sniffer", elastic.DefaultSnifferInterval, "sniffer interval")
- healthcheck = flag.Bool("healthcheck", elastic.DefaultHealthcheckEnabled, "enable or disable healthchecks")
- healthchecker = flag.Duration("healthchecker", elastic.DefaultHealthcheckInterval, "healthcheck interval")
-)
-
-func main() {
- flag.Parse()
-
- runtime.GOMAXPROCS(runtime.NumCPU())
-
- if *nodes == "" {
- log.Fatal("no nodes specified")
- }
- urls := strings.SplitN(*nodes, ",", -1)
-
- testcase, err := NewTestCase(*index, urls)
- if err != nil {
- log.Fatal(err)
- }
-
- testcase.SetErrorLogFile(*errorlogfile)
- testcase.SetInfoLogFile(*infologfile)
- testcase.SetTraceLogFile(*tracelogfile)
- testcase.SetMaxRetries(*retries)
- testcase.SetHealthcheck(*healthcheck)
- testcase.SetHealthcheckInterval(*healthchecker)
- testcase.SetSniff(*sniff)
- testcase.SetSnifferInterval(*sniffer)
-
- if err := testcase.Run(*n); err != nil {
- log.Fatal(err)
- }
-
- select {}
-}
-
-type RunInfo struct {
- Success bool
-}
-
-type TestCase struct {
- nodes []string
- client *elastic.Client
- runs int64
- failures int64
- runCh chan RunInfo
- index string
- errorlogfile string
- infologfile string
- tracelogfile string
- maxRetries int
- healthcheck bool
- healthcheckInterval time.Duration
- sniff bool
- snifferInterval time.Duration
-}
-
-func NewTestCase(index string, nodes []string) (*TestCase, error) {
- if index == "" {
- return nil, errors.New("no index name specified")
- }
-
- return &TestCase{
- index: index,
- nodes: nodes,
- runCh: make(chan RunInfo),
- }, nil
-}
-
-func (t *TestCase) SetIndex(name string) {
- t.index = name
-}
-
-func (t *TestCase) SetErrorLogFile(name string) {
- t.errorlogfile = name
-}
-
-func (t *TestCase) SetInfoLogFile(name string) {
- t.infologfile = name
-}
-
-func (t *TestCase) SetTraceLogFile(name string) {
- t.tracelogfile = name
-}
-
-func (t *TestCase) SetMaxRetries(n int) {
- t.maxRetries = n
-}
-
-func (t *TestCase) SetSniff(enabled bool) {
- t.sniff = enabled
-}
-
-func (t *TestCase) SetSnifferInterval(d time.Duration) {
- t.snifferInterval = d
-}
-
-func (t *TestCase) SetHealthcheck(enabled bool) {
- t.healthcheck = enabled
-}
-
-func (t *TestCase) SetHealthcheckInterval(d time.Duration) {
- t.healthcheckInterval = d
-}
-
-func (t *TestCase) Run(n int) error {
- if err := t.setup(); err != nil {
- return err
- }
-
- for i := 1; i < n; i++ {
- go t.search()
- }
-
- go t.monitor()
-
- return nil
-}
-
-func (t *TestCase) monitor() {
- print := func() {
- fmt.Printf("\033[32m%5d\033[0m; \033[31m%5d\033[0m: %s%s\r", t.runs, t.failures, t.client.String(), " ")
- }
-
- for {
- select {
- case run := <-t.runCh:
- atomic.AddInt64(&t.runs, 1)
- if !run.Success {
- atomic.AddInt64(&t.failures, 1)
- fmt.Println()
- }
- print()
- case <-time.After(5 * time.Second):
- // Print stats after some inactivity
- print()
- break
- }
- }
-}
-
-func (t *TestCase) setup() error {
- var errorlogger *log.Logger
- if t.errorlogfile != "" {
- f, err := os.OpenFile(t.errorlogfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
- if err != nil {
- return err
- }
- errorlogger = log.New(f, "", log.Ltime|log.Lmicroseconds|log.Lshortfile)
- }
-
- var infologger *log.Logger
- if t.infologfile != "" {
- f, err := os.OpenFile(t.infologfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
- if err != nil {
- return err
- }
- infologger = log.New(f, "", log.LstdFlags)
- }
-
- // Trace request and response details like this
- var tracelogger *log.Logger
- if t.tracelogfile != "" {
- f, err := os.OpenFile(t.tracelogfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
- if err != nil {
- return err
- }
- tracelogger = log.New(f, "", log.LstdFlags)
- }
-
- client, err := elastic.NewClient(
- elastic.SetURL(t.nodes...),
- elastic.SetErrorLog(errorlogger),
- elastic.SetInfoLog(infologger),
- elastic.SetTraceLog(tracelogger),
- elastic.SetMaxRetries(t.maxRetries),
- elastic.SetSniff(t.sniff),
- elastic.SetSnifferInterval(t.snifferInterval),
- elastic.SetHealthcheck(t.healthcheck),
- elastic.SetHealthcheckInterval(t.healthcheckInterval))
- if err != nil {
- // Handle error
- return err
- }
- t.client = client
-
- // Use the IndexExists service to check if a specified index exists.
- exists, err := t.client.IndexExists(t.index).Do()
- if err != nil {
- return err
- }
- if exists {
- deleteIndex, err := t.client.DeleteIndex(t.index).Do()
- if err != nil {
- return err
- }
- if !deleteIndex.Acknowledged {
- return errors.New("delete index not acknowledged")
- }
- }
-
- // Create a new index.
- createIndex, err := t.client.CreateIndex(t.index).Do()
- if err != nil {
- return err
- }
- if !createIndex.Acknowledged {
- return errors.New("create index not acknowledged")
- }
-
- // Index a tweet (using JSON serialization)
- tweet1 := Tweet{User: "olivere", Message: "Take Five", Retweets: 0}
- _, err = t.client.Index().
- Index(t.index).
- Type("tweet").
- Id("1").
- BodyJson(tweet1).
- Do()
- if err != nil {
- return err
- }
-
- // Index a second tweet (by string)
- tweet2 := `{"user" : "olivere", "message" : "It's a Raggy Waltz"}`
- _, err = t.client.Index().
- Index(t.index).
- Type("tweet").
- Id("2").
- BodyString(tweet2).
- Do()
- if err != nil {
- return err
- }
-
- // Flush to make sure the documents got written.
- _, err = t.client.Flush().Index(t.index).Do()
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (t *TestCase) search() {
- // Loop forever to check for connection issues
- for {
- // Get tweet with specified ID
- get1, err := t.client.Get().
- Index(t.index).
- Type("tweet").
- Id("1").
- Do()
- if err != nil {
- //failf("Get failed: %v", err)
- t.runCh <- RunInfo{Success: false}
- continue
- }
- if !get1.Found {
- //log.Printf("Document %s not found\n", "1")
- //fmt.Printf("Got document %s in version %d from index %s, type %s\n", get1.Id, get1.Version, get1.Index, get1.Type)
- t.runCh <- RunInfo{Success: false}
- continue
- }
-
- // Search with a term query
- termQuery := elastic.NewTermQuery("user", "olivere")
- searchResult, err := t.client.Search().
- Index(t.index). // search in index t.index
- Query(&termQuery). // specify the query
- Sort("user", true). // sort by "user" field, ascending
- From(0).Size(10). // take documents 0-9
- Pretty(true). // pretty print request and response JSON
- Do() // execute
- if err != nil {
- //failf("Search failed: %v\n", err)
- t.runCh <- RunInfo{Success: false}
- continue
- }
-
- // searchResult is of type SearchResult and returns hits, suggestions,
- // and all kinds of other information from Elasticsearch.
- //fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis)
-
- // Number of hits
- if searchResult.Hits != nil {
- //fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits)
-
- // Iterate through results
- for _, hit := range searchResult.Hits.Hits {
- // hit.Index contains the name of the index
-
- // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
- var tweet Tweet
- err := json.Unmarshal(*hit.Source, &tweet)
- if err != nil {
- // Deserialization failed
- //failf("Deserialize failed: %v\n", err)
- t.runCh <- RunInfo{Success: false}
- continue
- }
-
- // Work with tweet
- //fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- } else {
- // No hits
- //fmt.Print("Found no tweets\n")
- }
-
- t.runCh <- RunInfo{Success: true}
-
- // Sleep some time
- time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_health_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/cluster_health_test.go
deleted file mode 100644
index 455f1b87dd..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_health_test.go
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "net/url"
- "testing"
-)
-
-func TestClusterHealth(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Get cluster health
- res, err := client.ClusterHealth().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected res to be != nil; got: %v", res)
- }
- if res.Status != "green" && res.Status != "red" && res.Status != "yellow" {
- t.Fatalf("expected status \"green\", \"red\", or \"yellow\"; got: %q", res.Status)
- }
-}
-
-func TestClusterHealthURLs(t *testing.T) {
- tests := []struct {
- Service *ClusterHealthService
- ExpectedPath string
- ExpectedParams url.Values
- }{
- {
- Service: &ClusterHealthService{
- indices: []string{},
- },
- ExpectedPath: "/_cluster/health/",
- },
- {
- Service: &ClusterHealthService{
- indices: []string{"twitter"},
- },
- ExpectedPath: "/_cluster/health/twitter",
- },
- {
- Service: &ClusterHealthService{
- indices: []string{"twitter", "gplus"},
- },
- ExpectedPath: "/_cluster/health/twitter%2Cgplus",
- },
- {
- Service: &ClusterHealthService{
- indices: []string{"twitter"},
- waitForStatus: "yellow",
- },
- ExpectedPath: "/_cluster/health/twitter",
- ExpectedParams: url.Values{"wait_for_status": []string{"yellow"}},
- },
- }
-
- for _, test := range tests {
- gotPath, gotParams, err := test.Service.buildURL()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if gotPath != test.ExpectedPath {
- t.Errorf("expected URL path = %q; got: %q", test.ExpectedPath, gotPath)
- }
- if gotParams.Encode() != test.ExpectedParams.Encode() {
- t.Errorf("expected URL params = %v; got: %v", test.ExpectedParams, gotParams)
- }
- }
-}
-
-func TestClusterHealthWaitForStatus(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Cluster health on an index that does not exist should never get to yellow
- health, err := client.ClusterHealth().Index("no-such-index").WaitForStatus("yellow").Timeout("1s").Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if health.TimedOut != true {
- t.Fatalf("expected to timeout; got: %v", health.TimedOut)
- }
- if health.Status != "red" {
- t.Fatalf("expected health = %q; got: %q", "red", health.Status)
- }
-
- // Cluster wide health
- health, err = client.ClusterHealth().WaitForStatus("green").Timeout("10s").Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if health.TimedOut != false {
- t.Fatalf("expected no timeout; got: %v "+
- "(does your local cluster contain unassigned shards?)", health.TimedOut)
- }
- if health.Status != "green" {
- t.Fatalf("expected health = %q; got: %q", "green", health.Status)
- }
-
- // Cluster wide health via shortcut on client
- err = client.WaitForGreenStatus("10s")
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_state_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/cluster_state_test.go
deleted file mode 100644
index 9c036bd87c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_state_test.go
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "net/url"
- "testing"
-)
-
-func TestClusterState(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Get cluster state
- res, err := client.ClusterState().Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected res to be != nil; got: %v", res)
- }
- if res.ClusterName == "" {
- t.Fatalf("expected a cluster name; got: %q", res.ClusterName)
- }
-}
-
-func TestClusterStateURLs(t *testing.T) {
- tests := []struct {
- Service *ClusterStateService
- ExpectedPath string
- ExpectedParams url.Values
- }{
- {
- Service: &ClusterStateService{
- indices: []string{},
- metrics: []string{},
- },
- ExpectedPath: "/_cluster/state/_all/_all",
- },
- {
- Service: &ClusterStateService{
- indices: []string{"twitter"},
- metrics: []string{},
- },
- ExpectedPath: "/_cluster/state/_all/twitter",
- },
- {
- Service: &ClusterStateService{
- indices: []string{"twitter", "gplus"},
- metrics: []string{},
- },
- ExpectedPath: "/_cluster/state/_all/twitter%2Cgplus",
- },
- {
- Service: &ClusterStateService{
- indices: []string{},
- metrics: []string{"nodes"},
- },
- ExpectedPath: "/_cluster/state/nodes/_all",
- },
- {
- Service: &ClusterStateService{
- indices: []string{"twitter"},
- metrics: []string{"nodes"},
- },
- ExpectedPath: "/_cluster/state/nodes/twitter",
- },
- {
- Service: &ClusterStateService{
- indices: []string{"twitter"},
- metrics: []string{"nodes"},
- masterTimeout: "1s",
- },
- ExpectedPath: "/_cluster/state/nodes/twitter",
- ExpectedParams: url.Values{"master_timeout": []string{"1s"}},
- },
- }
-
- for _, test := range tests {
- gotPath, gotParams, err := test.Service.buildURL()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if gotPath != test.ExpectedPath {
- t.Errorf("expected URL path = %q; got: %q", test.ExpectedPath, gotPath)
- }
- if gotParams.Encode() != test.ExpectedParams.Encode() {
- t.Errorf("expected URL params = %v; got: %v", test.ExpectedParams, gotParams)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_stats_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/cluster_stats_test.go
deleted file mode 100644
index 74326a6e7d..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/cluster_stats_test.go
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "net/url"
- "testing"
-)
-
-func TestClusterStats(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Get cluster stats
- res, err := client.ClusterStats().Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected res to be != nil; got: %v", res)
- }
- if res.ClusterName == "" {
- t.Fatalf("expected a cluster name; got: %q", res.ClusterName)
- }
-}
-
-func TestClusterStatsURLs(t *testing.T) {
- fFlag := false
- tFlag := true
-
- tests := []struct {
- Service *ClusterStatsService
- ExpectedPath string
- ExpectedParams url.Values
- }{
- {
- Service: &ClusterStatsService{
- nodeId: []string{},
- },
- ExpectedPath: "/_cluster/stats",
- },
- {
- Service: &ClusterStatsService{
- nodeId: []string{"node1"},
- },
- ExpectedPath: "/_cluster/stats/nodes/node1",
- },
- {
- Service: &ClusterStatsService{
- nodeId: []string{"node1", "node2"},
- },
- ExpectedPath: "/_cluster/stats/nodes/node1%2Cnode2",
- },
- {
- Service: &ClusterStatsService{
- nodeId: []string{},
- flatSettings: &tFlag,
- },
- ExpectedPath: "/_cluster/stats",
- ExpectedParams: url.Values{"flat_settings": []string{"true"}},
- },
- {
- Service: &ClusterStatsService{
- nodeId: []string{"node1"},
- flatSettings: &fFlag,
- },
- ExpectedPath: "/_cluster/stats/nodes/node1",
- ExpectedParams: url.Values{"flat_settings": []string{"false"}},
- },
- }
-
- for _, test := range tests {
- gotPath, gotParams, err := test.Service.buildURL()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if gotPath != test.ExpectedPath {
- t.Errorf("expected URL path = %q; got: %q", test.ExpectedPath, gotPath)
- }
- if gotParams.Encode() != test.ExpectedParams.Encode() {
- t.Errorf("expected URL params = %v; got: %v", test.ExpectedParams, gotParams)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/count_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/count_test.go
deleted file mode 100644
index 44ecadf220..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/count_test.go
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import "testing"
-
-func TestCountURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Types []string
- Expected string
- }{
- {
- []string{},
- []string{},
- "/_all/_count",
- },
- {
- []string{},
- []string{"tweet"},
- "/_all/tweet/_count",
- },
- {
- []string{"twitter-*"},
- []string{"tweet", "follower"},
- "/twitter-%2A/tweet%2Cfollower/_count",
- },
- {
- []string{"twitter-2014", "twitter-2015"},
- []string{"tweet", "follower"},
- "/twitter-2014%2Ctwitter-2015/tweet%2Cfollower/_count",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.Count().Indices(test.Indices...).Types(test.Types...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
-
-func TestCount(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Count documents
- count, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 3 {
- t.Errorf("expected Count = %d; got %d", 3, count)
- }
-
- // Count documents
- count, err = client.Count(testIndexName).Type("tweet").Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 3 {
- t.Errorf("expected Count = %d; got %d", 3, count)
- }
-
- // Count documents
- count, err = client.Count(testIndexName).Type("gezwitscher").Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 0 {
- t.Errorf("expected Count = %d; got %d", 0, count)
- }
-
- // Count with query
- query := NewTermQuery("user", "olivere")
- count, err = client.Count(testIndexName).Query(query).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 2 {
- t.Errorf("expected Count = %d; got %d", 2, count)
- }
-
- // Count with query and type
- query = NewTermQuery("user", "olivere")
- count, err = client.Count(testIndexName).Type("tweet").Query(query).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 2 {
- t.Errorf("expected Count = %d; got %d", 2, count)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/decoder_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/decoder_test.go
deleted file mode 100644
index 5cfce9f5d4..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/decoder_test.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "bytes"
- "encoding/json"
- "sync/atomic"
- "testing"
-)
-
-type decoder struct {
- dec json.Decoder
-
- N int64
-}
-
-func (d *decoder) Decode(data []byte, v interface{}) error {
- atomic.AddInt64(&d.N, 1)
- dec := json.NewDecoder(bytes.NewReader(data))
- dec.UseNumber()
- return dec.Decode(v)
-}
-
-func TestDecoder(t *testing.T) {
- dec := &decoder{}
- client := setupTestClientAndCreateIndex(t, SetDecoder(dec), SetMaxRetries(0))
-
- tweet := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- indexResult, err := client.Index().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- BodyJson(&tweet).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexResult == nil {
- t.Errorf("expected result to be != nil; got: %v", indexResult)
- }
- if dec.N <= 0 {
- t.Errorf("expected at least 1 call of decoder; got: %d", dec.N)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/delete_by_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/delete_by_query_test.go
deleted file mode 100644
index a9a235d24e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/delete_by_query_test.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestDeleteByQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Count documents
- count, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 3 {
- t.Fatalf("expected count = %d; got: %d", 3, count)
- }
-
- // Delete all documents by sandrae
- q := NewTermQuery("user", "sandrae")
- res, err := client.DeleteByQuery().Index(testIndexName).Type("tweet").Query(q).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected response != nil; got: %v", res)
- }
- idx, found := res.Indices[testIndexName]
- if !found {
- t.Errorf("expected Found = true; got: %v", found)
- }
- if idx.Shards.Failed > 0 {
- t.Errorf("expected no failed shards; got: %d", idx.Shards.Failed)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- count, err = client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 2 {
- t.Fatalf("expected Count = %d; got: %d", 2, count)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/delete_mapping_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/delete_mapping_test.go
deleted file mode 100644
index 517477d458..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/delete_mapping_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestDeleteMappingURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Types []string
- Expected string
- }{
- {
- []string{"twitter"},
- []string{"tweet"},
- "/twitter/_mapping/tweet",
- },
- {
- []string{"store-1", "store-2"},
- []string{"tweet", "user"},
- "/store-1%2Cstore-2/_mapping/tweet%2Cuser",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.DeleteMapping().Index(test.Indices...).Type(test.Types...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/delete_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/delete_test.go
deleted file mode 100644
index ed07842fec..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/delete_test.go
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestDelete(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Count documents
- count, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 3 {
- t.Errorf("expected Count = %d; got %d", 3, count)
- }
-
- // Delete document 1
- res, err := client.Delete().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != true {
- t.Errorf("expected Found = true; got %v", res.Found)
- }
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- count, err = client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 2 {
- t.Errorf("expected Count = %d; got %d", 2, count)
- }
-
- // Delete non existent document 99
- res, err = client.Delete().Index(testIndexName).Type("tweet").Id("99").Refresh(true).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != false {
- t.Errorf("expected Found = false; got %v", res.Found)
- }
- count, err = client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 2 {
- t.Errorf("expected Count = %d; got %d", 2, count)
- }
-}
-
-func TestDeleteWithEmptyIDFails(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Delete document with blank ID
- _, err = client.Delete().Index(testIndexName).Type("tweet").Id("").Do()
- if err != ErrMissingId {
- t.Fatalf("expected to not accept delete without identifier, got: %v", err)
- }
-
- // Delete document with blank type
- _, err = client.Delete().Index(testIndexName).Type("").Id("1").Do()
- if err != ErrMissingType {
- t.Fatalf("expected to not accept delete without type, got: %v", err)
- }
-
- // Delete document with blank index
- _, err = client.Delete().Index("").Type("tweet").Id("1").Do()
- if err != ErrMissingIndex {
- t.Fatalf("expected to not accept delete without index, got: %v", err)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/errors_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/errors_test.go
deleted file mode 100644
index 553288d56c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/errors_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package elastic
-
-import (
- "bufio"
- "fmt"
- "net/http"
- "strings"
- "testing"
-)
-
-func TestResponseError(t *testing.T) {
- message := "Something went seriously wrong."
- raw := "HTTP/1.1 500 Internal Server Error\r\n" +
- "\r\n" +
- `{"status":500,"error":"` + message + `"}` + "\r\n"
- r := bufio.NewReader(strings.NewReader(raw))
-
- resp, err := http.ReadResponse(r, nil)
- if err != nil {
- t.Fatal(err)
- }
- err = checkResponse(resp)
- if err == nil {
- t.Fatalf("expected error; got: %v", err)
- }
-
- // Check for correct error message
- expected := fmt.Sprintf("elastic: Error %d (%s): %s", resp.StatusCode, http.StatusText(resp.StatusCode), message)
- got := err.Error()
- if got != expected {
- t.Fatalf("expected %q; got: %q", expected, got)
- }
-
- // Check that error is of type *elastic.Error, which contains additional information
- e, ok := err.(*Error)
- if !ok {
- t.Fatal("expected error to be of type *elastic.Error")
- }
- if e.Status != resp.StatusCode {
- t.Fatalf("expected status code %d; got: %d", resp.StatusCode, e.Status)
- }
- if e.Message != message {
- t.Fatalf("expected error message %q; got: %q", message, e.Message)
- }
-}
-
-func TestResponseErrorHTML(t *testing.T) {
- raw := "HTTP/1.1 413 Request Entity Too Large\r\n" +
- "\r\n" +
- `
-
413 Request Entity Too Large
-
-413 Request Entity Too Large
-
nginx/1.6.2
-
-` + "\r\n"
- r := bufio.NewReader(strings.NewReader(raw))
-
- resp, err := http.ReadResponse(r, nil)
- if err != nil {
- t.Fatal(err)
- }
- err = checkResponse(resp)
- if err == nil {
- t.Fatalf("expected error; got: %v", err)
- }
-
- // Check for correct error message
- expected := fmt.Sprintf("elastic: Error %d (%s)", http.StatusRequestEntityTooLarge, http.StatusText(http.StatusRequestEntityTooLarge))
- got := err.Error()
- if got != expected {
- t.Fatalf("expected %q; got: %q", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/example_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/example_test.go
deleted file mode 100644
index 7789e729c7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/example_test.go
+++ /dev/null
@@ -1,547 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic_test
-
-import (
- "encoding/json"
- "fmt"
- "log"
- "os"
- "reflect"
- "time"
-
- "github.com/olivere/elastic"
-)
-
-type Tweet struct {
- User string `json:"user"`
- Message string `json:"message"`
- Retweets int `json:"retweets"`
- Image string `json:"image,omitempty"`
- Created time.Time `json:"created,omitempty"`
- Tags []string `json:"tags,omitempty"`
- Location string `json:"location,omitempty"`
- Suggest *elastic.SuggestField `json:"suggest_field,omitempty"`
-}
-
-func Example() {
- errorlog := log.New(os.Stdout, "APP ", log.LstdFlags)
-
- // Obtain a client. You can provide your own HTTP client here.
- client, err := elastic.NewClient(elastic.SetErrorLog(errorlog))
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // Trace request and response details like this
- //client.SetTracer(log.New(os.Stdout, "", 0))
-
- // Ping the Elasticsearch server to get e.g. the version number
- info, code, err := client.Ping().Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- fmt.Printf("Elasticsearch returned with code %d and version %s", code, info.Version.Number)
-
- // Getting the ES version number is quite common, so there's a shortcut
- esversion, err := client.ElasticsearchVersion("http://127.0.0.1:9200")
- if err != nil {
- // Handle error
- panic(err)
- }
- fmt.Printf("Elasticsearch version %s", esversion)
-
- // Use the IndexExists service to check if a specified index exists.
- exists, err := client.IndexExists("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if !exists {
- // Create a new index.
- createIndex, err := client.CreateIndex("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if !createIndex.Acknowledged {
- // Not acknowledged
- }
- }
-
- // Index a tweet (using JSON serialization)
- tweet1 := Tweet{User: "olivere", Message: "Take Five", Retweets: 0}
- put1, err := client.Index().
- Index("twitter").
- Type("tweet").
- Id("1").
- BodyJson(tweet1).
- Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- fmt.Printf("Indexed tweet %s to index %s, type %s\n", put1.Id, put1.Index, put1.Type)
-
- // Index a second tweet (by string)
- tweet2 := `{"user" : "olivere", "message" : "It's a Raggy Waltz"}`
- put2, err := client.Index().
- Index("twitter").
- Type("tweet").
- Id("2").
- BodyString(tweet2).
- Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- fmt.Printf("Indexed tweet %s to index %s, type %s\n", put2.Id, put2.Index, put2.Type)
-
- // Get tweet with specified ID
- get1, err := client.Get().
- Index("twitter").
- Type("tweet").
- Id("1").
- Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if get1.Found {
- fmt.Printf("Got document %s in version %d from index %s, type %s\n", get1.Id, get1.Version, get1.Index, get1.Type)
- }
-
- // Flush to make sure the documents got written.
- _, err = client.Flush().Index("twitter").Do()
- if err != nil {
- panic(err)
- }
-
- // Search with a term query
- termQuery := elastic.NewTermQuery("user", "olivere")
- searchResult, err := client.Search().
- Index("twitter"). // search in index "twitter"
- Query(&termQuery). // specify the query
- Sort("user", true). // sort by "user" field, ascending
- From(0).Size(10). // take documents 0-9
- Pretty(true). // pretty print request and response JSON
- Do() // execute
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // searchResult is of type SearchResult and returns hits, suggestions,
- // and all kinds of other information from Elasticsearch.
- fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis)
-
- // Each is a convenience function that iterates over hits in a search result.
- // It makes sure you don't need to check for nil values in the response.
- // However, it ignores errors in serialization. If you want full control
- // over iterating the hits, see below.
- var ttyp Tweet
- for _, item := range searchResult.Each(reflect.TypeOf(ttyp)) {
- t := item.(Tweet)
- fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- // TotalHits is another convenience function that works even when something goes wrong.
- fmt.Printf("Found a total of %d tweets\n", searchResult.TotalHits())
-
- // Here's how you iterate through results with full control over each step.
- if searchResult.Hits != nil {
- fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits)
-
- // Iterate through results
- for _, hit := range searchResult.Hits.Hits {
- // hit.Index contains the name of the index
-
- // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
- var t Tweet
- err := json.Unmarshal(*hit.Source, &t)
- if err != nil {
- // Deserialization failed
- }
-
- // Work with tweet
- fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- } else {
- // No hits
- fmt.Print("Found no tweets\n")
- }
-
- // Update a tweet by the update API of Elasticsearch.
- // We just increment the number of retweets.
- update, err := client.Update().Index("twitter").Type("tweet").Id("1").
- Script("ctx._source.retweets += num").
- ScriptParams(map[string]interface{}{"num": 1}).
- Upsert(map[string]interface{}{"retweets": 0}).
- Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- fmt.Printf("New version of tweet %q is now %d", update.Id, update.Version)
-
- // ...
-
- // Delete an index.
- deleteIndex, err := client.DeleteIndex("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if !deleteIndex.Acknowledged {
- // Not acknowledged
- }
-}
-
-func ExampleClient_NewClient_default() {
- // Obtain a client to the Elasticsearch instance on http://localhost:9200.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- fmt.Printf("connection failed: %v\n", err)
- } else {
- fmt.Println("connected")
- }
- _ = client
- // Output:
- // connected
-}
-
-func ExampleClient_NewClient_cluster() {
- // Obtain a client for an Elasticsearch cluster of two nodes,
- // running on 10.0.1.1 and 10.0.1.2.
- client, err := elastic.NewClient(elastic.SetURL("http://10.0.1.1:9200", "http://10.0.1.2:9200"))
- if err != nil {
- // Handle error
- panic(err)
- }
- _ = client
-}
-
-func ExampleClient_NewClient_manyOptions() {
- // Obtain a client for an Elasticsearch cluster of two nodes,
- // running on 10.0.1.1 and 10.0.1.2. Do not run the sniffer.
- // Set the healthcheck interval to 10s. When requests fail,
- // retry 5 times. Print error messages to os.Stderr and informational
- // messages to os.Stdout.
- client, err := elastic.NewClient(
- elastic.SetURL("http://10.0.1.1:9200", "http://10.0.1.2:9200"),
- elastic.SetSniff(false),
- elastic.SetHealthcheckInterval(10*time.Second),
- elastic.SetMaxRetries(5),
- elastic.SetErrorLog(log.New(os.Stderr, "ELASTIC ", log.LstdFlags)),
- elastic.SetInfoLog(log.New(os.Stdout, "", log.LstdFlags)))
- if err != nil {
- // Handle error
- panic(err)
- }
- _ = client
-}
-
-func ExampleIndexExistsService() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
- // Use the IndexExists service to check if the index "twitter" exists.
- exists, err := client.IndexExists("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if exists {
- // ...
- }
-}
-
-func ExampleCreateIndexService() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
- // Create a new index.
- createIndex, err := client.CreateIndex("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if !createIndex.Acknowledged {
- // Not acknowledged
- }
-}
-
-func ExampleDeleteIndexService() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
- // Delete an index.
- deleteIndex, err := client.DeleteIndex("twitter").Do()
- if err != nil {
- // Handle error
- panic(err)
- }
- if !deleteIndex.Acknowledged {
- // Not acknowledged
- }
-}
-
-func ExampleSearchService() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // Search with a term query
- termQuery := elastic.NewTermQuery("user", "olivere")
- searchResult, err := client.Search().
- Index("twitter"). // search in index "twitter"
- Query(&termQuery). // specify the query
- Sort("user", true). // sort by "user" field, ascending
- From(0).Size(10). // take documents 0-9
- Pretty(true). // pretty print request and response JSON
- Do() // execute
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // searchResult is of type SearchResult and returns hits, suggestions,
- // and all kinds of other information from Elasticsearch.
- fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis)
-
- // Number of hits
- if searchResult.Hits != nil {
- fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits)
-
- // Iterate through results
- for _, hit := range searchResult.Hits.Hits {
- // hit.Index contains the name of the index
-
- // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
- var t Tweet
- err := json.Unmarshal(*hit.Source, &t)
- if err != nil {
- // Deserialization failed
- }
-
- // Work with tweet
- fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- } else {
- // No hits
- fmt.Print("Found no tweets\n")
- }
-}
-
-func ExampleAggregations() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // Create an aggregation for users and a sub-aggregation for a date histogram of tweets (per year).
- timeline := elastic.NewTermsAggregation().Field("user").Size(10).OrderByCountDesc()
- histogram := elastic.NewDateHistogramAggregation().Field("created").Interval("year")
- timeline = timeline.SubAggregation("history", histogram)
-
- // Search with a term query
- searchResult, err := client.Search().
- Index("twitter"). // search in index "twitter"
- Query(elastic.NewMatchAllQuery()). // return all results, but ...
- SearchType("count"). // ... do not return hits, just the count
- Aggregation("timeline", timeline). // add our aggregation to the query
- Pretty(true). // pretty print request and response JSON
- Do() // execute
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // Access "timeline" aggregate in search result.
- agg, found := searchResult.Aggregations.Terms("timeline")
- if !found {
- log.Fatalf("we sould have a terms aggregation called %q", "timeline")
- }
- for _, userBucket := range agg.Buckets {
- // Every bucket should have the user field as key.
- user := userBucket.Key
-
- // The sub-aggregation history should have the number of tweets per year.
- histogram, found := userBucket.DateHistogram("history")
- if found {
- for _, year := range histogram.Buckets {
- fmt.Printf("user %q has %d tweets in %q\n", user, year.DocCount, year.KeyAsString)
- }
- }
- }
-}
-
-func ExampleSearchResult() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Do a search
- searchResult, err := client.Search().Index("twitter").Query(elastic.NewMatchAllQuery()).Do()
- if err != nil {
- panic(err)
- }
-
- // searchResult is of type SearchResult and returns hits, suggestions,
- // and all kinds of other information from Elasticsearch.
- fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis)
-
- // Each is a utility function that iterates over hits in a search result.
- // It makes sure you don't need to check for nil values in the response.
- // However, it ignores errors in serialization. If you want full control
- // over iterating the hits, see below.
- var ttyp Tweet
- for _, item := range searchResult.Each(reflect.TypeOf(ttyp)) {
- t := item.(Tweet)
- fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- fmt.Printf("Found a total of %d tweets\n", searchResult.TotalHits())
-
- // Here's how you iterate hits with full control.
- if searchResult.Hits != nil {
- fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits)
-
- // Iterate through results
- for _, hit := range searchResult.Hits.Hits {
- // hit.Index contains the name of the index
-
- // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
- var t Tweet
- err := json.Unmarshal(*hit.Source, &t)
- if err != nil {
- // Deserialization failed
- }
-
- // Work with tweet
- fmt.Printf("Tweet by %s: %s\n", t.User, t.Message)
- }
- } else {
- // No hits
- fmt.Print("Found no tweets\n")
- }
-}
-
-func ExamplePutTemplateService() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Create search template
- tmpl := `{"template":{"query":{"match":{"title":"{{query_string}}"}}}}`
-
- // Create template
- resp, err := client.PutTemplate().
- Id("my-search-template"). // Name of the template
- BodyString(tmpl). // Search template itself
- Do() // Execute
- if err != nil {
- panic(err)
- }
- if resp.Created {
- fmt.Println("search template created")
- }
-}
-
-func ExampleGetTemplateService() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Get template stored under "my-search-template"
- resp, err := client.GetTemplate().Id("my-search-template").Do()
- if err != nil {
- panic(err)
- }
- fmt.Printf("search template is: %q\n", resp.Template)
-}
-
-func ExampleDeleteTemplateService() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Delete template
- resp, err := client.DeleteTemplate().Id("my-search-template").Do()
- if err != nil {
- panic(err)
- }
- if resp != nil && resp.Found {
- fmt.Println("template deleted")
- }
-}
-
-func ExampleClusterHealthService() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Get cluster health
- res, err := client.ClusterHealth().Index("twitter").Do()
- if err != nil {
- panic(err)
- }
- if res == nil {
- panic(err)
- }
- fmt.Printf("Cluster status is %q\n", res.Status)
-}
-
-func ExampleClusterHealthService_WaitForGreen() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Wait for status green
- res, err := client.ClusterHealth().WaitForStatus("green").Timeout("15s").Do()
- if err != nil {
- panic(err)
- }
- if res.TimedOut {
- fmt.Printf("time out waiting for cluster status %q\n", "green")
- } else {
- fmt.Printf("cluster status is %q\n", res.Status)
- }
-}
-
-func ExampleClusterStateService() {
- client, err := elastic.NewClient()
- if err != nil {
- panic(err)
- }
-
- // Get cluster state
- res, err := client.ClusterState().Metric("version").Do()
- if err != nil {
- panic(err)
- }
- fmt.Printf("Cluster %q has version %d", res.ClusterName, res.Version)
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/exists_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/exists_test.go
deleted file mode 100644
index 80573a7fcb..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/exists_test.go
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import "testing"
-
-func TestExists(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))
-
- exists, err := client.Exists().Index(testIndexName).Type("comment").Id("1").Parent("tweet").Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Fatal("expected document to exist")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/explain_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/explain_test.go
deleted file mode 100644
index e799d6c521..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/explain_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import "testing"
-
-func TestExplain(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- indexResult, err := client.Index().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- BodyJson(&tweet1).
- Refresh(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexResult == nil {
- t.Errorf("expected result to be != nil; got: %v", indexResult)
- }
-
- // Explain
- query := NewTermQuery("user", "olivere")
- expl, err := client.Explain(testIndexName, "tweet", "1").Query(query).Do()
- if err != nil {
- t.Fatal(err)
- }
- if expl == nil {
- t.Fatal("expected to return an explanation")
- }
- if !expl.Matched {
- t.Errorf("expected matched to be %v; got: %v", true, expl.Matched)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/fetch_source_context_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/fetch_source_context_test.go
deleted file mode 100644
index ae15a10ec6..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/fetch_source_context_test.go
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFetchSourceContextNoFetchSource(t *testing.T) {
- builder := NewFetchSourceContext(false)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `false`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFetchSourceContextNoFetchSourceIgnoreIncludesAndExcludes(t *testing.T) {
- builder := NewFetchSourceContext(false).Include("a", "b").Exclude("c")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `false`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFetchSourceContextFetchSource(t *testing.T) {
- builder := NewFetchSourceContext(true)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"excludes":[],"includes":[]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFetchSourceContextFetchSourceWithIncludesOnly(t *testing.T) {
- builder := NewFetchSourceContext(true).Include("a", "b")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"excludes":[],"includes":["a","b"]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFetchSourceContextFetchSourceWithIncludesAndExcludes(t *testing.T) {
- builder := NewFetchSourceContext(true).Include("a", "b").Exclude("c")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"excludes":["c"],"includes":["a","b"]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFetchSourceContextQueryDefaults(t *testing.T) {
- builder := NewFetchSourceContext(true)
- values := builder.Query()
- got := values.Encode()
- expected := ""
- if got != expected {
- t.Errorf("expected %q; got: %q", expected, got)
- }
-}
-
-func TestFetchSourceContextQueryNoFetchSource(t *testing.T) {
- builder := NewFetchSourceContext(false)
- values := builder.Query()
- got := values.Encode()
- expected := "_source=false"
- if got != expected {
- t.Errorf("expected %q; got: %q", expected, got)
- }
-}
-
-func TestFetchSourceContextQueryFetchSourceWithIncludesAndExcludes(t *testing.T) {
- builder := NewFetchSourceContext(true).Include("a", "b").Exclude("c")
- values := builder.Query()
- got := values.Encode()
- expected := "_source_exclude=c&_source_include=a%2Cb"
- if got != expected {
- t.Errorf("expected %q; got: %q", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/flush_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/flush_test.go
deleted file mode 100644
index 515ff3a792..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/flush_test.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestFlush(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Flush all indices
- res, err := client.Flush().Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Errorf("expected res to be != nil; got: %v", res)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/geo_point_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/geo_point_test.go
deleted file mode 100644
index ebc28c2ecc..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/geo_point_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoPointSource(t *testing.T) {
- pt := GeoPoint{Lat: 40, Lon: -70}
-
- data, err := json.Marshal(pt.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"lat":40,"lon":-70}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/get_mapping_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/get_mapping_test.go
deleted file mode 100644
index 1cdbd0b2f9..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/get_mapping_test.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestGetMappingURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Types []string
- Expected string
- }{
- {
- []string{},
- []string{},
- "/_all/_mapping/_all",
- },
- {
- []string{},
- []string{"tweet"},
- "/_all/_mapping/tweet",
- },
- {
- []string{"twitter"},
- []string{"tweet"},
- "/twitter/_mapping/tweet",
- },
- {
- []string{"store-1", "store-2"},
- []string{"tweet", "user"},
- "/store-1%2Cstore-2/_mapping/tweet%2Cuser",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.GetMapping().Index(test.Indices...).Type(test.Types...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/get_template_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/get_template_test.go
deleted file mode 100644
index 00aea68997..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/get_template_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestGetPutDeleteTemplate(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // This is a search template, not an index template!
- tmpl := `{
- "template": {
- "query" : { "term" : { "{{my_field}}" : "{{my_value}}" } },
- "size" : "{{my_size}}"
- },
- "params":{
- "my_field" : "user",
- "my_value" : "olivere",
- "my_size" : 5
- }
-}`
- putres, err := client.PutTemplate().Id("elastic-template").BodyString(tmpl).Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if putres == nil {
- t.Fatalf("expected response; got: %v", putres)
- }
- if !putres.Created {
- t.Fatalf("expected template to be created; got: %v", putres.Created)
- }
-
- // Always delete template
- defer client.DeleteTemplate().Id("elastic-template").Do()
-
- // Get template
- getres, err := client.GetTemplate().Id("elastic-template").Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if getres == nil {
- t.Fatalf("expected response; got: %v", getres)
- }
- if getres.Template == "" {
- t.Errorf("expected template %q; got: %q", tmpl, getres.Template)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/get_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/get_test.go
deleted file mode 100644
index 64f544490e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/get_test.go
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGet(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Get document 1
- res, err := client.Get().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != true {
- t.Errorf("expected Found = true; got %v", res.Found)
- }
- if res.Source == nil {
- t.Errorf("expected Source != nil; got %v", res.Source)
- }
-
- // Get non existent document 99
- res, err = client.Get().Index(testIndexName).Type("tweet").Id("99").Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != false {
- t.Errorf("expected Found = false; got %v", res.Found)
- }
- if res.Source != nil {
- t.Errorf("expected Source == nil; got %v", res.Source)
- }
-}
-
-func TestGetWithSourceFiltering(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Get document 1, without source
- res, err := client.Get().Index(testIndexName).Type("tweet").Id("1").FetchSource(false).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != true {
- t.Errorf("expected Found = true; got %v", res.Found)
- }
- if res.Source != nil {
- t.Errorf("expected Source == nil; got %v", res.Source)
- }
-
- // Get document 1, exclude Message field
- fsc := NewFetchSourceContext(true).Exclude("message")
- res, err = client.Get().Index(testIndexName).Type("tweet").Id("1").FetchSourceContext(fsc).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != true {
- t.Errorf("expected Found = true; got %v", res.Found)
- }
- if res.Source == nil {
- t.Errorf("expected Source != nil; got %v", res.Source)
- }
- var tw tweet
- err = json.Unmarshal(*res.Source, &tw)
- if err != nil {
- t.Fatal(err)
- }
- if tw.User != "olivere" {
- t.Errorf("expected user %q; got: %q", "olivere", tw.User)
- }
- if tw.Message != "" {
- t.Errorf("expected message %q; got: %q", "", tw.Message)
- }
-}
-
-func TestGetWithFields(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").Timestamp("12345").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Get document 1, specifying fields
- res, err := client.Get().Index(testIndexName).Type("tweet").Id("1").Fields("message", "_timestamp").Do()
- if err != nil {
- t.Fatal(err)
- }
- if res.Found != true {
- t.Errorf("expected Found = true; got %v", res.Found)
- }
-
- timestamp, ok := res.Fields["_timestamp"].(float64)
- if !ok {
- t.Fatalf("Cannot retrieve \"_timestamp\" field from document")
- }
- if timestamp != 12345 {
- t.Fatalf("Expected timestamp %v; got %v", 12345, timestamp)
- }
-
- messageField, ok := res.Fields["message"]
- if !ok {
- t.Fatalf("Cannot retrieve \"message\" field from document")
- }
-
- // Depending on the version of elasticsearch the message field will be returned
- // as a string or a slice of strings. This test works in both cases.
-
- messageString, ok := messageField.(string)
- if !ok {
- messageArray, ok := messageField.([]interface{})
- if ok {
- messageString, ok = messageArray[0].(string)
- }
- if !ok {
- t.Fatalf("\"message\" field should be a string or a slice of strings")
- }
- }
-
- if messageString != tweet1.Message {
- t.Errorf("Expected message %s; got %s", tweet1.Message, messageString)
- }
-}
-
-func TestGetFailsWithMissingParams(t *testing.T) {
- // Mitigate against http://stackoverflow.com/questions/27491738/elasticsearch-go-index-failures-no-feature-for-name
- client := setupTestClientAndCreateIndex(t)
- if _, err := client.Get().Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- if _, err := client.Get().Index(testIndexName).Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- if _, err := client.Get().Type("tweet").Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- if _, err := client.Get().Id("1").Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- if _, err := client.Get().Index(testIndexName).Type("tweet").Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- /*
- if _, err := client.Get().Index(testIndexName).Id("1").Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
- */
- if _, err := client.Get().Type("tweet").Id("1").Do(); err == nil {
- t.Fatal("expected Get to fail")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/highlight_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/highlight_test.go
deleted file mode 100644
index 9538172dfd..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/highlight_test.go
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestHighlighterField(t *testing.T) {
- field := NewHighlighterField("grade")
- data, err := json.Marshal(field.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlighterFieldWithOptions(t *testing.T) {
- field := NewHighlighterField("grade").FragmentSize(2).NumOfFragments(1)
- data, err := json.Marshal(field.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fragment_size":2,"number_of_fragments":1}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlightWithStringField(t *testing.T) {
- builder := NewHighlight().Field("grade")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":{"grade":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlightWithFields(t *testing.T) {
- gradeField := NewHighlighterField("grade")
- builder := NewHighlight().Fields(gradeField)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":{"grade":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlightWithMultipleFields(t *testing.T) {
- gradeField := NewHighlighterField("grade")
- colorField := NewHighlighterField("color")
- builder := NewHighlight().Fields(gradeField, colorField)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":{"color":{},"grade":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlighterWithExplicitFieldOrder(t *testing.T) {
- gradeField := NewHighlighterField("grade").FragmentSize(2)
- colorField := NewHighlighterField("color").FragmentSize(2).NumOfFragments(1)
- builder := NewHighlight().Fields(gradeField, colorField).UseExplicitFieldOrder(true)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":[{"grade":{"fragment_size":2}},{"color":{"fragment_size":2,"number_of_fragments":1}}]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHighlightWithTermQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun to do."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Specify highlighter
- hl := NewHighlight()
- hl = hl.Fields(NewHighlighterField("message"))
- hl = hl.PreTags("").PostTags("")
-
- // Match all should return all documents
- query := NewPrefixQuery("message", "golang")
- searchResult, err := client.Search().
- Index(testIndexName).
- Highlight(hl).
- Query(&query).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Fatalf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 1 {
- t.Fatalf("expected SearchResult.Hits.TotalHits = %d; got %d", 1, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 1 {
- t.Fatalf("expected len(SearchResult.Hits.Hits) = %d; got %d", 1, len(searchResult.Hits.Hits))
- }
-
- hit := searchResult.Hits.Hits[0]
- var tw tweet
- if err := json.Unmarshal(*hit.Source, &tw); err != nil {
- t.Fatal(err)
- }
- if hit.Highlight == nil || len(hit.Highlight) == 0 {
- t.Fatal("expected hit to have a highlight; got nil")
- }
- if hl, found := hit.Highlight["message"]; found {
- if len(hl) != 1 {
- t.Fatalf("expected to have one highlight for field \"message\"; got %d", len(hl))
- }
- expected := "Welcome to Golang and Elasticsearch."
- if hl[0] != expected {
- t.Errorf("expected to have highlight \"%s\"; got \"%s\"", expected, hl[0])
- }
- } else {
- t.Fatal("expected to have a highlight on field \"message\"; got none")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/index_get_settings_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/index_get_settings_test.go
deleted file mode 100644
index f53512d53b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/index_get_settings_test.go
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestIndexGetSettingsURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Names []string
- Expected string
- }{
- {
- []string{},
- []string{},
- "/_all/_settings",
- },
- {
- []string{},
- []string{"index.merge.*"},
- "/_all/_settings/index.merge.%2A",
- },
- {
- []string{"twitter-*"},
- []string{"index.merge.*", "_settings"},
- "/twitter-%2A/_settings/index.merge.%2A%2C_settings",
- },
- {
- []string{"store-1", "store-2"},
- []string{"index.merge.*", "_settings"},
- "/store-1%2Cstore-2/_settings/index.merge.%2A%2C_settings",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.IndexGetSettings().Index(test.Indices...).Name(test.Names...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
-
-func TestIndexGetSettingsService(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if esversion < "1.4.0" {
- t.Skip("Index Get API is available since 1.4")
- return
- }
-
- res, err := client.IndexGetSettings().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected result; got: %v", res)
- }
- info, found := res[testIndexName]
- if !found {
- t.Fatalf("expected index %q to be found; got: %v", testIndexName, found)
- }
- if info == nil {
- t.Fatalf("expected index %q to be != nil; got: %v", testIndexName, info)
- }
- if info.Settings == nil {
- t.Fatalf("expected index settings of %q to be != nil; got: %v", testIndexName, info.Settings)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/index_get_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/index_get_test.go
deleted file mode 100644
index 3883925ded..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/index_get_test.go
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestIndexGetURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Features []string
- Expected string
- }{
- {
- []string{},
- []string{},
- "/_all",
- },
- {
- []string{},
- []string{"_mappings"},
- "/_all/_mappings",
- },
- {
- []string{"twitter"},
- []string{"_mappings", "_settings"},
- "/twitter/_mappings%2C_settings",
- },
- {
- []string{"store-1", "store-2"},
- []string{"_mappings", "_settings"},
- "/store-1%2Cstore-2/_mappings%2C_settings",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.IndexGet().Index(test.Indices...).Feature(test.Features...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
-
-func TestIndexGetService(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if esversion < "1.4.0" {
- t.Skip("Index Get API is available since 1.4")
- return
- }
-
- res, err := client.IndexGet().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected result; got: %v", res)
- }
- info, found := res[testIndexName]
- if !found {
- t.Fatalf("expected index %q to be found; got: %v", testIndexName, found)
- }
- if info == nil {
- t.Fatalf("expected index %q to be != nil; got: %v", testIndexName, info)
- }
- if info.Mappings == nil {
- t.Errorf("expected mappings to be != nil; got: %v", info.Mappings)
- }
- if info.Settings == nil {
- t.Errorf("expected settings to be != nil; got: %v", info.Settings)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/index_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/index_test.go
deleted file mode 100644
index 187eab1ac0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/index_test.go
+++ /dev/null
@@ -1,552 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "fmt"
- "log"
- "os"
- "testing"
- "time"
-)
-
-const (
- testIndexName = "elastic-test"
- testIndexName2 = "elastic-test2"
- testMapping = `
-{
- "settings":{
- "number_of_shards":1,
- "number_of_replicas":0
- },
- "mappings":{
- "_default_": {
- "_timestamp": {
- "enabled": true,
- "store": "yes"
- },
- "_ttl": {
- "enabled": true,
- "store": "yes"
- }
- },
- "tweet":{
- "properties":{
- "tags":{
- "type":"string"
- },
- "location":{
- "type":"geo_point"
- },
- "suggest_field":{
- "type":"completion",
- "payloads":true
- }
- }
- },
- "comment":{
- "_parent": {
- "type": "tweet"
- }
- }
- }
-}
-`
-)
-
-type tweet struct {
- User string `json:"user"`
- Message string `json:"message"`
- Retweets int `json:"retweets"`
- Image string `json:"image,omitempty"`
- Created time.Time `json:"created,omitempty"`
- Tags []string `json:"tags,omitempty"`
- Location string `json:"location,omitempty"`
- Suggest *SuggestField `json:"suggest_field,omitempty"`
-}
-
-func (t tweet) String() string {
- return fmt.Sprintf("tweet{User:%q,Message:%q,Retweets:%d}", t.User, t.Message, t.Retweets)
-}
-
-type comment struct {
- User string `json:"user"`
- Comment string `json:"comment"`
- Created time.Time `json:"created,omitempty"`
-}
-
-func (c comment) String() string {
- return fmt.Sprintf("comment{User:%q,Comment:%q}", c.User, c.Comment)
-}
-
-func isTravis() bool {
- return os.Getenv("TRAVIS") != ""
-}
-
-func travisGoVersion() string {
- return os.Getenv("TRAVIS_GO_VERSION")
-}
-
-type logger interface {
- Error(args ...interface{})
- Errorf(format string, args ...interface{})
- Fatal(args ...interface{})
- Fatalf(format string, args ...interface{})
- Fail()
- FailNow()
- Log(args ...interface{})
- Logf(format string, args ...interface{})
-}
-
-func setupTestClient(t logger, options ...ClientOptionFunc) (client *Client) {
- var err error
-
- client, err = NewClient(options...)
- if err != nil {
- t.Fatal(err)
- }
-
- client.DeleteIndex(testIndexName).Do()
- client.DeleteIndex(testIndexName2).Do()
-
- return client
-}
-
-func setupTestClientAndCreateIndex(t logger, options ...ClientOptionFunc) *Client {
- client := setupTestClient(t, options...)
-
- // Create index
- createIndex, err := client.CreateIndex(testIndexName).Body(testMapping).Do()
- if err != nil {
- t.Fatal(err)
- }
- if createIndex == nil {
- t.Errorf("expected result to be != nil; got: %v", createIndex)
- }
-
- // Create second index
- createIndex2, err := client.CreateIndex(testIndexName2).Body(testMapping).Do()
- if err != nil {
- t.Fatal(err)
- }
- if createIndex2 == nil {
- t.Errorf("expected result to be != nil; got: %v", createIndex2)
- }
-
- return client
-}
-
-func setupTestClientAndCreateIndexAndLog(t logger, options ...ClientOptionFunc) *Client {
- return setupTestClientAndCreateIndex(t, SetTraceLog(log.New(os.Stdout, "", 0)))
-}
-
-func setupTestClientAndCreateIndexAndAddDocs(t logger, options ...ClientOptionFunc) *Client {
- client := setupTestClientAndCreateIndex(t, options...)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
- comment1 := comment{User: "nico", Comment: "You bet."}
-
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").Routing("someroutingkey").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("1").Parent("3").BodyJson(&comment1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- return client
-}
-
-func TestIndexLifecycle(t *testing.T) {
- client := setupTestClient(t)
-
- // Create index
- createIndex, err := client.CreateIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !createIndex.Acknowledged {
- t.Errorf("expected CreateIndexResult.Acknowledged %v; got %v", true, createIndex.Acknowledged)
- }
-
- // Check if index exists
- indexExists, err := client.IndexExists(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !indexExists {
- t.Fatalf("index %s should exist, but doesn't\n", testIndexName)
- }
-
- // Delete index
- deleteIndex, err := client.DeleteIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !deleteIndex.Acknowledged {
- t.Errorf("expected DeleteIndexResult.Acknowledged %v; got %v", true, deleteIndex.Acknowledged)
- }
-
- // Check if index exists
- indexExists, err = client.IndexExists(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexExists {
- t.Fatalf("index %s should not exist, but does\n", testIndexName)
- }
-}
-
-func TestIndexExistScenarios(t *testing.T) {
- client := setupTestClient(t)
-
- // Should return false if index does not exist
- indexExists, err := client.IndexExists(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexExists {
- t.Fatalf("expected index exists to return %v, got %v", false, indexExists)
- }
-
- // Create index
- createIndex, err := client.CreateIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !createIndex.Acknowledged {
- t.Errorf("expected CreateIndexResult.Ack %v; got %v", true, createIndex.Acknowledged)
- }
-
- // Should return true if index does not exist
- indexExists, err = client.IndexExists(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !indexExists {
- t.Fatalf("expected index exists to return %v, got %v", true, indexExists)
- }
-}
-
-// TODO(oe): Find out why this test fails on Travis CI.
-/*
-func TestIndexOpenAndClose(t *testing.T) {
- client := setupTestClient(t)
-
- // Create index
- createIndex, err := client.CreateIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !createIndex.Acknowledged {
- t.Errorf("expected CreateIndexResult.Acknowledged %v; got %v", true, createIndex.Acknowledged)
- }
- defer func() {
- // Delete index
- deleteIndex, err := client.DeleteIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !deleteIndex.Acknowledged {
- t.Errorf("expected DeleteIndexResult.Acknowledged %v; got %v", true, deleteIndex.Acknowledged)
- }
- }()
-
- waitForYellow := func() {
- // Wait for status yellow
- res, err := client.ClusterHealth().WaitForStatus("yellow").Timeout("15s").Do()
- if err != nil {
- t.Fatal(err)
- }
- if res != nil && res.TimedOut {
- t.Fatalf("cluster time out waiting for status %q", "yellow")
- }
- }
-
- // Wait for cluster
- waitForYellow()
-
- // Close index
- cresp, err := client.CloseIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !cresp.Acknowledged {
- t.Fatalf("expected close index of %q to be acknowledged\n", testIndexName)
- }
-
- // Wait for cluster
- waitForYellow()
-
- // Open index again
- oresp, err := client.OpenIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !oresp.Acknowledged {
- t.Fatalf("expected open index of %q to be acknowledged\n", testIndexName)
- }
-}
-*/
-
-func TestDocumentLifecycle(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- indexResult, err := client.Index().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- BodyJson(&tweet1).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexResult == nil {
- t.Errorf("expected result to be != nil; got: %v", indexResult)
- }
-
- // Exists
- exists, err := client.Exists().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Errorf("expected exists %v; got %v", true, exists)
- }
-
- // Get document
- getResult, err := client.Get().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if getResult.Index != testIndexName {
- t.Errorf("expected GetResult.Index %q; got %q", testIndexName, getResult.Index)
- }
- if getResult.Type != "tweet" {
- t.Errorf("expected GetResult.Type %q; got %q", "tweet", getResult.Type)
- }
- if getResult.Id != "1" {
- t.Errorf("expected GetResult.Id %q; got %q", "1", getResult.Id)
- }
- if getResult.Source == nil {
- t.Errorf("expected GetResult.Source to be != nil; got nil")
- }
-
- // Decode the Source field
- var tweetGot tweet
- err = json.Unmarshal(*getResult.Source, &tweetGot)
- if err != nil {
- t.Fatal(err)
- }
- if tweetGot.User != tweet1.User {
- t.Errorf("expected Tweet.User to be %q; got %q", tweet1.User, tweetGot.User)
- }
- if tweetGot.Message != tweet1.Message {
- t.Errorf("expected Tweet.Message to be %q; got %q", tweet1.Message, tweetGot.Message)
- }
-
- // Delete document again
- deleteResult, err := client.Delete().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if deleteResult == nil {
- t.Errorf("expected result to be != nil; got: %v", deleteResult)
- }
-
- // Exists
- exists, err = client.Exists().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Errorf("expected exists %v; got %v", false, exists)
- }
-}
-
-func TestDocumentLifecycleWithAutomaticIDGeneration(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- indexResult, err := client.Index().
- Index(testIndexName).
- Type("tweet").
- BodyJson(&tweet1).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexResult == nil {
- t.Errorf("expected result to be != nil; got: %v", indexResult)
- }
- if indexResult.Id == "" {
- t.Fatalf("expected Es to generate an automatic ID, got: %v", indexResult.Id)
- }
- id := indexResult.Id
-
- // Exists
- exists, err := client.Exists().Index(testIndexName).Type("tweet").Id(id).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Errorf("expected exists %v; got %v", true, exists)
- }
-
- // Get document
- getResult, err := client.Get().
- Index(testIndexName).
- Type("tweet").
- Id(id).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if getResult.Index != testIndexName {
- t.Errorf("expected GetResult.Index %q; got %q", testIndexName, getResult.Index)
- }
- if getResult.Type != "tweet" {
- t.Errorf("expected GetResult.Type %q; got %q", "tweet", getResult.Type)
- }
- if getResult.Id != id {
- t.Errorf("expected GetResult.Id %q; got %q", id, getResult.Id)
- }
- if getResult.Source == nil {
- t.Errorf("expected GetResult.Source to be != nil; got nil")
- }
-
- // Decode the Source field
- var tweetGot tweet
- err = json.Unmarshal(*getResult.Source, &tweetGot)
- if err != nil {
- t.Fatal(err)
- }
- if tweetGot.User != tweet1.User {
- t.Errorf("expected Tweet.User to be %q; got %q", tweet1.User, tweetGot.User)
- }
- if tweetGot.Message != tweet1.Message {
- t.Errorf("expected Tweet.Message to be %q; got %q", tweet1.Message, tweetGot.Message)
- }
-
- // Delete document again
- deleteResult, err := client.Delete().Index(testIndexName).Type("tweet").Id(id).Do()
- if err != nil {
- t.Fatal(err)
- }
- if deleteResult == nil {
- t.Errorf("expected result to be != nil; got: %v", deleteResult)
- }
-
- // Exists
- exists, err = client.Exists().Index(testIndexName).Type("tweet").Id(id).Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Errorf("expected exists %v; got %v", false, exists)
- }
-}
-
-func TestIndexCreateExistsOpenCloseDelete(t *testing.T) {
- // TODO: Find out how to make these test robust
- t.Skip("test fails regularly with 409 (Conflict): " +
- "IndexPrimaryShardNotAllocatedException[[elastic-test] " +
- "primary not allocated post api... skipping")
-
- client := setupTestClient(t)
-
- // Create index
- createIndex, err := client.CreateIndex(testIndexName).Body(testMapping).Do()
- if err != nil {
- t.Fatal(err)
- }
- if createIndex == nil {
- t.Fatalf("expected response; got: %v", createIndex)
- }
- if !createIndex.Acknowledged {
- t.Errorf("expected ack for creating index; got: %v", createIndex.Acknowledged)
- }
-
- // Exists
- indexExists, err := client.IndexExists(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !indexExists {
- t.Fatalf("expected index exists=%v; got %v", true, indexExists)
- }
-
- // Flush
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Close index
- closeIndex, err := client.CloseIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if closeIndex == nil {
- t.Fatalf("expected response; got: %v", closeIndex)
- }
- if !closeIndex.Acknowledged {
- t.Errorf("expected ack for closing index; got: %v", closeIndex.Acknowledged)
- }
-
- // Open index
- openIndex, err := client.OpenIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if openIndex == nil {
- t.Fatalf("expected response; got: %v", openIndex)
- }
- if !openIndex.Acknowledged {
- t.Errorf("expected ack for opening index; got: %v", openIndex.Acknowledged)
- }
-
- // Flush
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Delete index
- deleteIndex, err := client.DeleteIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if deleteIndex == nil {
- t.Fatalf("expected response; got: %v", deleteIndex)
- }
- if !deleteIndex.Acknowledged {
- t.Errorf("expected ack for deleting index; got %v", deleteIndex.Acknowledged)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_template_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_template_test.go
deleted file mode 100644
index 32fb82ad3e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_template_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestIndexExistsTemplate(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tmpl := `{
- "template":"elastic-test*",
- "settings":{
- "number_of_shards":1,
- "number_of_replicas":0
- },
- "mappings":{
- "tweet":{
- "properties":{
- "tags":{
- "type":"string"
- },
- "location":{
- "type":"geo_point"
- },
- "suggest_field":{
- "type":"completion",
- "payloads":true
- }
- }
- }
- }
-}`
- putres, err := client.IndexPutTemplate("elastic-template").BodyString(tmpl).Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if putres == nil {
- t.Fatalf("expected response; got: %v", putres)
- }
- if !putres.Acknowledged {
- t.Fatalf("expected index template to be ack'd; got: %v", putres.Acknowledged)
- }
-
- // Always delete template
- defer client.IndexDeleteTemplate("elastic-template").Do()
-
- // Check if template exists
- exists, err := client.IndexTemplateExists("elastic-template").Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if !exists {
- t.Fatalf("expected index template %q to exist; got: %v", "elastic-template", exists)
- }
-
- // Get template
- getres, err := client.IndexGetTemplate("elastic-template").Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if getres == nil {
- t.Fatalf("expected to get index template %q; got: %v", "elastic-template", getres)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_type_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_type_test.go
deleted file mode 100644
index b37d42f94e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/indices_exists_type_test.go
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestTypeExistsBuildURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Types []string
- Expected string
- ExpectValidateFailure bool
- }{
- {
- []string{},
- []string{},
- "",
- true,
- },
- {
- []string{"index1"},
- []string{},
- "",
- true,
- },
- {
- []string{},
- []string{"type1"},
- "",
- true,
- },
- {
- []string{"index1"},
- []string{"type1"},
- "/index1/type1",
- false,
- },
- {
- []string{"index1", "index2"},
- []string{"type1"},
- "/index1%2Cindex2/type1",
- false,
- },
- {
- []string{"index1", "index2"},
- []string{"type1", "type2"},
- "/index1%2Cindex2/type1%2Ctype2",
- false,
- },
- }
-
- for i, test := range tests {
- err := client.TypeExists().Index(test.Indices...).Type(test.Types...).Validate()
- if err == nil && test.ExpectValidateFailure {
- t.Errorf("case #%d: expected validate to fail", i+1)
- continue
- }
- if err != nil && !test.ExpectValidateFailure {
- t.Errorf("case #%d: expected validate to succeed", i+1)
- continue
- }
- if !test.ExpectValidateFailure {
- path, _, err := client.TypeExists().Index(test.Indices...).Type(test.Types...).buildURL()
- if err != nil {
- t.Fatalf("case #%d: %v", i+1, err)
- }
- if path != test.Expected {
- t.Errorf("case #%d: expected %q; got: %q", i+1, test.Expected, path)
- }
- }
- }
-}
-
-func TestTypeExists(t *testing.T) {
- client := setupTestClient(t)
-
- // Create index with tweet type
- createIndex, err := client.CreateIndex(testIndexName).Body(testMapping).Do()
- if err != nil {
- t.Fatal(err)
- }
- if createIndex == nil {
- t.Errorf("expected result to be != nil; got: %v", createIndex)
- }
- if !createIndex.Acknowledged {
- t.Errorf("expected CreateIndexResult.Acknowledged %v; got %v", true, createIndex.Acknowledged)
- }
-
- // Check if type exists
- exists, err := client.TypeExists().Index(testIndexName).Type("tweet").Do()
- if err != nil {
- t.Fatal(err)
- }
- if !exists {
- t.Fatalf("type %s should exist in index %s, but doesn't\n", "tweet", testIndexName)
- }
-
- // Delete index
- deleteIndex, err := client.DeleteIndex(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if !deleteIndex.Acknowledged {
- t.Errorf("expected DeleteIndexResult.Acknowledged %v; got %v", true, deleteIndex.Acknowledged)
- }
-
- // Check if type exists
- exists, err = client.TypeExists().Index(testIndexName).Type("tweet").Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Fatalf("type %s should not exist in index %s, but it does\n", "tweet", testIndexName)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/indices_get_template_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/indices_get_template_test.go
deleted file mode 100644
index 693cde5ea5..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/indices_get_template_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestIndexGetTemplateURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Names []string
- Expected string
- }{
- {
- []string{},
- "/_template",
- },
- {
- []string{"index1"},
- "/_template/index1",
- },
- {
- []string{"index1", "index2"},
- "/_template/index1%2Cindex2",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.IndexGetTemplate().Name(test.Names...).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/indices_stats_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/indices_stats_test.go
deleted file mode 100644
index 2a72858d71..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/indices_stats_test.go
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestIndexStatsBuildURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Metrics []string
- Expected string
- }{
- {
- []string{},
- []string{},
- "/_stats",
- },
- {
- []string{"index1"},
- []string{},
- "/index1/_stats",
- },
- {
- []string{},
- []string{"metric1"},
- "/_stats/metric1",
- },
- {
- []string{"index1"},
- []string{"metric1"},
- "/index1/_stats/metric1",
- },
- {
- []string{"index1", "index2"},
- []string{"metric1"},
- "/index1%2Cindex2/_stats/metric1",
- },
- {
- []string{"index1", "index2"},
- []string{"metric1", "metric2"},
- "/index1%2Cindex2/_stats/metric1%2Cmetric2",
- },
- }
-
- for i, test := range tests {
- path, _, err := client.IndexStats().Index(test.Indices...).Metric(test.Metrics...).buildURL()
- if err != nil {
- t.Fatalf("case #%d: %v", i+1, err)
- }
- if path != test.Expected {
- t.Errorf("case #%d: expected %q; got: %q", i+1, test.Expected, path)
- }
- }
-}
-
-func TestIndexStats(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- stats, err := client.IndexStats(testIndexName).Do()
- if err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if stats == nil {
- t.Fatalf("expected response; got: %v", stats)
- }
- stat, found := stats.Indices[testIndexName]
- if !found {
- t.Fatalf("expected stats about index %q; got: %v", testIndexName, found)
- }
- if stat.Total == nil {
- t.Fatalf("expected total to be != nil; got: %v", stat.Total)
- }
- if stat.Total.Docs == nil {
- t.Fatalf("expected total docs to be != nil; got: %v", stat.Total.Docs)
- }
- if stat.Total.Docs.Count == 0 {
- t.Fatalf("expected total docs count to be > 0; got: %d", stat.Total.Docs.Count)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/inner_hit_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/inner_hit_test.go
deleted file mode 100644
index dfd77ec900..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/inner_hit_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestInnerHitEmpty(t *testing.T) {
- hit := NewInnerHit()
- data, err := json.Marshal(hit.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestInnerHitWithName(t *testing.T) {
- hit := NewInnerHit().Name("comments")
- data, err := json.Marshal(hit.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"name":"comments"}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/multi_get_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/multi_get_test.go
deleted file mode 100644
index 64b4722121..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/multi_get_test.go
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMultiGet(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add some documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Count documents
- count, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if count != 3 {
- t.Errorf("expected Count = %d; got %d", 3, count)
- }
-
- // Get documents 1 and 3
- res, err := client.MultiGet().
- Add(NewMultiGetItem().Index(testIndexName).Type("tweet").Id("1")).
- Add(NewMultiGetItem().Index(testIndexName).Type("tweet").Id("3")).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected result to be != nil; got nil")
- }
- if res.Docs == nil {
- t.Fatal("expected result docs to be != nil; got nil")
- }
- if len(res.Docs) != 2 {
- t.Fatalf("expected to have 2 docs; got %d", len(res.Docs))
- }
-
- item := res.Docs[0]
- if item.Error != "" {
- t.Errorf("expected no error on item 0; got %q", item.Error)
- }
- if item.Source == nil {
- t.Errorf("expected Source != nil; got %v", item.Source)
- }
- var doc tweet
- if err := json.Unmarshal(*item.Source, &doc); err != nil {
- t.Fatalf("expected to unmarshal item Source; got %v", err)
- }
- if doc.Message != tweet1.Message {
- t.Errorf("expected Message of first tweet to be %q; got %q", tweet1.Message, doc.Message)
- }
-
- item = res.Docs[1]
- if item.Error != "" {
- t.Errorf("expected no error on item 1; got %q", item.Error)
- }
- if item.Source == nil {
- t.Errorf("expected Source != nil; got %v", item.Source)
- }
- if err := json.Unmarshal(*item.Source, &doc); err != nil {
- t.Fatalf("expected to unmarshal item Source; got %v", err)
- }
- if doc.Message != tweet3.Message {
- t.Errorf("expected Message of second tweet to be %q; got %q", tweet3.Message, doc.Message)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/multi_search_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/multi_search_test.go
deleted file mode 100644
index 1741890c77..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/multi_search_test.go
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestMultiSearch(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere",
- Message: "Welcome to Golang and Elasticsearch.",
- Tags: []string{"golang", "elasticsearch"},
- }
- tweet2 := tweet{
- User: "olivere",
- Message: "Another unrelated topic.",
- Tags: []string{"golang"},
- }
- tweet3 := tweet{
- User: "sandrae",
- Message: "Cycling is fun.",
- Tags: []string{"sports", "cycling"},
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Spawn two search queries with one roundtrip
- q1 := NewMatchAllQuery()
- q2 := NewTermQuery("tags", "golang")
-
- sreq1 := NewSearchRequest().Indices(testIndexName, testIndexName2).
- Source(NewSearchSource().Query(q1).Size(10))
- sreq2 := NewSearchRequest().Index(testIndexName).Type("tweet").
- Source(NewSearchSource().Query(q2))
-
- searchResult, err := client.MultiSearch().
- Add(sreq1, sreq2).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Responses == nil {
- t.Fatal("expected responses != nil; got nil")
- }
- if len(searchResult.Responses) != 2 {
- t.Fatalf("expected 2 responses; got %d", len(searchResult.Responses))
- }
-
- sres := searchResult.Responses[0]
- if sres.Hits == nil {
- t.Errorf("expected Hits != nil; got nil")
- }
- if sres.Hits.TotalHits != 3 {
- t.Errorf("expected Hits.TotalHits = %d; got %d", 3, sres.Hits.TotalHits)
- }
- if len(sres.Hits.Hits) != 3 {
- t.Errorf("expected len(Hits.Hits) = %d; got %d", 3, len(sres.Hits.Hits))
- }
- for _, hit := range sres.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-
- sres = searchResult.Responses[1]
- if sres.Hits == nil {
- t.Errorf("expected Hits != nil; got nil")
- }
- if sres.Hits.TotalHits != 2 {
- t.Errorf("expected Hits.TotalHits = %d; got %d", 2, sres.Hits.TotalHits)
- }
- if len(sres.Hits.Hits) != 2 {
- t.Errorf("expected len(Hits.Hits) = %d; got %d", 2, len(sres.Hits.Hits))
- }
- for _, hit := range sres.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
-
-func TestMultiSearchWithOneRequest(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere",
- Message: "Welcome to Golang and Elasticsearch.",
- Tags: []string{"golang", "elasticsearch"},
- }
- tweet2 := tweet{
- User: "olivere",
- Message: "Another unrelated topic.",
- Tags: []string{"golang"},
- }
- tweet3 := tweet{
- User: "sandrae",
- Message: "Cycling is fun.",
- Tags: []string{"sports", "cycling"},
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Spawn two search queries with one roundtrip
- query := NewMatchAllQuery()
- source := NewSearchSource().Query(query).Size(10)
- sreq := NewSearchRequest().Source(source)
-
- searchResult, err := client.MultiSearch().
- Index(testIndexName).
- Add(sreq).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Responses == nil {
- t.Fatal("expected responses != nil; got nil")
- }
- if len(searchResult.Responses) != 1 {
- t.Fatalf("expected 1 responses; got %d", len(searchResult.Responses))
- }
-
- sres := searchResult.Responses[0]
- if sres.Hits == nil {
- t.Errorf("expected Hits != nil; got nil")
- }
- if sres.Hits.TotalHits != 3 {
- t.Errorf("expected Hits.TotalHits = %d; got %d", 3, sres.Hits.TotalHits)
- }
- if len(sres.Hits.Hits) != 3 {
- t.Errorf("expected len(Hits.Hits) = %d; got %d", 3, len(sres.Hits.Hits))
- }
- for _, hit := range sres.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/nodes_info_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/nodes_info_test.go
deleted file mode 100644
index 0402b2706f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/nodes_info_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import "testing"
-
-func TestNodesInfo(t *testing.T) {
- client, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
-
- info, err := client.NodesInfo().Do()
- if err != nil {
- t.Fatal(err)
- }
- if info == nil {
- t.Fatal("expected nodes info")
- }
-
- if info.ClusterName == "" {
- t.Errorf("expected cluster name; got: %q", info.ClusterName)
- }
- if len(info.Nodes) == 0 {
- t.Errorf("expected some nodes; got: %d", len(info.Nodes))
- }
- for id, node := range info.Nodes {
- if id == "" {
- t.Errorf("expected node id; got: %q", id)
- }
- if node == nil {
- t.Fatalf("expected node info; got: %v", node)
- }
- if node.IP == "" {
- t.Errorf("expected node IP; got: %q", node.IP)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/optimize_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/optimize_test.go
deleted file mode 100644
index c47de3a946..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/optimize_test.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestOptimize(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add some documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Optimize documents
- res, err := client.Optimize(testIndexName, testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected result; got nil")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/percolate_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/percolate_test.go
deleted file mode 100644
index cb4863d851..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/percolate_test.go
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import "testing"
-
-func TestPercolate(t *testing.T) {
- client := setupTestClientAndCreateIndex(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Register a query in the ".percolator" type.
- search := NewSearchSource().Query(NewMatchQuery("message", "Golang"))
- _, err = client.Index().
- Index(testIndexName).Type(".percolator").Id("1").
- BodyJson(search.Source()).
- Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Percolate should return our registered query
- newTweet := tweet{User: "olivere", Message: "Golang is fun."}
- res, err := client.Percolate().
- Index(testIndexName).Type("tweet").
- Doc(newTweet). // shortcut for: BodyJson(map[string]interface{}{"doc": newTweet}).
- Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Errorf("expected results != nil; got nil")
- }
- if res.Total != 1 {
- t.Fatalf("expected 1 result; got: %d", res.Total)
- }
- if res.Matches == nil {
- t.Fatalf("expected Matches; got: %v", res.Matches)
- }
- matches := res.Matches
- if matches == nil {
- t.Fatalf("expected matches as map; got: %v", matches)
- }
- if len(matches) != 1 {
- t.Fatalf("expected %d registered matches; got: %d", 1, len(matches))
- }
- if matches[0].Id != "1" {
- t.Errorf("expected to return query %q; got: %q", "1", matches[0].Id)
- }
-
- // Percolating an existsing document should return our registered query
- res, err = client.Percolate().
- Index(testIndexName).Type("tweet").
- Id("1").
- Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Errorf("expected results != nil; got nil")
- }
- if res.Total != 1 {
- t.Fatalf("expected 1 result; got: %d", res.Total)
- }
- if res.Matches == nil {
- t.Fatalf("expected Matches; got: %v", res.Matches)
- }
- matches = res.Matches
- if matches == nil {
- t.Fatalf("expected matches as map; got: %v", matches)
- }
- if len(matches) != 1 {
- t.Fatalf("expected %d registered matches; got: %d", 1, len(matches))
- }
- if matches[0].Id != "1" {
- t.Errorf("expected to return query %q; got: %q", "1", matches[0].Id)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/ping_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/ping_test.go
deleted file mode 100644
index ba76dcf840..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/ping_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "net/http"
- "testing"
-)
-
-func TestPingGet(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- res, code, err := client.Ping().Do()
- if err != nil {
- t.Fatal(err)
- }
- if code != http.StatusOK {
- t.Errorf("expected status code = %d; got %d", http.StatusOK, code)
- }
- if res == nil {
- t.Fatalf("expected to return result, got: %v", res)
- }
- if res.Status != http.StatusOK {
- t.Errorf("expected Status = %d; got %d", http.StatusOK, res.Status)
- }
- if res.Name == "" {
- t.Errorf("expected Name != \"\"; got %q", res.Name)
- }
- if res.Version.Number == "" {
- t.Errorf("expected Version.Number != \"\"; got %q", res.Version.Number)
- }
-}
-
-func TestPingHead(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- res, code, err := client.Ping().HttpHeadOnly(true).Do()
- if err != nil {
- t.Fatal(err)
- }
- if code != http.StatusOK {
- t.Errorf("expected status code = %d; got %d", http.StatusOK, code)
- }
- if res != nil {
- t.Errorf("expected not to return result, got: %v", res)
- }
-}
-
-func TestPingHeadFailure(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- res, code, err := client.Ping().
- URL("http://127.0.0.1:9299").
- HttpHeadOnly(true).
- Do()
- if err == nil {
- t.Error("expected error, got nil")
- }
- if code == http.StatusOK {
- t.Errorf("expected status code != %d; got %d", http.StatusOK, code)
- }
- if res != nil {
- t.Errorf("expected not to return result, got: %v", res)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/put_mapping_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/put_mapping_test.go
deleted file mode 100644
index d6245c2b87..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/put_mapping_test.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestPutMappingURL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tests := []struct {
- Indices []string
- Type string
- Expected string
- }{
- {
- []string{},
- "tweet",
- "/_mapping/tweet",
- },
- {
- []string{"*"},
- "tweet",
- "/%2A/_mapping/tweet",
- },
- {
- []string{"store-1", "store-2"},
- "tweet",
- "/store-1%2Cstore-2/_mapping/tweet",
- },
- }
-
- for _, test := range tests {
- path, _, err := client.PutMapping().Index(test.Indices...).Type(test.Type).buildURL()
- if err != nil {
- t.Fatal(err)
- }
- if path != test.Expected {
- t.Errorf("expected %q; got: %q", test.Expected, path)
- }
- }
-}
-
-func TestMappingLifecycle(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- mapping := `{
- "tweetdoc":{
- "properties":{
- "message":{
- "type":"string",
- "store":true
- }
- }
- }
- }`
-
- putresp, err := client.PutMapping().Index(testIndexName2).Type("tweetdoc").BodyString(mapping).Do()
- if err != nil {
- t.Fatalf("expected put mapping to succeed; got: %v", err)
- }
- if putresp == nil {
- t.Fatalf("expected put mapping response; got: %v", putresp)
- }
- if !putresp.Acknowledged {
- t.Fatalf("expected put mapping ack; got: %v", putresp.Acknowledged)
- }
-
- getresp, err := client.GetMapping().Index(testIndexName2).Type("tweetdoc").Do()
- if err != nil {
- t.Fatalf("expected get mapping to succeed; got: %v", err)
- }
- if getresp == nil {
- t.Fatalf("expected get mapping response; got: %v", getresp)
- }
- props, ok := getresp[testIndexName2]
- if !ok {
- t.Fatalf("expected JSON root to be of type map[string]interface{}; got: %#v", props)
- }
-
- delresp, err := client.DeleteMapping().Index(testIndexName2).Type("tweetdoc").Do()
- if err != nil {
- t.Fatalf("expected delete mapping to succeed; got: %v", err)
- }
- if delresp == nil {
- t.Fatalf("expected delete mapping response; got: %v", delresp)
- }
- if !delresp.Acknowledged {
- t.Fatalf("expected delete mapping ack; got: %v", delresp.Acknowledged)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/refresh_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/refresh_test.go
deleted file mode 100644
index 885e63365b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/refresh_test.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestRefresh(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add some documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Refresh indices
- res, err := client.Refresh(testIndexName, testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatal("expected result; got nil")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/reindexer_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/reindexer_test.go
deleted file mode 100644
index 82f839e63b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/reindexer_test.go
+++ /dev/null
@@ -1,292 +0,0 @@
-package elastic
-
-import (
- "encoding/json"
- "testing"
- "time"
-)
-
-func TestReindexer(t *testing.T) {
-
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- sourceCount, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if sourceCount <= 0 {
- t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount)
- }
-
- targetCount, err := client.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != 0 {
- t.Fatalf("expected %d documents; got: %d", 0, targetCount)
- }
-
- r := NewReindexer(client, testIndexName, CopyToTargetIndex(testIndexName2))
- ret, err := r.Do()
- if err != nil {
- t.Fatal(err)
- }
- if ret == nil {
- t.Fatalf("expected result != %v; got: %v", nil, ret)
- }
- if ret.Success != sourceCount {
- t.Errorf("expected success = %d; got: %d", sourceCount, ret.Success)
- }
- if ret.Failed != 0 {
- t.Errorf("expected failed = %d; got: %d", 0, ret.Failed)
- }
- if len(ret.Errors) != 0 {
- t.Errorf("expected to return no errors by default; got: %v", ret.Errors)
- }
-
- if _, err := client.Flush().Index(testIndexName2).Do(); err != nil {
- t.Fatal(err)
- }
-
- targetCount, err = client.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != sourceCount {
- t.Fatalf("expected %d documents; got: %d", sourceCount, targetCount)
- }
-}
-
-func TestReindexerWithQuery(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- q := NewTermQuery("user", "olivere")
-
- sourceCount, err := client.Count(testIndexName).Query(q).Do()
- if err != nil {
- t.Fatal(err)
- }
- if sourceCount <= 0 {
- t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount)
- }
-
- targetCount, err := client.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != 0 {
- t.Fatalf("expected %d documents; got: %d", 0, targetCount)
- }
-
- r := NewReindexer(client, testIndexName, CopyToTargetIndex(testIndexName2))
- r = r.Query(q)
- ret, err := r.Do()
- if err != nil {
- t.Fatal(err)
- }
- if ret == nil {
- t.Fatalf("expected result != %v; got: %v", nil, ret)
- }
- if ret.Success != sourceCount {
- t.Errorf("expected success = %d; got: %d", sourceCount, ret.Success)
- }
- if ret.Failed != 0 {
- t.Errorf("expected failed = %d; got: %d", 0, ret.Failed)
- }
- if len(ret.Errors) != 0 {
- t.Errorf("expected to return no errors by default; got: %v", ret.Errors)
- }
-
- if _, err := client.Flush().Index(testIndexName2).Do(); err != nil {
- t.Fatal(err)
- }
-
- targetCount, err = client.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != sourceCount {
- t.Fatalf("expected %d documents; got: %d", sourceCount, targetCount)
- }
-}
-
-func TestReindexerProgress(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- sourceCount, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if sourceCount <= 0 {
- t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount)
- }
-
- var calls int64
- totalsOk := true
- progress := func(current, total int64) {
- calls += 1
- totalsOk = totalsOk && total == sourceCount
- }
-
- r := NewReindexer(client, testIndexName, CopyToTargetIndex(testIndexName2))
- r = r.Progress(progress)
- ret, err := r.Do()
- if err != nil {
- t.Fatal(err)
- }
- if ret == nil {
- t.Fatalf("expected result != %v; got: %v", nil, ret)
- }
- if ret.Success != sourceCount {
- t.Errorf("expected success = %d; got: %d", sourceCount, ret.Success)
- }
- if ret.Failed != 0 {
- t.Errorf("expected failed = %d; got: %d", 0, ret.Failed)
- }
- if len(ret.Errors) != 0 {
- t.Errorf("expected to return no errors by default; got: %v", ret.Errors)
- }
-
- if calls != sourceCount {
- t.Errorf("expected progress to be called %d times; got: %d", sourceCount, calls)
- }
- if !totalsOk {
- t.Errorf("expected totals in progress to be %d", sourceCount)
- }
-}
-
-func TestReindexerWithTargetClient(t *testing.T) {
- sourceClient := setupTestClientAndCreateIndexAndAddDocs(t)
- targetClient, err := NewClient()
- if err != nil {
- t.Fatal(err)
- }
-
- sourceCount, err := sourceClient.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if sourceCount <= 0 {
- t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount)
- }
-
- // Timing issue with the target client
- time.Sleep(2 * time.Second)
-
- targetCount, err := targetClient.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != 0 {
- t.Fatalf("expected %d documents; got: %d", 0, targetCount)
- }
-
- r := NewReindexer(sourceClient, testIndexName, CopyToTargetIndex(testIndexName2))
- r = r.TargetClient(targetClient)
- ret, err := r.Do()
- if err != nil {
- t.Fatal(err)
- }
- if ret == nil {
- t.Fatalf("expected result != %v; got: %v", nil, ret)
- }
- if ret.Success != sourceCount {
- t.Errorf("expected success = %d; got: %d", sourceCount, ret.Success)
- }
- if ret.Failed != 0 {
- t.Errorf("expected failed = %d; got: %d", 0, ret.Failed)
- }
- if len(ret.Errors) != 0 {
- t.Errorf("expected to return no errors by default; got: %v", ret.Errors)
- }
-
- if _, err := targetClient.Flush().Index(testIndexName2).Do(); err != nil {
- t.Fatal(err)
- }
-
- targetCount, err = targetClient.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != sourceCount {
- t.Fatalf("expected %d documents; got: %d", sourceCount, targetCount)
- }
-}
-
-// TestReindexerPreservingTTL shows how a caller can take control of the
-// copying process by providing ScanFields and a custom ReindexerFunc.
-func TestReindexerPreservingTTL(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
-
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").TTL("999999").Version(10).VersionType("external").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- sourceCount, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
- if sourceCount <= 0 {
- t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount)
- }
-
- targetCount, err := client.Count(testIndexName2).Do()
- if err != nil {
- t.Fatal(err)
- }
- if targetCount != 0 {
- t.Fatalf("expected %d documents; got: %d", 0, targetCount)
- }
-
- // Carries over the source item's ttl to the reindexed item
- copyWithTTL := func(hit *SearchHit, bulkService *BulkService) error {
- source := make(map[string]interface{})
- if err := json.Unmarshal(*hit.Source, &source); err != nil {
- return err
- }
- req := NewBulkIndexRequest().Index(testIndexName2).Type(hit.Type).Id(hit.Id).Doc(source)
- if ttl, ok := hit.Fields["_ttl"].(float64); ok {
- req.Ttl(int64(ttl))
- }
- bulkService.Add(req)
- return nil
- }
-
- r := NewReindexer(client, testIndexName, copyWithTTL).ScanFields("_source", "_ttl")
-
- ret, err := r.Do()
- if err != nil {
- t.Fatal(err)
- }
- if ret == nil {
- t.Fatalf("expected result != %v; got: %v", nil, ret)
- }
- if ret.Success != sourceCount {
- t.Errorf("expected success = %d; got: %d", sourceCount, ret.Success)
- }
- if ret.Failed != 0 {
- t.Errorf("expected failed = %d; got: %d", 0, ret.Failed)
- }
- if len(ret.Errors) != 0 {
- t.Errorf("expected to return no errors by default; got: %v", ret.Errors)
- }
-
- getResult, err := client.Get().Index(testIndexName2).Id("1").Fields("_source", "_ttl").Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, ok := getResult.Fields["_ttl"].(float64)
- if !ok {
- t.Errorf("Cannot retrieve TTL from reindexed document")
- }
-
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/scan_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/scan_test.go
deleted file mode 100644
index 7b1bca7407..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/scan_test.go
+++ /dev/null
@@ -1,501 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestScan(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- cursor, err := client.Scan(testIndexName).Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- if cursor.Results == nil {
- t.Fatalf("expected results != nil; got nil")
- }
- if cursor.Results.Hits == nil {
- t.Fatalf("expected results.Hits != nil; got nil")
- }
- if cursor.Results.Hits.TotalHits != 3 {
- t.Fatalf("expected results.Hits.TotalHits = %d; got %d", 3, cursor.Results.Hits.TotalHits)
- }
- if len(cursor.Results.Hits.Hits) != 0 {
- t.Fatalf("expected len(results.Hits.Hits) = %d; got %d", 0, len(cursor.Results.Hits.Hits))
- }
-
- pages := 0
- numDocs := 0
-
- for {
- searchResult, err := cursor.Next()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- pages += 1
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Fatalf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- numDocs += 1
- }
- }
-
- if pages <= 0 {
- t.Errorf("expected to retrieve at least 1 page; got %d", pages)
- }
-
- if numDocs != 3 {
- t.Errorf("expected to retrieve %d hits; got %d", 3, numDocs)
- }
-}
-
-func TestScanWithSort(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch.", Retweets: 4}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic.", Retweets: 10}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun.", Retweets: 3}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // We sort on a numerical field, because sorting on the 'message' string field would
- // raise the whole question of tokenizing and analyzing.
- cursor, err := client.Scan(testIndexName).Sort("retweets", true).Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- if cursor.Results == nil {
- t.Fatalf("expected results != nil; got nil")
- }
- if cursor.Results.Hits == nil {
- t.Fatalf("expected results.Hits != nil; got nil")
- }
- if cursor.Results.Hits.TotalHits != 3 {
- t.Fatalf("expected results.Hits.TotalHits = %d; got %d", 3, cursor.Results.Hits.TotalHits)
- }
- if len(cursor.Results.Hits.Hits) != 1 {
- t.Fatalf("expected len(results.Hits.Hits) = %d; got %d", 1, len(cursor.Results.Hits.Hits))
- }
-
- if cursor.Results.Hits.Hits[0].Id != "3" {
- t.Fatalf("expected hitID = %v; got %v", "3", cursor.Results.Hits.Hits[0].Id)
-
- }
-
- numDocs := 1 // The cursor already gave us a result
- pages := 0
-
- for {
- searchResult, err := cursor.Next()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- pages += 1
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Fatalf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- numDocs += 1
- }
- }
-
- if pages <= 0 {
- t.Errorf("expected to retrieve at least 1 page; got %d", pages)
- }
-
- if numDocs != 3 {
- t.Errorf("expected to retrieve %d hits; got %d", 3, numDocs)
- }
-}
-
-func TestScanWithSearchSource(t *testing.T) {
- //client := setupTestClientAndCreateIndexAndLog(t)
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch.", Retweets: 4}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic.", Retweets: 10}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun.", Retweets: 3}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- src := NewSearchSource().
- Query(NewTermQuery("user", "olivere")).
- FetchSourceContext(NewFetchSourceContext(true).Include("retweets"))
- cursor, err := client.Scan(testIndexName).SearchSource(src).Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- if cursor.Results == nil {
- t.Fatalf("expected results != nil; got nil")
- }
- if cursor.Results.Hits == nil {
- t.Fatalf("expected results.Hits != nil; got nil")
- }
- if cursor.Results.Hits.TotalHits != 2 {
- t.Fatalf("expected results.Hits.TotalHits = %d; got %d", 2, cursor.Results.Hits.TotalHits)
- }
-
- numDocs := 0
- pages := 0
-
- for {
- searchResult, err := cursor.Next()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- pages += 1
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Fatalf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- if _, found := item["message"]; found {
- t.Fatalf("expected to not see field %q; got: %#v", "message", item)
- }
- numDocs += 1
- }
- }
-
- if pages != 3 {
- t.Errorf("expected to retrieve %d pages; got %d", 2, pages)
- }
-
- if numDocs != 2 {
- t.Errorf("expected to retrieve %d hits; got %d", 2, numDocs)
- }
-}
-
-func TestScanWithQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Return tweets from olivere only
- termQuery := NewTermQuery("user", "olivere")
- cursor, err := client.Scan(testIndexName).
- Size(1).
- Query(termQuery).
- Do()
- if err != nil {
- t.Fatal(err)
- }
-
- if cursor.Results == nil {
- t.Fatalf("expected results != nil; got nil")
- }
- if cursor.Results.Hits == nil {
- t.Fatalf("expected results.Hits != nil; got nil")
- }
- if cursor.Results.Hits.TotalHits != 2 {
- t.Fatalf("expected results.Hits.TotalHits = %d; got %d", 2, cursor.Results.Hits.TotalHits)
- }
- if len(cursor.Results.Hits.Hits) != 0 {
- t.Fatalf("expected len(results.Hits.Hits) = %d; got %d", 0, len(cursor.Results.Hits.Hits))
- }
-
- pages := 0
- numDocs := 0
-
- for {
- searchResult, err := cursor.Next()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- pages += 1
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Fatalf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- numDocs += 1
- }
- }
-
- if pages <= 0 {
- t.Errorf("expected to retrieve at least 1 page; got %d", pages)
- }
-
- if numDocs != 2 {
- t.Errorf("expected to retrieve %d hits; got %d", 2, numDocs)
- }
-}
-
-func TestScanAndScrollWithMissingIndex(t *testing.T) {
- client := setupTestClient(t) // does not create testIndexName
-
- cursor, err := client.Scan(testIndexName).Scroll("30s").Do()
- if err != nil {
- t.Fatal(err)
- }
- if cursor == nil {
- t.Fatalf("expected cursor; got: %v", cursor)
- }
-
- // First request immediately returns EOS
- res, err := cursor.Next()
- if err != EOS {
- t.Fatal(err)
- }
- if res != nil {
- t.Fatalf("expected results == %v; got: %v", nil, res)
- }
-}
-
-func TestScanAndScrollWithEmptyIndex(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- if isTravis() {
- t.Skip("test on Travis failes regularly with " +
- "Error 503 (Service Unavailable): SearchPhaseExecutionException[Failed to execute phase [init_scan], all shards failed]")
- }
-
- _, err := client.Flush().Index(testIndexName).WaitIfOngoing(true).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- cursor, err := client.Scan(testIndexName).Scroll("30s").Do()
- if err != nil {
- t.Fatal(err)
- }
- if cursor == nil {
- t.Fatalf("expected cursor; got: %v", cursor)
- }
-
- // First request returns no error, but no hits
- res, err := cursor.Next()
- if err != nil {
- t.Fatal(err)
- }
- if res == nil {
- t.Fatalf("expected results != nil; got: nil")
- }
- if res.ScrollId == "" {
- t.Fatalf("expected scrollId in results; got: %q", res.ScrollId)
- }
- if res.TotalHits() != 0 {
- t.Fatalf("expected TotalHits() = %d; got %d", 0, res.TotalHits())
- }
- if res.Hits == nil {
- t.Fatalf("expected results.Hits != nil; got: nil")
- }
- if res.Hits.TotalHits != 0 {
- t.Fatalf("expected results.Hits.TotalHits = %d; got %d", 0, res.Hits.TotalHits)
- }
- if res.Hits.Hits == nil {
- t.Fatalf("expected results.Hits.Hits != nil; got: %v", res.Hits.Hits)
- }
- if len(res.Hits.Hits) != 0 {
- t.Fatalf("expected len(results.Hits.Hits) == %d; got: %d", 0, len(res.Hits.Hits))
- }
-
- // Subsequent requests return EOS
- res, err = cursor.Next()
- if err != EOS {
- t.Fatal(err)
- }
- if res != nil {
- t.Fatalf("expected results == %v; got: %v", nil, res)
- }
-
- res, err = cursor.Next()
- if err != EOS {
- t.Fatal(err)
- }
- if res != nil {
- t.Fatalf("expected results == %v; got: %v", nil, res)
- }
-}
-
-func TestIssue119(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- comment1 := comment{User: "nico", Comment: "You bet."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
-
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("1").Parent("1").BodyJson(&comment1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- cursor, err := client.Scan(testIndexName).Fields("_source", "_parent").Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- for {
- searchResult, err := cursor.Next()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Type == "tweet" {
- if _, ok := hit.Fields["_parent"].(string); ok {
- t.Errorf("Type `tweet` cannot have any parent...")
-
- toPrint, _ := json.MarshalIndent(hit, "", " ")
- t.Fatal(string(toPrint))
- }
- }
-
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/scroll_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/scroll_test.go
deleted file mode 100644
index 4a5c481118..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/scroll_test.go
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestScroll(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- res, err := client.Scroll(testIndexName).Size(1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- if res == nil {
- t.Errorf("expected results != nil; got nil")
- }
- if res.Hits == nil {
- t.Errorf("expected results.Hits != nil; got nil")
- }
- if res.Hits.TotalHits != 3 {
- t.Errorf("expected results.Hits.TotalHits = %d; got %d", 3, res.Hits.TotalHits)
- }
- if len(res.Hits.Hits) != 0 {
- t.Errorf("expected len(results.Hits.Hits) = %d; got %d", 0, len(res.Hits.Hits))
- }
- if res.ScrollId == "" {
- t.Errorf("expected scrollId in results; got %q", res.ScrollId)
- }
-
- pages := 0
- numDocs := 0
- scrollId := res.ScrollId
-
- for {
- searchResult, err := client.Scroll(testIndexName).
- Size(1).
- ScrollId(scrollId).
- Do()
- if err == EOS {
- break
- }
- if err != nil {
- t.Fatal(err)
- }
-
- pages += 1
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- numDocs += 1
- }
-
- scrollId = searchResult.ScrollId
- if scrollId == "" {
- t.Errorf("expeced scrollId in results; got %q", scrollId)
- }
- }
-
- if pages <= 0 {
- t.Errorf("expected to retrieve at least 1 page; got %d", pages)
- }
-
- if numDocs != 3 {
- t.Errorf("expected to retrieve %d hits; got %d", 3, numDocs)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_avg_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_avg_test.go
deleted file mode 100644
index 8ddd8310b9..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_avg_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestAvgAggregation(t *testing.T) {
- agg := NewAvgAggregation().Field("grade")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"avg":{"field":"grade"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestAvgAggregationWithFormat(t *testing.T) {
- agg := NewAvgAggregation().Field("grade").Format("000.0")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"avg":{"field":"grade","format":"000.0"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_cardinality_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_cardinality_test.go
deleted file mode 100644
index f2ff3df302..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_cardinality_test.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestCardinalityAggregation(t *testing.T) {
- agg := NewCardinalityAggregation().Field("author.hash")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"cardinality":{"field":"author.hash"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestCardinalityAggregationWithOptions(t *testing.T) {
- agg := NewCardinalityAggregation().Field("author.hash").PrecisionThreshold(100).Rehash(true)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"cardinality":{"field":"author.hash","precision_threshold":100,"rehash":true}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestCardinalityAggregationWithFormat(t *testing.T) {
- agg := NewCardinalityAggregation().Field("author.hash").Format("00000")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"cardinality":{"field":"author.hash","format":"00000"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_children_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_children_test.go
deleted file mode 100644
index 092d09fb05..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_children_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestChildrenAggregation(t *testing.T) {
- agg := NewChildrenAggregation().Type("answer")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"type":"answer"}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestChildrenAggregationWithSubAggregation(t *testing.T) {
- subAgg := NewTermsAggregation().Field("owner.display_name").Size(10)
- agg := NewChildrenAggregation().Type("answer")
- agg = agg.SubAggregation("top-names", subAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"top-names":{"terms":{"field":"owner.display_name","size":10}}},"type":"answer"}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_histogram_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_histogram_test.go
deleted file mode 100644
index 0e461c6a7f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_histogram_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestDateHistogramAggregation(t *testing.T) {
- agg := NewDateHistogramAggregation().Field("date").Interval("month").Format("YYYY-MM")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_histogram":{"field":"date","format":"YYYY-MM","interval":"month"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_range_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_range_test.go
deleted file mode 100644
index 87221c18c7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_date_range_test.go
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestDateRangeAggregation(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at")
- agg = agg.AddRange(nil, "2012-12-31")
- agg = agg.AddRange("2013-01-01", "2013-12-31")
- agg = agg.AddRange("2014-01-01", nil)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","ranges":[{"to":"2012-12-31"},{"from":"2013-01-01","to":"2013-12-31"},{"from":"2014-01-01"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateRangeAggregationWithUnbounded(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at").
- AddUnboundedFrom("2012-12-31").
- AddRange("2013-01-01", "2013-12-31").
- AddUnboundedTo("2014-01-01")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","ranges":[{"to":"2012-12-31"},{"from":"2013-01-01","to":"2013-12-31"},{"from":"2014-01-01"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateRangeAggregationWithLtAndCo(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at").
- Lt("2012-12-31").
- Between("2013-01-01", "2013-12-31").
- Gt("2014-01-01")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","ranges":[{"to":"2012-12-31"},{"from":"2013-01-01","to":"2013-12-31"},{"from":"2014-01-01"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateRangeAggregationWithKeyedFlag(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at").
- Keyed(true).
- Lt("2012-12-31").
- Between("2013-01-01", "2013-12-31").
- Gt("2014-01-01")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","keyed":true,"ranges":[{"to":"2012-12-31"},{"from":"2013-01-01","to":"2013-12-31"},{"from":"2014-01-01"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateRangeAggregationWithKeys(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at").
- Keyed(true).
- LtWithKey("pre-2012", "2012-12-31").
- BetweenWithKey("2013", "2013-01-01", "2013-12-31").
- GtWithKey("post-2013", "2014-01-01")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","keyed":true,"ranges":[{"key":"pre-2012","to":"2012-12-31"},{"from":"2013-01-01","key":"2013","to":"2013-12-31"},{"from":"2014-01-01","key":"post-2013"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateRangeAggregationWithSpecialNames(t *testing.T) {
- agg := NewDateRangeAggregation().Field("created_at").
- AddRange("now-10M/M", "now+10M/M")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_range":{"field":"created_at","ranges":[{"from":"now-10M/M","to":"now+10M/M"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_extended_stats_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_extended_stats_test.go
deleted file mode 100644
index 8771c4624b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_extended_stats_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestExtendedStatsAggregation(t *testing.T) {
- agg := NewExtendedStatsAggregation().Field("grade")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"extended_stats":{"field":"grade"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestExtendedStatsAggregationWithFormat(t *testing.T) {
- agg := NewExtendedStatsAggregation().Field("grade").Format("000.0")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"extended_stats":{"field":"grade","format":"000.0"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filter_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filter_test.go
deleted file mode 100644
index b901378dc1..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filter_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFilterAggregation(t *testing.T) {
- filter := NewRangeFilter("stock").Gt(0)
- agg := NewFilterAggregation().Filter(filter)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"filter":{"range":{"stock":{"from":0,"include_lower":false,"include_upper":true,"to":null}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFilterAggregationWithSubAggregation(t *testing.T) {
- avgPriceAgg := NewAvgAggregation().Field("price")
- filter := NewRangeFilter("stock").Gt(0)
- agg := NewFilterAggregation().Filter(filter).
- SubAggregation("avg_price", avgPriceAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"avg_price":{"avg":{"field":"price"}}},"filter":{"range":{"stock":{"from":0,"include_lower":false,"include_upper":true,"to":null}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filters_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filters_test.go
deleted file mode 100644
index c1b244d982..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_filters_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFiltersAggregation(t *testing.T) {
- f1 := NewRangeFilter("stock").Gt(0)
- f2 := NewTermFilter("symbol", "GOOG")
- agg := NewFiltersAggregation().Filters(f1, f2)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"filters":{"filters":[{"range":{"stock":{"from":0,"include_lower":false,"include_upper":true,"to":null}}},{"term":{"symbol":"GOOG"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFiltersAggregationWithSubAggregation(t *testing.T) {
- avgPriceAgg := NewAvgAggregation().Field("price")
- f1 := NewRangeFilter("stock").Gt(0)
- f2 := NewTermFilter("symbol", "GOOG")
- agg := NewFiltersAggregation().Filters(f1, f2).SubAggregation("avg_price", avgPriceAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"avg_price":{"avg":{"field":"price"}}},"filters":{"filters":[{"range":{"stock":{"from":0,"include_lower":false,"include_upper":true,"to":null}}},{"term":{"symbol":"GOOG"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_bounds_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_bounds_test.go
deleted file mode 100644
index 904d7a2499..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_bounds_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoBoundsAggregation(t *testing.T) {
- agg := NewGeoBoundsAggregation().Field("location")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_bounds":{"field":"location"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoBoundsAggregationWithWrapLongitude(t *testing.T) {
- agg := NewGeoBoundsAggregation().Field("location").WrapLongitude(true)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_bounds":{"field":"location","wrap_longitude":true}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_distance_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_distance_test.go
deleted file mode 100644
index 85729e5bfe..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_geo_distance_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoDistanceAggregation(t *testing.T) {
- agg := NewGeoDistanceAggregation().Field("location").Point("52.3760, 4.894")
- agg = agg.AddRange(nil, 100)
- agg = agg.AddRange(100, 300)
- agg = agg.AddRange(300, nil)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"field":"location","origin":"52.3760, 4.894","ranges":[{"to":100},{"from":100,"to":300},{"from":300}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceAggregationWithUnbounded(t *testing.T) {
- agg := NewGeoDistanceAggregation().Field("location").Point("52.3760, 4.894")
- agg = agg.AddUnboundedFrom(100)
- agg = agg.AddRange(100, 300)
- agg = agg.AddUnboundedTo(300)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"field":"location","origin":"52.3760, 4.894","ranges":[{"to":100},{"from":100,"to":300},{"from":300}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_global_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_global_test.go
deleted file mode 100644
index 5b28bb3770..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_global_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGlobalAggregation(t *testing.T) {
- agg := NewGlobalAggregation()
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"global":{}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_histogram_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_histogram_test.go
deleted file mode 100644
index 19c5021619..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_histogram_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHistogramAggregation(t *testing.T) {
- agg := NewHistogramAggregation().Field("price").Interval(50)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"histogram":{"field":"price","interval":50}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_max_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_max_test.go
deleted file mode 100644
index 60d3779a2c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_max_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMaxAggregation(t *testing.T) {
- agg := NewMaxAggregation().Field("price")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"max":{"field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMaxAggregationWithFormat(t *testing.T) {
- agg := NewMaxAggregation().Field("price").Format("00000.00")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"max":{"field":"price","format":"00000.00"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_min_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_min_test.go
deleted file mode 100644
index a52cc02495..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_min_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMinAggregation(t *testing.T) {
- agg := NewMinAggregation().Field("price")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"min":{"field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMinAggregationWithFormat(t *testing.T) {
- agg := NewMinAggregation().Field("price").Format("00000.00")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"min":{"field":"price","format":"00000.00"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_missing_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_missing_test.go
deleted file mode 100644
index 4ed528a856..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_missing_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMissingAggregation(t *testing.T) {
- agg := NewMissingAggregation().Field("price")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"missing":{"field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_nested_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_nested_test.go
deleted file mode 100644
index 78c897f40e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_nested_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestNestedAggregation(t *testing.T) {
- agg := NewNestedAggregation().Path("resellers")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"nested":{"path":"resellers"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNestedAggregationWithSubAggregation(t *testing.T) {
- minPriceAgg := NewMinAggregation().Field("resellers.price")
- agg := NewNestedAggregation().Path("resellers").SubAggregation("min_price", minPriceAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"min_price":{"min":{"field":"resellers.price"}}},"nested":{"path":"resellers"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentile_ranks_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentile_ranks_test.go
deleted file mode 100644
index 61f4a5de8a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentile_ranks_test.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestPercentileRanksAggregation(t *testing.T) {
- agg := NewPercentileRanksAggregation().Field("load_time")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentile_ranks":{"field":"load_time"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPercentileRanksAggregationWithCustomValues(t *testing.T) {
- agg := NewPercentileRanksAggregation().Field("load_time").Values(15, 30)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentile_ranks":{"field":"load_time","values":[15,30]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPercentileRanksAggregationWithFormat(t *testing.T) {
- agg := NewPercentileRanksAggregation().Field("load_time").Format("000.0")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentile_ranks":{"field":"load_time","format":"000.0"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentiles_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentiles_test.go
deleted file mode 100644
index c8e7522ae4..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_percentiles_test.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestPercentilesAggregation(t *testing.T) {
- agg := NewPercentilesAggregation().Field("price")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentiles":{"field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPercentilesAggregationWithCustomPercents(t *testing.T) {
- agg := NewPercentilesAggregation().Field("price").Percentiles(0.2, 0.5, 0.9)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentiles":{"field":"price","percents":[0.2,0.5,0.9]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPercentilesAggregationWithFormat(t *testing.T) {
- agg := NewPercentilesAggregation().Field("price").Format("00000.00")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"percentiles":{"field":"price","format":"00000.00"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_range_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_range_test.go
deleted file mode 100644
index 771310c34c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_range_test.go
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRangeAggregation(t *testing.T) {
- agg := NewRangeAggregation().Field("price")
- agg = agg.AddRange(nil, 50)
- agg = agg.AddRange(50, 100)
- agg = agg.AddRange(100, nil)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"price","ranges":[{"to":50},{"from":50,"to":100},{"from":100}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeAggregationWithUnbounded(t *testing.T) {
- agg := NewRangeAggregation().Field("field_name").
- AddUnboundedFrom(50).
- AddRange(20, 70).
- AddRange(70, 120).
- AddUnboundedTo(150)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeAggregationWithLtAndCo(t *testing.T) {
- agg := NewRangeAggregation().Field("field_name").
- Lt(50).
- Between(20, 70).
- Between(70, 120).
- Gt(150)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeAggregationWithKeyedFlag(t *testing.T) {
- agg := NewRangeAggregation().Field("field_name").
- Keyed(true).
- Lt(50).
- Between(20, 70).
- Between(70, 120).
- Gt(150)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","keyed":true,"ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeAggregationWithKeys(t *testing.T) {
- agg := NewRangeAggregation().Field("field_name").
- Keyed(true).
- LtWithKey("cheap", 50).
- BetweenWithKey("affordable", 20, 70).
- BetweenWithKey("average", 70, 120).
- GtWithKey("expensive", 150)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","keyed":true,"ranges":[{"key":"cheap","to":50},{"from":20,"key":"affordable","to":70},{"from":70,"key":"average","to":120},{"from":150,"key":"expensive"}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_significant_terms_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_significant_terms_test.go
deleted file mode 100644
index c53740c7ea..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_significant_terms_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSignificantTermsAggregation(t *testing.T) {
- agg := NewSignificantTermsAggregation().Field("crime_type")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"significant_terms":{"field":"crime_type"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSignificantTermsAggregationWithArgs(t *testing.T) {
- agg := NewSignificantTermsAggregation().
- Field("crime_type").
- ExecutionHint("map").
- ShardSize(5).
- MinDocCount(10).
- BackgroundFilter(NewTermFilter("city", "London"))
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"significant_terms":{"background_filter":{"term":{"city":"London"}},"execution_hint":"map","field":"crime_type","min_doc_count":10,"shard_size":5}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSignificantTermsAggregationSubAggregation(t *testing.T) {
- crimeTypesAgg := NewSignificantTermsAggregation().Field("crime_type")
- agg := NewTermsAggregation().Field("force")
- agg = agg.SubAggregation("significantCrimeTypes", crimeTypesAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"significantCrimeTypes":{"significant_terms":{"field":"crime_type"}}},"terms":{"field":"force"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_stats_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_stats_test.go
deleted file mode 100644
index 616bfde01f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_stats_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestStatsAggregation(t *testing.T) {
- agg := NewStatsAggregation().Field("grade")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"stats":{"field":"grade"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestStatsAggregationWithFormat(t *testing.T) {
- agg := NewStatsAggregation().Field("grade").Format("0000.0")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"stats":{"field":"grade","format":"0000.0"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_sum_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_sum_test.go
deleted file mode 100644
index de87e79373..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_sum_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSumAggregation(t *testing.T) {
- agg := NewSumAggregation().Field("price")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"sum":{"field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSumAggregationWithFormat(t *testing.T) {
- agg := NewSumAggregation().Field("price").Format("00000.00")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"sum":{"field":"price","format":"00000.00"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_terms_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_terms_test.go
deleted file mode 100644
index e3bb7672aa..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_terms_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermsAggregation(t *testing.T) {
- agg := NewTermsAggregation().Field("gender").Size(10).OrderByTermDesc()
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms":{"field":"gender","order":{"_term":"desc"},"size":10}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermsAggregationWithSubAggregation(t *testing.T) {
- subAgg := NewAvgAggregation().Field("height")
- agg := NewTermsAggregation().Field("gender").Size(10).
- OrderByAggregation("avg_height", false)
- agg = agg.SubAggregation("avg_height", subAgg)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"avg_height":{"avg":{"field":"height"}}},"terms":{"field":"gender","order":{"avg_height":"desc"},"size":10}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermsAggregationWithMultipleSubAggregation(t *testing.T) {
- subAgg1 := NewAvgAggregation().Field("height")
- subAgg2 := NewAvgAggregation().Field("width")
- agg := NewTermsAggregation().Field("gender").Size(10).
- OrderByAggregation("avg_height", false)
- agg = agg.SubAggregation("avg_height", subAgg1)
- agg = agg.SubAggregation("avg_width", subAgg2)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"aggregations":{"avg_height":{"avg":{"field":"height"}},"avg_width":{"avg":{"field":"width"}}},"terms":{"field":"gender","order":{"avg_height":"desc"},"size":10}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_test.go
deleted file mode 100644
index a504e741b8..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_test.go
+++ /dev/null
@@ -1,2627 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "strings"
- "testing"
- "time"
-)
-
-func TestAggs(t *testing.T) {
- //client := setupTestClientAndCreateIndex(t, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))
- client := setupTestClientAndCreateIndex(t)
-
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
-
- tweet1 := tweet{
- User: "olivere",
- Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Image: "http://golang.org/doc/gopher/gophercolor.png",
- Tags: []string{"golang", "elasticsearch"},
- Location: "48.1333,11.5667", // lat,lon
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere",
- Retweets: 0,
- Message: "Another unrelated topic.",
- Tags: []string{"golang"},
- Location: "48.1189,11.4289", // lat,lon
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae",
- Retweets: 12,
- Message: "Cycling is fun.",
- Tags: []string{"sports", "cycling"},
- Location: "47.7167,11.7167", // lat,lon
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
-
- // Terms Aggregate by user name
- globalAgg := NewGlobalAggregation()
- usersAgg := NewTermsAggregation().Field("user").Size(10).OrderByCountDesc()
- retweetsAgg := NewTermsAggregation().Field("retweets").Size(10)
- avgRetweetsAgg := NewAvgAggregation().Field("retweets")
- minRetweetsAgg := NewMinAggregation().Field("retweets")
- maxRetweetsAgg := NewMaxAggregation().Field("retweets")
- sumRetweetsAgg := NewSumAggregation().Field("retweets")
- statsRetweetsAgg := NewStatsAggregation().Field("retweets")
- extstatsRetweetsAgg := NewExtendedStatsAggregation().Field("retweets")
- valueCountRetweetsAgg := NewValueCountAggregation().Field("retweets")
- percentilesRetweetsAgg := NewPercentilesAggregation().Field("retweets")
- percentileRanksRetweetsAgg := NewPercentileRanksAggregation().Field("retweets").Values(25, 50, 75)
- cardinalityAgg := NewCardinalityAggregation().Field("user")
- significantTermsAgg := NewSignificantTermsAggregation().Field("message")
- retweetsRangeAgg := NewRangeAggregation().Field("retweets").Lt(10).Between(10, 100).Gt(100)
- retweetsKeyedRangeAgg := NewRangeAggregation().Field("retweets").Keyed(true).Lt(10).Between(10, 100).Gt(100)
- dateRangeAgg := NewDateRangeAggregation().Field("created").Lt("2012-01-01").Between("2012-01-01", "2013-01-01").Gt("2013-01-01")
- missingTagsAgg := NewMissingAggregation().Field("tags")
- retweetsHistoAgg := NewHistogramAggregation().Field("retweets").Interval(100)
- dateHistoAgg := NewDateHistogramAggregation().Field("created").Interval("year")
- retweetsFilterAgg := NewFilterAggregation().Filter(
- NewRangeFilter("created").Gte("2012-01-01").Lte("2012-12-31")).
- SubAggregation("avgRetweetsSub", NewAvgAggregation().Field("retweets"))
- queryFilterAgg := NewFilterAggregation().Filter(NewQueryFilter(NewTermQuery("tags", "golang")))
- topTagsHitsAgg := NewTopHitsAggregation().Sort("created", false).Size(5).FetchSource(true)
- topTagsAgg := NewTermsAggregation().Field("tags").Size(3).SubAggregation("top_tag_hits", topTagsHitsAgg)
- geoBoundsAgg := NewGeoBoundsAggregation().Field("location")
-
- // Run query
- builder := client.Search().Index(testIndexName).Query(&all)
- builder = builder.Aggregation("global", globalAgg)
- builder = builder.Aggregation("users", usersAgg)
- builder = builder.Aggregation("retweets", retweetsAgg)
- builder = builder.Aggregation("avgRetweets", avgRetweetsAgg)
- builder = builder.Aggregation("minRetweets", minRetweetsAgg)
- builder = builder.Aggregation("maxRetweets", maxRetweetsAgg)
- builder = builder.Aggregation("sumRetweets", sumRetweetsAgg)
- builder = builder.Aggregation("statsRetweets", statsRetweetsAgg)
- builder = builder.Aggregation("extstatsRetweets", extstatsRetweetsAgg)
- builder = builder.Aggregation("valueCountRetweets", valueCountRetweetsAgg)
- builder = builder.Aggregation("percentilesRetweets", percentilesRetweetsAgg)
- builder = builder.Aggregation("percentileRanksRetweets", percentileRanksRetweetsAgg)
- builder = builder.Aggregation("usersCardinality", cardinalityAgg)
- builder = builder.Aggregation("significantTerms", significantTermsAgg)
- builder = builder.Aggregation("retweetsRange", retweetsRangeAgg)
- builder = builder.Aggregation("retweetsKeyedRange", retweetsKeyedRangeAgg)
- builder = builder.Aggregation("dateRange", dateRangeAgg)
- builder = builder.Aggregation("missingTags", missingTagsAgg)
- builder = builder.Aggregation("retweetsHisto", retweetsHistoAgg)
- builder = builder.Aggregation("dateHisto", dateHistoAgg)
- builder = builder.Aggregation("retweetsFilter", retweetsFilterAgg)
- builder = builder.Aggregation("queryFilter", queryFilterAgg)
- builder = builder.Aggregation("top-tags", topTagsAgg)
- builder = builder.Aggregation("viewport", geoBoundsAgg)
- if esversion >= "1.4" {
- countByUserAgg := NewFiltersAggregation().Filters(NewTermFilter("user", "olivere"), NewTermFilter("user", "sandrae"))
- builder = builder.Aggregation("countByUser", countByUserAgg)
- }
- searchResult, err := builder.Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected Hits != nil; got: nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected Hits.TotalHits = %d; got: %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(Hits.Hits) = %d; got: %d", 3, len(searchResult.Hits.Hits))
- }
- agg := searchResult.Aggregations
- if agg == nil {
- t.Fatalf("expected Aggregations != nil; got: nil")
- }
-
- // Search for non-existent aggregate should return (nil, false)
- unknownAgg, found := agg.Terms("no-such-aggregate")
- if found {
- t.Errorf("expected unknown aggregation to not be found; got: %v", found)
- }
- if unknownAgg != nil {
- t.Errorf("expected unknown aggregation to return %v; got %v", nil, unknownAgg)
- }
-
- // Global
- globalAggRes, found := agg.Global("global")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if globalAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if globalAggRes.DocCount != 3 {
- t.Errorf("expected DocCount = %d; got: %d", 3, globalAggRes.DocCount)
- }
-
- // Search for existent aggregate (by name) should return (aggregate, true)
- termsAggRes, found := agg.Terms("users")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if termsAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(termsAggRes.Buckets) != 2 {
- t.Fatalf("expected %d; got: %d", 2, len(termsAggRes.Buckets))
- }
- if termsAggRes.Buckets[0].Key != "olivere" {
- t.Errorf("expected %q; got: %q", "olivere", termsAggRes.Buckets[0].Key)
- }
- if termsAggRes.Buckets[0].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, termsAggRes.Buckets[0].DocCount)
- }
- if termsAggRes.Buckets[1].Key != "sandrae" {
- t.Errorf("expected %q; got: %q", "sandrae", termsAggRes.Buckets[1].Key)
- }
- if termsAggRes.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, termsAggRes.Buckets[1].DocCount)
- }
-
- // A terms aggregate with keys that are not strings
- retweetsAggRes, found := agg.Terms("retweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if retweetsAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(retweetsAggRes.Buckets) != 3 {
- t.Fatalf("expected %d; got: %d", 3, len(retweetsAggRes.Buckets))
- }
-
- if retweetsAggRes.Buckets[0].Key != float64(0) {
- t.Errorf("expected %v; got: %v", float64(0), retweetsAggRes.Buckets[0].Key)
- }
- if got, err := retweetsAggRes.Buckets[0].KeyNumber.Int64(); err != nil {
- t.Errorf("expected %d; got: %v", 0, retweetsAggRes.Buckets[0].Key)
- } else if got != 0 {
- t.Errorf("expected %d; got: %d", 0, got)
- }
- if retweetsAggRes.Buckets[0].KeyNumber != "0" {
- t.Errorf("expected %q; got: %q", "0", retweetsAggRes.Buckets[0].KeyNumber)
- }
- if retweetsAggRes.Buckets[0].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, retweetsAggRes.Buckets[0].DocCount)
- }
-
- if retweetsAggRes.Buckets[1].Key != float64(12) {
- t.Errorf("expected %v; got: %v", float64(12), retweetsAggRes.Buckets[1].Key)
- }
- if got, err := retweetsAggRes.Buckets[1].KeyNumber.Int64(); err != nil {
- t.Errorf("expected %d; got: %v", 0, retweetsAggRes.Buckets[1].KeyNumber)
- } else if got != 12 {
- t.Errorf("expected %d; got: %d", 12, got)
- }
- if retweetsAggRes.Buckets[1].KeyNumber != "12" {
- t.Errorf("expected %q; got: %q", "12", retweetsAggRes.Buckets[1].KeyNumber)
- }
- if retweetsAggRes.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, retweetsAggRes.Buckets[1].DocCount)
- }
-
- if retweetsAggRes.Buckets[2].Key != float64(108) {
- t.Errorf("expected %v; got: %v", float64(108), retweetsAggRes.Buckets[2].Key)
- }
- if got, err := retweetsAggRes.Buckets[2].KeyNumber.Int64(); err != nil {
- t.Errorf("expected %d; got: %v", 108, retweetsAggRes.Buckets[2].KeyNumber)
- } else if got != 108 {
- t.Errorf("expected %d; got: %d", 108, got)
- }
- if retweetsAggRes.Buckets[2].KeyNumber != "108" {
- t.Errorf("expected %q; got: %q", "108", retweetsAggRes.Buckets[2].KeyNumber)
- }
- if retweetsAggRes.Buckets[2].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, retweetsAggRes.Buckets[2].DocCount)
- }
-
- // avgRetweets
- avgAggRes, found := agg.Avg("avgRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if avgAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if avgAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *avgAggRes.Value)
- }
- if *avgAggRes.Value != 40.0 {
- t.Errorf("expected %v; got: %v", 40.0, *avgAggRes.Value)
- }
-
- // minRetweets
- minAggRes, found := agg.Min("minRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if minAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if minAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *minAggRes.Value)
- }
- if *minAggRes.Value != 0.0 {
- t.Errorf("expected %v; got: %v", 0.0, *minAggRes.Value)
- }
-
- // maxRetweets
- maxAggRes, found := agg.Max("maxRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if maxAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if maxAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *maxAggRes.Value)
- }
- if *maxAggRes.Value != 108.0 {
- t.Errorf("expected %v; got: %v", 108.0, *maxAggRes.Value)
- }
-
- // sumRetweets
- sumAggRes, found := agg.Sum("sumRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if sumAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if sumAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *sumAggRes.Value)
- }
- if *sumAggRes.Value != 120.0 {
- t.Errorf("expected %v; got: %v", 120.0, *sumAggRes.Value)
- }
-
- // statsRetweets
- statsAggRes, found := agg.Stats("statsRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if statsAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if statsAggRes.Count != 3 {
- t.Errorf("expected %d; got: %d", 3, statsAggRes.Count)
- }
- if statsAggRes.Min == nil {
- t.Fatalf("expected != nil; got: %v", *statsAggRes.Min)
- }
- if *statsAggRes.Min != 0.0 {
- t.Errorf("expected %v; got: %v", 0.0, *statsAggRes.Min)
- }
- if statsAggRes.Max == nil {
- t.Fatalf("expected != nil; got: %v", *statsAggRes.Max)
- }
- if *statsAggRes.Max != 108.0 {
- t.Errorf("expected %v; got: %v", 108.0, *statsAggRes.Max)
- }
- if statsAggRes.Avg == nil {
- t.Fatalf("expected != nil; got: %v", *statsAggRes.Avg)
- }
- if *statsAggRes.Avg != 40.0 {
- t.Errorf("expected %v; got: %v", 40.0, *statsAggRes.Avg)
- }
- if statsAggRes.Sum == nil {
- t.Fatalf("expected != nil; got: %v", *statsAggRes.Sum)
- }
- if *statsAggRes.Sum != 120.0 {
- t.Errorf("expected %v; got: %v", 120.0, *statsAggRes.Sum)
- }
-
- // extstatsRetweets
- extStatsAggRes, found := agg.ExtendedStats("extstatsRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if extStatsAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if extStatsAggRes.Count != 3 {
- t.Errorf("expected %d; got: %d", 3, extStatsAggRes.Count)
- }
- if extStatsAggRes.Min == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.Min)
- }
- if *extStatsAggRes.Min != 0.0 {
- t.Errorf("expected %v; got: %v", 0.0, *extStatsAggRes.Min)
- }
- if extStatsAggRes.Max == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.Max)
- }
- if *extStatsAggRes.Max != 108.0 {
- t.Errorf("expected %v; got: %v", 108.0, *extStatsAggRes.Max)
- }
- if extStatsAggRes.Avg == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.Avg)
- }
- if *extStatsAggRes.Avg != 40.0 {
- t.Errorf("expected %v; got: %v", 40.0, *extStatsAggRes.Avg)
- }
- if extStatsAggRes.Sum == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.Sum)
- }
- if *extStatsAggRes.Sum != 120.0 {
- t.Errorf("expected %v; got: %v", 120.0, *extStatsAggRes.Sum)
- }
- if extStatsAggRes.SumOfSquares == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.SumOfSquares)
- }
- if *extStatsAggRes.SumOfSquares != 11808.0 {
- t.Errorf("expected %v; got: %v", 11808.0, *extStatsAggRes.SumOfSquares)
- }
- if extStatsAggRes.Variance == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.Variance)
- }
- if *extStatsAggRes.Variance != 2336.0 {
- t.Errorf("expected %v; got: %v", 2336.0, *extStatsAggRes.Variance)
- }
- if extStatsAggRes.StdDeviation == nil {
- t.Fatalf("expected != nil; got: %v", *extStatsAggRes.StdDeviation)
- }
- if *extStatsAggRes.StdDeviation != 48.33218389437829 {
- t.Errorf("expected %v; got: %v", 48.33218389437829, *extStatsAggRes.StdDeviation)
- }
-
- // valueCountRetweets
- valueCountAggRes, found := agg.ValueCount("valueCountRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if valueCountAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if valueCountAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *valueCountAggRes.Value)
- }
- if *valueCountAggRes.Value != 3.0 {
- t.Errorf("expected %v; got: %v", 3.0, *valueCountAggRes.Value)
- }
-
- // percentilesRetweets
- percentilesAggRes, found := agg.Percentiles("percentilesRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if percentilesAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- // ES 1.4.x returns 7: {"1.0":...}
- // ES 1.5.0 returns 14: {"1.0":..., "1.0_as_string":...}
- // So we're relaxing the test here.
- if len(percentilesAggRes.Values) == 0 {
- t.Errorf("expected at least %d value; got: %d\nValues are: %#v", 1, len(percentilesAggRes.Values), percentilesAggRes.Values)
- }
- if _, found := percentilesAggRes.Values["0.0"]; found {
- t.Errorf("expected %v; got: %v", false, found)
- }
- if percentilesAggRes.Values["1.0"] != 0.24 {
- t.Errorf("expected %v; got: %v", 0.24, percentilesAggRes.Values["1.0"])
- }
- if percentilesAggRes.Values["25.0"] != 6.0 {
- t.Errorf("expected %v; got: %v", 6.0, percentilesAggRes.Values["25.0"])
- }
- if percentilesAggRes.Values["99.0"] != 106.08 {
- t.Errorf("expected %v; got: %v", 106.08, percentilesAggRes.Values["99.0"])
- }
-
- // percentileRanksRetweets
- percentileRanksAggRes, found := agg.PercentileRanks("percentileRanksRetweets")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if percentileRanksAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(percentileRanksAggRes.Values) == 0 {
- t.Errorf("expected at least %d value; got %d\nValues are: %#v", 1, len(percentileRanksAggRes.Values), percentileRanksAggRes.Values)
- }
- if _, found := percentileRanksAggRes.Values["0.0"]; found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if percentileRanksAggRes.Values["25.0"] != 21.180555555555557 {
- t.Errorf("expected %v; got: %v", 21.180555555555557, percentileRanksAggRes.Values["25.0"])
- }
- if percentileRanksAggRes.Values["50.0"] != 29.86111111111111 {
- t.Errorf("expected %v; got: %v", 29.86111111111111, percentileRanksAggRes.Values["50.0"])
- }
- if percentileRanksAggRes.Values["75.0"] != 38.54166666666667 {
- t.Errorf("expected %v; got: %v", 38.54166666666667, percentileRanksAggRes.Values["75.0"])
- }
-
- // usersCardinality
- cardAggRes, found := agg.Cardinality("usersCardinality")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if cardAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if cardAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", *cardAggRes.Value)
- }
- if *cardAggRes.Value != 2 {
- t.Errorf("expected %v; got: %v", 2, *cardAggRes.Value)
- }
-
- // retweetsFilter
- filterAggRes, found := agg.Filter("retweetsFilter")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if filterAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if filterAggRes.DocCount != 2 {
- t.Fatalf("expected %v; got: %v", 2, filterAggRes.DocCount)
- }
-
- // Retrieve sub-aggregation
- avgRetweetsAggRes, found := filterAggRes.Avg("avgRetweetsSub")
- if !found {
- t.Error("expected sub-aggregation \"avgRetweets\" to be found; got false")
- }
- if avgRetweetsAggRes == nil {
- t.Fatal("expected sub-aggregation \"avgRetweets\"; got nil")
- }
- if avgRetweetsAggRes.Value == nil {
- t.Fatalf("expected != nil; got: %v", avgRetweetsAggRes.Value)
- }
- if *avgRetweetsAggRes.Value != 54.0 {
- t.Errorf("expected %v; got: %v", 54.0, *avgRetweetsAggRes.Value)
- }
-
- // queryFilter
- queryFilterAggRes, found := agg.Filter("queryFilter")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if queryFilterAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if queryFilterAggRes.DocCount != 2 {
- t.Fatalf("expected %v; got: %v", 2, queryFilterAggRes.DocCount)
- }
-
- // significantTerms
- stAggRes, found := agg.SignificantTerms("significantTerms")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if stAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if stAggRes.DocCount != 3 {
- t.Errorf("expected %v; got: %v", 3, stAggRes.DocCount)
- }
- if len(stAggRes.Buckets) != 0 {
- t.Errorf("expected %v; got: %v", 0, len(stAggRes.Buckets))
- }
-
- // retweetsRange
- rangeAggRes, found := agg.Range("retweetsRange")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if rangeAggRes == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if len(rangeAggRes.Buckets) != 3 {
- t.Fatalf("expected %d; got: %d", 3, len(rangeAggRes.Buckets))
- }
- if rangeAggRes.Buckets[0].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, rangeAggRes.Buckets[0].DocCount)
- }
- if rangeAggRes.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, rangeAggRes.Buckets[1].DocCount)
- }
- if rangeAggRes.Buckets[2].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, rangeAggRes.Buckets[2].DocCount)
- }
-
- // retweetsKeyedRange
- keyedRangeAggRes, found := agg.KeyedRange("retweetsKeyedRange")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if keyedRangeAggRes == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if len(keyedRangeAggRes.Buckets) != 3 {
- t.Fatalf("expected %d; got: %d", 3, len(keyedRangeAggRes.Buckets))
- }
- _, found = keyedRangeAggRes.Buckets["no-such-key"]
- if found {
- t.Fatalf("expected bucket to not be found; got: %v", found)
- }
- bucket, found := keyedRangeAggRes.Buckets["*-10.0"]
- if !found {
- t.Fatalf("expected bucket to be found; got: %v", found)
- }
- if bucket.DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, bucket.DocCount)
- }
- bucket, found = keyedRangeAggRes.Buckets["10.0-100.0"]
- if !found {
- t.Fatalf("expected bucket to be found; got: %v", found)
- }
- if bucket.DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, bucket.DocCount)
- }
- bucket, found = keyedRangeAggRes.Buckets["100.0-*"]
- if !found {
- t.Fatalf("expected bucket to be found; got: %v", found)
- }
- if bucket.DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, bucket.DocCount)
- }
-
- // dateRange
- dateRangeRes, found := agg.DateRange("dateRange")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if dateRangeRes == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if dateRangeRes.Buckets[0].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, dateRangeRes.Buckets[0].DocCount)
- }
- if dateRangeRes.Buckets[0].From != nil {
- t.Fatal("expected From to be nil")
- }
- if dateRangeRes.Buckets[0].To == nil {
- t.Fatal("expected To to be != nil")
- }
- if *dateRangeRes.Buckets[0].To != 1.325376e+12 {
- t.Errorf("expected %v; got: %v", 1.325376e+12, *dateRangeRes.Buckets[0].To)
- }
- if dateRangeRes.Buckets[0].ToAsString != "2012-01-01T00:00:00.000Z" {
- t.Errorf("expected %q; got: %q", "2012-01-01T00:00:00.000Z", dateRangeRes.Buckets[0].ToAsString)
- }
- if dateRangeRes.Buckets[1].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, dateRangeRes.Buckets[1].DocCount)
- }
- if dateRangeRes.Buckets[1].From == nil {
- t.Fatal("expected From to be != nil")
- }
- if *dateRangeRes.Buckets[1].From != 1.325376e+12 {
- t.Errorf("expected From = %v; got: %v", 1.325376e+12, *dateRangeRes.Buckets[1].From)
- }
- if dateRangeRes.Buckets[1].FromAsString != "2012-01-01T00:00:00.000Z" {
- t.Errorf("expected FromAsString = %q; got: %q", "2012-01-01T00:00:00.000Z", dateRangeRes.Buckets[1].FromAsString)
- }
- if dateRangeRes.Buckets[1].To == nil {
- t.Fatal("expected To to be != nil")
- }
- if *dateRangeRes.Buckets[1].To != 1.3569984e+12 {
- t.Errorf("expected To = %v; got: %v", 1.3569984e+12, *dateRangeRes.Buckets[1].To)
- }
- if dateRangeRes.Buckets[1].ToAsString != "2013-01-01T00:00:00.000Z" {
- t.Errorf("expected ToAsString = %q; got: %q", "2013-01-01T00:00:00.000Z", dateRangeRes.Buckets[1].ToAsString)
- }
- if dateRangeRes.Buckets[2].DocCount != 0 {
- t.Errorf("expected %d; got: %d", 0, dateRangeRes.Buckets[2].DocCount)
- }
- if dateRangeRes.Buckets[2].To != nil {
- t.Fatal("expected To to be nil")
- }
- if dateRangeRes.Buckets[2].From == nil {
- t.Fatal("expected From to be != nil")
- }
- if *dateRangeRes.Buckets[2].From != 1.3569984e+12 {
- t.Errorf("expected %v; got: %v", 1.3569984e+12, *dateRangeRes.Buckets[2].From)
- }
- if dateRangeRes.Buckets[2].FromAsString != "2013-01-01T00:00:00.000Z" {
- t.Errorf("expected %q; got: %q", "2013-01-01T00:00:00.000Z", dateRangeRes.Buckets[2].FromAsString)
- }
-
- // missingTags
- missingRes, found := agg.Missing("missingTags")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if missingRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if missingRes.DocCount != 0 {
- t.Errorf("expected searchResult.Aggregations[\"missingTags\"].DocCount = %v; got %v", 0, missingRes.DocCount)
- }
-
- // retweetsHisto
- histoRes, found := agg.Histogram("retweetsHisto")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if histoRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(histoRes.Buckets) != 2 {
- t.Fatalf("expected %d; got: %d", 2, len(histoRes.Buckets))
- }
- if histoRes.Buckets[0].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, histoRes.Buckets[0].DocCount)
- }
- if histoRes.Buckets[0].Key != 0.0 {
- t.Errorf("expected %v; got: %v", 0.0, histoRes.Buckets[0].Key)
- }
- if histoRes.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, histoRes.Buckets[1].DocCount)
- }
- if histoRes.Buckets[1].Key != 100.0 {
- t.Errorf("expected %v; got: %v", 100.0, histoRes.Buckets[1].Key)
- }
-
- // dateHisto
- dateHistoRes, found := agg.DateHistogram("dateHisto")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if dateHistoRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(dateHistoRes.Buckets) != 2 {
- t.Fatalf("expected %d; got: %d", 2, len(dateHistoRes.Buckets))
- }
- if dateHistoRes.Buckets[0].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, dateHistoRes.Buckets[0].DocCount)
- }
- if dateHistoRes.Buckets[0].Key != 1.29384e+12 {
- t.Errorf("expected %v; got: %v", 1.29384e+12, dateHistoRes.Buckets[0].Key)
- }
- if dateHistoRes.Buckets[0].KeyAsString == nil {
- t.Fatalf("expected != nil; got: %q", dateHistoRes.Buckets[0].KeyAsString)
- }
- if *dateHistoRes.Buckets[0].KeyAsString != "2011-01-01T00:00:00.000Z" {
- t.Errorf("expected %q; got: %q", "2011-01-01T00:00:00.000Z", *dateHistoRes.Buckets[0].KeyAsString)
- }
- if dateHistoRes.Buckets[1].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, dateHistoRes.Buckets[1].DocCount)
- }
- if dateHistoRes.Buckets[1].Key != 1.325376e+12 {
- t.Errorf("expected %v; got: %v", 1.325376e+12, dateHistoRes.Buckets[1].Key)
- }
- if dateHistoRes.Buckets[1].KeyAsString == nil {
- t.Fatalf("expected != nil; got: %q", dateHistoRes.Buckets[1].KeyAsString)
- }
- if *dateHistoRes.Buckets[1].KeyAsString != "2012-01-01T00:00:00.000Z" {
- t.Errorf("expected %q; got: %q", "2012-01-01T00:00:00.000Z", *dateHistoRes.Buckets[1].KeyAsString)
- }
-
- // topHits
- topTags, found := agg.Terms("top-tags")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if topTags == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if esversion >= "1.4.0" {
- if topTags.DocCountErrorUpperBound != 0 {
- t.Errorf("expected %v; got: %v", 0, topTags.DocCountErrorUpperBound)
- }
- if topTags.SumOfOtherDocCount != 1 {
- t.Errorf("expected %v; got: %v", 1, topTags.SumOfOtherDocCount)
- }
- }
- if len(topTags.Buckets) != 3 {
- t.Fatalf("expected %d; got: %d", 3, len(topTags.Buckets))
- }
- if topTags.Buckets[0].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, topTags.Buckets[0].DocCount)
- }
- if topTags.Buckets[0].Key != "golang" {
- t.Errorf("expected %v; got: %v", "golang", topTags.Buckets[0].Key)
- }
- topHits, found := topTags.Buckets[0].TopHits("top_tag_hits")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if topHits == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if topHits.Hits == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if topHits.Hits.TotalHits != 2 {
- t.Errorf("expected %d; got: %d", 2, topHits.Hits.TotalHits)
- }
- if topHits.Hits.Hits == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(topHits.Hits.Hits) != 2 {
- t.Fatalf("expected %d; got: %d", 2, len(topHits.Hits.Hits))
- }
- hit := topHits.Hits.Hits[0]
- if !found {
- t.Fatalf("expected %v; got: %v", true, found)
- }
- if hit == nil {
- t.Fatal("expected != nil; got: nil")
- }
- var tw tweet
- if err := json.Unmarshal(*hit.Source, &tw); err != nil {
- t.Fatalf("expected no error; got: %v", err)
- }
- if tw.Message != "Welcome to Golang and Elasticsearch." {
- t.Errorf("expected %q; got: %q", "Welcome to Golang and Elasticsearch.", tw.Message)
- }
- if topTags.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, topTags.Buckets[1].DocCount)
- }
- if topTags.Buckets[1].Key != "cycling" {
- t.Errorf("expected %v; got: %v", "cycling", topTags.Buckets[1].Key)
- }
- topHits, found = topTags.Buckets[1].TopHits("top_tag_hits")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if topHits == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if topHits.Hits == nil {
- t.Fatal("expected != nil; got nil")
- }
- if topHits.Hits.TotalHits != 1 {
- t.Errorf("expected %d; got: %d", 1, topHits.Hits.TotalHits)
- }
- if topTags.Buckets[2].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, topTags.Buckets[2].DocCount)
- }
- if topTags.Buckets[2].Key != "elasticsearch" {
- t.Errorf("expected %v; got: %v", "elasticsearch", topTags.Buckets[2].Key)
- }
- topHits, found = topTags.Buckets[2].TopHits("top_tag_hits")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if topHits == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if topHits.Hits == nil {
- t.Fatal("expected != nil; got: nil")
- }
- if topHits.Hits.TotalHits != 1 {
- t.Errorf("expected %d; got: %d", 1, topHits.Hits.TotalHits)
- }
-
- // viewport via geo_bounds (1.3.0 has an error in that it doesn't output the aggregation name)
- geoBoundsRes, found := agg.GeoBounds("viewport")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if geoBoundsRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
-
- if esversion >= "1.4" {
- // Filters agg "countByUser"
- countByUserAggRes, found := agg.Filters("countByUser")
- if !found {
- t.Errorf("expected %v; got: %v", true, found)
- }
- if countByUserAggRes == nil {
- t.Fatalf("expected != nil; got: nil")
- }
- if len(countByUserAggRes.Buckets) != 2 {
- t.Fatalf("expected %d; got: %d", 2, len(countByUserAggRes.Buckets))
- }
- if countByUserAggRes.Buckets[0].DocCount != 2 {
- t.Errorf("expected %d; got: %d", 2, countByUserAggRes.Buckets[0].DocCount)
- }
- if countByUserAggRes.Buckets[1].DocCount != 1 {
- t.Errorf("expected %d; got: %d", 1, countByUserAggRes.Buckets[1].DocCount)
- }
- }
-}
-
-// TestAggsMarshal ensures that marshaling aggregations back into a string
-// does not yield base64 encoded data. See https://github.com/olivere/elastic/issues/51
-// and https://groups.google.com/forum/#!topic/Golang-Nuts/38ShOlhxAYY for details.
-func TestAggsMarshal(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere",
- Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Image: "http://golang.org/doc/gopher/gophercolor.png",
- Tags: []string{"golang", "elasticsearch"},
- Location: "48.1333,11.5667", // lat,lon
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- dhagg := NewDateHistogramAggregation().Field("created").Interval("year")
-
- // Run query
- builder := client.Search().Index(testIndexName).Query(&all)
- builder = builder.Aggregation("dhagg", dhagg)
- searchResult, err := builder.Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.TotalHits() != 1 {
- t.Errorf("expected Hits.TotalHits = %d; got: %d", 1, searchResult.TotalHits())
- }
- if _, found := searchResult.Aggregations["dhagg"]; !found {
- t.Fatalf("expected aggregation %q", "dhagg")
- }
- buf, err := json.Marshal(searchResult)
- if err != nil {
- t.Fatal(err)
- }
- s := string(buf)
- if i := strings.Index(s, `{"dhagg":{"buckets":[{"key_as_string":"2012-01-01`); i < 0 {
- t.Errorf("expected to serialize aggregation into string; got: %v", s)
- }
-}
-
-func TestAggsMin(t *testing.T) {
- s := `{
- "min_price": {
- "value": 10
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Min("min_price")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(10) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(10), *agg.Value)
- }
-}
-
-func TestAggsMax(t *testing.T) {
- s := `{
- "max_price": {
- "value": 35
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Max("max_price")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(35) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(35), *agg.Value)
- }
-}
-
-func TestAggsSum(t *testing.T) {
- s := `{
- "intraday_return": {
- "value": 2.18
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Sum("intraday_return")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(2.18) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(2.18), *agg.Value)
- }
-}
-
-func TestAggsAvg(t *testing.T) {
- s := `{
- "avg_grade": {
- "value": 75
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Avg("avg_grade")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(75) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(75), *agg.Value)
- }
-}
-
-func TestAggsValueCount(t *testing.T) {
- s := `{
- "grades_count": {
- "value": 10
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.ValueCount("grades_count")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(10) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(10), *agg.Value)
- }
-}
-
-func TestAggsCardinality(t *testing.T) {
- s := `{
- "author_count": {
- "value": 12
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Cardinality("author_count")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Value == nil {
- t.Fatalf("expected aggregation value != nil; got: %v", agg.Value)
- }
- if *agg.Value != float64(12) {
- t.Fatalf("expected aggregation value = %v; got: %v", float64(12), *agg.Value)
- }
-}
-
-func TestAggsStats(t *testing.T) {
- s := `{
- "grades_stats": {
- "count": 6,
- "min": 60,
- "max": 98,
- "avg": 78.5,
- "sum": 471
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Stats("grades_stats")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Count != int64(6) {
- t.Fatalf("expected aggregation Count = %v; got: %v", int64(6), agg.Count)
- }
- if agg.Min == nil {
- t.Fatalf("expected aggregation Min != nil; got: %v", agg.Min)
- }
- if *agg.Min != float64(60) {
- t.Fatalf("expected aggregation Min = %v; got: %v", float64(60), *agg.Min)
- }
- if agg.Max == nil {
- t.Fatalf("expected aggregation Max != nil; got: %v", agg.Max)
- }
- if *agg.Max != float64(98) {
- t.Fatalf("expected aggregation Max = %v; got: %v", float64(98), *agg.Max)
- }
- if agg.Avg == nil {
- t.Fatalf("expected aggregation Avg != nil; got: %v", agg.Avg)
- }
- if *agg.Avg != float64(78.5) {
- t.Fatalf("expected aggregation Avg = %v; got: %v", float64(78.5), *agg.Avg)
- }
- if agg.Sum == nil {
- t.Fatalf("expected aggregation Sum != nil; got: %v", agg.Sum)
- }
- if *agg.Sum != float64(471) {
- t.Fatalf("expected aggregation Sum = %v; got: %v", float64(471), *agg.Sum)
- }
-}
-
-func TestAggsExtendedStats(t *testing.T) {
- s := `{
- "grades_stats": {
- "count": 6,
- "min": 72,
- "max": 117.6,
- "avg": 94.2,
- "sum": 565.2,
- "sum_of_squares": 54551.51999999999,
- "variance": 218.2799999999976,
- "std_deviation": 14.774302013969987
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.ExtendedStats("grades_stats")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Count != int64(6) {
- t.Fatalf("expected aggregation Count = %v; got: %v", int64(6), agg.Count)
- }
- if agg.Min == nil {
- t.Fatalf("expected aggregation Min != nil; got: %v", agg.Min)
- }
- if *agg.Min != float64(72) {
- t.Fatalf("expected aggregation Min = %v; got: %v", float64(72), *agg.Min)
- }
- if agg.Max == nil {
- t.Fatalf("expected aggregation Max != nil; got: %v", agg.Max)
- }
- if *agg.Max != float64(117.6) {
- t.Fatalf("expected aggregation Max = %v; got: %v", float64(117.6), *agg.Max)
- }
- if agg.Avg == nil {
- t.Fatalf("expected aggregation Avg != nil; got: %v", agg.Avg)
- }
- if *agg.Avg != float64(94.2) {
- t.Fatalf("expected aggregation Avg = %v; got: %v", float64(94.2), *agg.Avg)
- }
- if agg.Sum == nil {
- t.Fatalf("expected aggregation Sum != nil; got: %v", agg.Sum)
- }
- if *agg.Sum != float64(565.2) {
- t.Fatalf("expected aggregation Sum = %v; got: %v", float64(565.2), *agg.Sum)
- }
- if agg.SumOfSquares == nil {
- t.Fatalf("expected aggregation sum_of_squares != nil; got: %v", agg.SumOfSquares)
- }
- if *agg.SumOfSquares != float64(54551.51999999999) {
- t.Fatalf("expected aggregation sum_of_squares = %v; got: %v", float64(54551.51999999999), *agg.SumOfSquares)
- }
- if agg.Variance == nil {
- t.Fatalf("expected aggregation Variance != nil; got: %v", agg.Variance)
- }
- if *agg.Variance != float64(218.2799999999976) {
- t.Fatalf("expected aggregation Variance = %v; got: %v", float64(218.2799999999976), *agg.Variance)
- }
- if agg.StdDeviation == nil {
- t.Fatalf("expected aggregation StdDeviation != nil; got: %v", agg.StdDeviation)
- }
- if *agg.StdDeviation != float64(14.774302013969987) {
- t.Fatalf("expected aggregation StdDeviation = %v; got: %v", float64(14.774302013969987), *agg.StdDeviation)
- }
-}
-
-func TestAggsPercentiles(t *testing.T) {
- s := `{
- "load_time_outlier": {
- "values" : {
- "1.0": 15,
- "5.0": 20,
- "25.0": 23,
- "50.0": 25,
- "75.0": 29,
- "95.0": 60,
- "99.0": 150
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Percentiles("load_time_outlier")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Values == nil {
- t.Fatalf("expected aggregation Values != nil; got: %v", agg.Values)
- }
- if len(agg.Values) != 7 {
- t.Fatalf("expected %d aggregation Values; got: %d", 7, len(agg.Values))
- }
- if agg.Values["1.0"] != float64(15) {
- t.Errorf("expected aggregation value for \"1.0\" = %v; got: %v", float64(15), agg.Values["1.0"])
- }
- if agg.Values["5.0"] != float64(20) {
- t.Errorf("expected aggregation value for \"5.0\" = %v; got: %v", float64(20), agg.Values["5.0"])
- }
- if agg.Values["25.0"] != float64(23) {
- t.Errorf("expected aggregation value for \"25.0\" = %v; got: %v", float64(23), agg.Values["25.0"])
- }
- if agg.Values["50.0"] != float64(25) {
- t.Errorf("expected aggregation value for \"50.0\" = %v; got: %v", float64(25), agg.Values["50.0"])
- }
- if agg.Values["75.0"] != float64(29) {
- t.Errorf("expected aggregation value for \"75.0\" = %v; got: %v", float64(29), agg.Values["75.0"])
- }
- if agg.Values["95.0"] != float64(60) {
- t.Errorf("expected aggregation value for \"95.0\" = %v; got: %v", float64(60), agg.Values["95.0"])
- }
- if agg.Values["99.0"] != float64(150) {
- t.Errorf("expected aggregation value for \"99.0\" = %v; got: %v", float64(150), agg.Values["99.0"])
- }
-}
-
-func TestAggsPercentilRanks(t *testing.T) {
- s := `{
- "load_time_outlier": {
- "values" : {
- "15": 92,
- "30": 100
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.PercentileRanks("load_time_outlier")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Values == nil {
- t.Fatalf("expected aggregation Values != nil; got: %v", agg.Values)
- }
- if len(agg.Values) != 2 {
- t.Fatalf("expected %d aggregation Values; got: %d", 7, len(agg.Values))
- }
- if agg.Values["15"] != float64(92) {
- t.Errorf("expected aggregation value for \"15\" = %v; got: %v", float64(92), agg.Values["15"])
- }
- if agg.Values["30"] != float64(100) {
- t.Errorf("expected aggregation value for \"30\" = %v; got: %v", float64(100), agg.Values["30"])
- }
-}
-
-func TestAggsTopHits(t *testing.T) {
- s := `{
- "top-tags": {
- "buckets": [
- {
- "key": "windows-7",
- "doc_count": 25365,
- "top_tags_hits": {
- "hits": {
- "total": 25365,
- "max_score": 1,
- "hits": [
- {
- "_index": "stack",
- "_type": "question",
- "_id": "602679",
- "_score": 1,
- "_source": {
- "title": "Windows port opening"
- },
- "sort": [
- 1370143231177
- ]
- }
- ]
- }
- }
- },
- {
- "key": "linux",
- "doc_count": 18342,
- "top_tags_hits": {
- "hits": {
- "total": 18342,
- "max_score": 1,
- "hits": [
- {
- "_index": "stack",
- "_type": "question",
- "_id": "602672",
- "_score": 1,
- "_source": {
- "title": "Ubuntu RFID Screensaver lock-unlock"
- },
- "sort": [
- 1370143379747
- ]
- }
- ]
- }
- }
- },
- {
- "key": "windows",
- "doc_count": 18119,
- "top_tags_hits": {
- "hits": {
- "total": 18119,
- "max_score": 1,
- "hits": [
- {
- "_index": "stack",
- "_type": "question",
- "_id": "602678",
- "_score": 1,
- "_source": {
- "title": "If I change my computers date / time, what could be affected?"
- },
- "sort": [
- 1370142868283
- ]
- }
- ]
- }
- }
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Terms("top-tags")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 3 {
- t.Errorf("expected %d bucket entries; got: %d", 3, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != "windows-7" {
- t.Errorf("expected bucket key = %q; got: %q", "windows-7", agg.Buckets[0].Key)
- }
- if agg.Buckets[1].Key != "linux" {
- t.Errorf("expected bucket key = %q; got: %q", "linux", agg.Buckets[1].Key)
- }
- if agg.Buckets[2].Key != "windows" {
- t.Errorf("expected bucket key = %q; got: %q", "windows", agg.Buckets[2].Key)
- }
-
- // Sub-aggregation of top-hits
- subAgg, found := agg.Buckets[0].TopHits("top_tags_hits")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Hits == nil {
- t.Fatalf("expected sub aggregation Hits != nil; got: %v", subAgg.Hits)
- }
- if subAgg.Hits.TotalHits != 25365 {
- t.Fatalf("expected sub aggregation Hits.TotalHits = %d; got: %d", 25365, subAgg.Hits.TotalHits)
- }
- if subAgg.Hits.MaxScore == nil {
- t.Fatalf("expected sub aggregation Hits.MaxScore != %v; got: %v", nil, *subAgg.Hits.MaxScore)
- }
- if *subAgg.Hits.MaxScore != float64(1.0) {
- t.Fatalf("expected sub aggregation Hits.MaxScore = %v; got: %v", float64(1.0), *subAgg.Hits.MaxScore)
- }
-
- subAgg, found = agg.Buckets[1].TopHits("top_tags_hits")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Hits == nil {
- t.Fatalf("expected sub aggregation Hits != nil; got: %v", subAgg.Hits)
- }
- if subAgg.Hits.TotalHits != 18342 {
- t.Fatalf("expected sub aggregation Hits.TotalHits = %d; got: %d", 18342, subAgg.Hits.TotalHits)
- }
- if subAgg.Hits.MaxScore == nil {
- t.Fatalf("expected sub aggregation Hits.MaxScore != %v; got: %v", nil, *subAgg.Hits.MaxScore)
- }
- if *subAgg.Hits.MaxScore != float64(1.0) {
- t.Fatalf("expected sub aggregation Hits.MaxScore = %v; got: %v", float64(1.0), *subAgg.Hits.MaxScore)
- }
-
- subAgg, found = agg.Buckets[2].TopHits("top_tags_hits")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Hits == nil {
- t.Fatalf("expected sub aggregation Hits != nil; got: %v", subAgg.Hits)
- }
- if subAgg.Hits.TotalHits != 18119 {
- t.Fatalf("expected sub aggregation Hits.TotalHits = %d; got: %d", 18119, subAgg.Hits.TotalHits)
- }
- if subAgg.Hits.MaxScore == nil {
- t.Fatalf("expected sub aggregation Hits.MaxScore != %v; got: %v", nil, *subAgg.Hits.MaxScore)
- }
- if *subAgg.Hits.MaxScore != float64(1.0) {
- t.Fatalf("expected sub aggregation Hits.MaxScore = %v; got: %v", float64(1.0), *subAgg.Hits.MaxScore)
- }
-}
-
-func TestAggsGlobal(t *testing.T) {
- s := `{
- "all_products" : {
- "doc_count" : 100,
- "avg_price" : {
- "value" : 56.3
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Global("all_products")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 100 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 100, agg.DocCount)
- }
-
- // Sub-aggregation
- subAgg, found := agg.Avg("avg_price")
- if !found {
- t.Fatalf("expected sub-aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub-aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Value == nil {
- t.Fatalf("expected sub-aggregation value != nil; got: %v", subAgg.Value)
- }
- if *subAgg.Value != float64(56.3) {
- t.Fatalf("expected sub-aggregation value = %v; got: %v", float64(56.3), *subAgg.Value)
- }
-}
-
-func TestAggsFilter(t *testing.T) {
- s := `{
- "in_stock_products" : {
- "doc_count" : 100,
- "avg_price" : { "value" : 56.3 }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Filter("in_stock_products")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 100 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 100, agg.DocCount)
- }
-
- // Sub-aggregation
- subAgg, found := agg.Avg("avg_price")
- if !found {
- t.Fatalf("expected sub-aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub-aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Value == nil {
- t.Fatalf("expected sub-aggregation value != nil; got: %v", subAgg.Value)
- }
- if *subAgg.Value != float64(56.3) {
- t.Fatalf("expected sub-aggregation value = %v; got: %v", float64(56.3), *subAgg.Value)
- }
-}
-
-func TestAggsFiltersWithBuckets(t *testing.T) {
- s := `{
- "messages" : {
- "buckets" : [
- {
- "doc_count" : 34,
- "monthly" : {
- "buckets" : []
- }
- },
- {
- "doc_count" : 439,
- "monthly" : {
- "buckets" : []
- }
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Filters("messages")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != %v; got: %v", nil, agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Fatalf("expected %d buckets; got: %d", 2, len(agg.Buckets))
- }
-
- if agg.Buckets[0].DocCount != 34 {
- t.Fatalf("expected DocCount = %d; got: %d", 34, agg.Buckets[0].DocCount)
- }
- subAgg, found := agg.Buckets[0].Histogram("monthly")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != %v; got: %v", nil, subAgg)
- }
-
- if agg.Buckets[1].DocCount != 439 {
- t.Fatalf("expected DocCount = %d; got: %d", 439, agg.Buckets[1].DocCount)
- }
- subAgg, found = agg.Buckets[1].Histogram("monthly")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != %v; got: %v", nil, subAgg)
- }
-}
-
-func TestAggsFiltersWithNamedBuckets(t *testing.T) {
- s := `{
- "messages" : {
- "buckets" : {
- "errors" : {
- "doc_count" : 34,
- "monthly" : {
- "buckets" : []
- }
- },
- "warnings" : {
- "doc_count" : 439,
- "monthly" : {
- "buckets" : []
- }
- }
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Filters("messages")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.NamedBuckets == nil {
- t.Fatalf("expected aggregation buckets != %v; got: %v", nil, agg.NamedBuckets)
- }
- if len(agg.NamedBuckets) != 2 {
- t.Fatalf("expected %d buckets; got: %d", 2, len(agg.NamedBuckets))
- }
-
- if agg.NamedBuckets["errors"].DocCount != 34 {
- t.Fatalf("expected DocCount = %d; got: %d", 34, agg.NamedBuckets["errors"].DocCount)
- }
- subAgg, found := agg.NamedBuckets["errors"].Histogram("monthly")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != %v; got: %v", nil, subAgg)
- }
-
- if agg.NamedBuckets["warnings"].DocCount != 439 {
- t.Fatalf("expected DocCount = %d; got: %d", 439, agg.NamedBuckets["warnings"].DocCount)
- }
- subAgg, found = agg.NamedBuckets["warnings"].Histogram("monthly")
- if !found {
- t.Fatalf("expected sub aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub aggregation != %v; got: %v", nil, subAgg)
- }
-}
-
-func TestAggsMissing(t *testing.T) {
- s := `{
- "products_without_a_price" : {
- "doc_count" : 10
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Missing("products_without_a_price")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 10 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 10, agg.DocCount)
- }
-}
-
-func TestAggsNested(t *testing.T) {
- s := `{
- "resellers": {
- "min_price": {
- "value" : 350
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Nested("resellers")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 0 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 0, agg.DocCount)
- }
-
- // Sub-aggregation
- subAgg, found := agg.Avg("min_price")
- if !found {
- t.Fatalf("expected sub-aggregation to be found; got: %v", found)
- }
- if subAgg == nil {
- t.Fatalf("expected sub-aggregation != nil; got: %v", subAgg)
- }
- if subAgg.Value == nil {
- t.Fatalf("expected sub-aggregation value != nil; got: %v", subAgg.Value)
- }
- if *subAgg.Value != float64(350) {
- t.Fatalf("expected sub-aggregation value = %v; got: %v", float64(350), *subAgg.Value)
- }
-}
-
-func TestAggsReverseNested(t *testing.T) {
- s := `{
- "comment_to_issue": {
- "doc_count" : 10
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.ReverseNested("comment_to_issue")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 10 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 10, agg.DocCount)
- }
-}
-
-func TestAggsChildren(t *testing.T) {
- s := `{
- "to-answers": {
- "doc_count" : 10
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Children("to-answers")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 10 {
- t.Fatalf("expected aggregation DocCount = %d; got: %d", 10, agg.DocCount)
- }
-}
-
-func TestAggsTerms(t *testing.T) {
- s := `{
- "users" : {
- "doc_count_error_upper_bound" : 1,
- "sum_other_doc_count" : 2,
- "buckets" : [ {
- "key" : "olivere",
- "doc_count" : 2
- }, {
- "key" : "sandrae",
- "doc_count" : 1
- } ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Terms("users")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != "olivere" {
- t.Errorf("expected key %q; got: %q", "olivere", agg.Buckets[0].Key)
- }
- if agg.Buckets[0].DocCount != 2 {
- t.Errorf("expected doc count %d; got: %d", 2, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != "sandrae" {
- t.Errorf("expected key %q; got: %q", "sandrae", agg.Buckets[1].Key)
- }
- if agg.Buckets[1].DocCount != 1 {
- t.Errorf("expected doc count %d; got: %d", 1, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsTermsWithNumericKeys(t *testing.T) {
- s := `{
- "users" : {
- "doc_count_error_upper_bound" : 1,
- "sum_other_doc_count" : 2,
- "buckets" : [ {
- "key" : 17,
- "doc_count" : 2
- }, {
- "key" : 21,
- "doc_count" : 1
- } ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Terms("users")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != float64(17) {
- t.Errorf("expected key %v; got: %v", 17, agg.Buckets[0].Key)
- }
- if got, err := agg.Buckets[0].KeyNumber.Int64(); err != nil {
- t.Errorf("expected to convert key to int64; got: %v", err)
- } else if got != 17 {
- t.Errorf("expected key %v; got: %v", 17, agg.Buckets[0].Key)
- }
- if agg.Buckets[0].DocCount != 2 {
- t.Errorf("expected doc count %d; got: %d", 2, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != float64(21) {
- t.Errorf("expected key %v; got: %v", 21, agg.Buckets[1].Key)
- }
- if got, err := agg.Buckets[1].KeyNumber.Int64(); err != nil {
- t.Errorf("expected to convert key to int64; got: %v", err)
- } else if got != 21 {
- t.Errorf("expected key %v; got: %v", 21, agg.Buckets[1].Key)
- }
- if agg.Buckets[1].DocCount != 1 {
- t.Errorf("expected doc count %d; got: %d", 1, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsTermsWithBoolKeys(t *testing.T) {
- s := `{
- "users" : {
- "doc_count_error_upper_bound" : 1,
- "sum_other_doc_count" : 2,
- "buckets" : [ {
- "key" : true,
- "doc_count" : 2
- }, {
- "key" : false,
- "doc_count" : 1
- } ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Terms("users")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != true {
- t.Errorf("expected key %v; got: %v", true, agg.Buckets[0].Key)
- }
- if agg.Buckets[0].DocCount != 2 {
- t.Errorf("expected doc count %d; got: %d", 2, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != false {
- t.Errorf("expected key %v; got: %v", false, agg.Buckets[1].Key)
- }
- if agg.Buckets[1].DocCount != 1 {
- t.Errorf("expected doc count %d; got: %d", 1, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsSignificantTerms(t *testing.T) {
- s := `{
- "significantCrimeTypes" : {
- "doc_count": 47347,
- "buckets" : [
- {
- "key": "Bicycle theft",
- "doc_count": 3640,
- "score": 0.371235374214817,
- "bg_count": 66799
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.SignificantTerms("significantCrimeTypes")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.DocCount != 47347 {
- t.Fatalf("expected aggregation DocCount != %d; got: %d", 47347, agg.DocCount)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 1 {
- t.Errorf("expected %d bucket entries; got: %d", 1, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != "Bicycle theft" {
- t.Errorf("expected key = %q; got: %q", "Bicycle theft", agg.Buckets[0].Key)
- }
- if agg.Buckets[0].DocCount != 3640 {
- t.Errorf("expected doc count = %d; got: %d", 3640, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[0].Score != float64(0.371235374214817) {
- t.Errorf("expected score = %v; got: %v", float64(0.371235374214817), agg.Buckets[0].Score)
- }
- if agg.Buckets[0].BgCount != 66799 {
- t.Errorf("expected BgCount = %d; got: %d", 66799, agg.Buckets[0].BgCount)
- }
-}
-
-func TestAggsRange(t *testing.T) {
- s := `{
- "price_ranges" : {
- "buckets": [
- {
- "to": 50,
- "doc_count": 2
- },
- {
- "from": 50,
- "to": 100,
- "doc_count": 4
- },
- {
- "from": 100,
- "doc_count": 4
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Range("price_ranges")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 3 {
- t.Errorf("expected %d bucket entries; got: %d", 3, len(agg.Buckets))
- }
- if agg.Buckets[0].From != nil {
- t.Errorf("expected From = %v; got: %v", nil, agg.Buckets[0].From)
- }
- if agg.Buckets[0].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[0].To)
- }
- if *agg.Buckets[0].To != float64(50) {
- t.Errorf("expected To = %v; got: %v", float64(50), *agg.Buckets[0].To)
- }
- if agg.Buckets[0].DocCount != 2 {
- t.Errorf("expected DocCount = %d; got: %d", 2, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[1].From)
- }
- if *agg.Buckets[1].From != float64(50) {
- t.Errorf("expected From = %v; got: %v", float64(50), *agg.Buckets[1].From)
- }
- if agg.Buckets[1].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[1].To)
- }
- if *agg.Buckets[1].To != float64(100) {
- t.Errorf("expected To = %v; got: %v", float64(100), *agg.Buckets[1].To)
- }
- if agg.Buckets[1].DocCount != 4 {
- t.Errorf("expected DocCount = %d; got: %d", 4, agg.Buckets[1].DocCount)
- }
- if agg.Buckets[2].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[2].From)
- }
- if *agg.Buckets[2].From != float64(100) {
- t.Errorf("expected From = %v; got: %v", float64(100), *agg.Buckets[2].From)
- }
- if agg.Buckets[2].To != nil {
- t.Errorf("expected To = %v; got: %v", nil, agg.Buckets[2].To)
- }
- if agg.Buckets[2].DocCount != 4 {
- t.Errorf("expected DocCount = %d; got: %d", 4, agg.Buckets[2].DocCount)
- }
-}
-
-func TestAggsDateRange(t *testing.T) {
- s := `{
- "range": {
- "buckets": [
- {
- "to": 1.3437792E+12,
- "to_as_string": "08-2012",
- "doc_count": 7
- },
- {
- "from": 1.3437792E+12,
- "from_as_string": "08-2012",
- "doc_count": 2
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.DateRange("range")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].From != nil {
- t.Errorf("expected From = %v; got: %v", nil, agg.Buckets[0].From)
- }
- if agg.Buckets[0].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[0].To)
- }
- if *agg.Buckets[0].To != float64(1.3437792E+12) {
- t.Errorf("expected To = %v; got: %v", float64(1.3437792E+12), *agg.Buckets[0].To)
- }
- if agg.Buckets[0].ToAsString != "08-2012" {
- t.Errorf("expected ToAsString = %q; got: %q", "08-2012", agg.Buckets[0].ToAsString)
- }
- if agg.Buckets[0].DocCount != 7 {
- t.Errorf("expected DocCount = %d; got: %d", 7, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[1].From)
- }
- if *agg.Buckets[1].From != float64(1.3437792E+12) {
- t.Errorf("expected From = %v; got: %v", float64(1.3437792E+12), *agg.Buckets[1].From)
- }
- if agg.Buckets[1].FromAsString != "08-2012" {
- t.Errorf("expected FromAsString = %q; got: %q", "08-2012", agg.Buckets[1].FromAsString)
- }
- if agg.Buckets[1].To != nil {
- t.Errorf("expected To = %v; got: %v", nil, agg.Buckets[1].To)
- }
- if agg.Buckets[1].DocCount != 2 {
- t.Errorf("expected DocCount = %d; got: %d", 2, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsIPv4Range(t *testing.T) {
- s := `{
- "ip_ranges": {
- "buckets" : [
- {
- "to": 167772165,
- "to_as_string": "10.0.0.5",
- "doc_count": 4
- },
- {
- "from": 167772165,
- "from_as_string": "10.0.0.5",
- "doc_count": 6
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.IPv4Range("ip_ranges")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].From != nil {
- t.Errorf("expected From = %v; got: %v", nil, agg.Buckets[0].From)
- }
- if agg.Buckets[0].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[0].To)
- }
- if *agg.Buckets[0].To != float64(167772165) {
- t.Errorf("expected To = %v; got: %v", float64(167772165), *agg.Buckets[0].To)
- }
- if agg.Buckets[0].ToAsString != "10.0.0.5" {
- t.Errorf("expected ToAsString = %q; got: %q", "10.0.0.5", agg.Buckets[0].ToAsString)
- }
- if agg.Buckets[0].DocCount != 4 {
- t.Errorf("expected DocCount = %d; got: %d", 4, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[1].From)
- }
- if *agg.Buckets[1].From != float64(167772165) {
- t.Errorf("expected From = %v; got: %v", float64(167772165), *agg.Buckets[1].From)
- }
- if agg.Buckets[1].FromAsString != "10.0.0.5" {
- t.Errorf("expected FromAsString = %q; got: %q", "10.0.0.5", agg.Buckets[1].FromAsString)
- }
- if agg.Buckets[1].To != nil {
- t.Errorf("expected To = %v; got: %v", nil, agg.Buckets[1].To)
- }
- if agg.Buckets[1].DocCount != 6 {
- t.Errorf("expected DocCount = %d; got: %d", 6, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsHistogram(t *testing.T) {
- s := `{
- "prices" : {
- "buckets": [
- {
- "key": 0,
- "doc_count": 2
- },
- {
- "key": 50,
- "doc_count": 4
- },
- {
- "key": 150,
- "doc_count": 3
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.Histogram("prices")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 3 {
- t.Errorf("expected %d buckets; got: %d", 3, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != 0 {
- t.Errorf("expected key = %v; got: %v", 0, agg.Buckets[0].Key)
- }
- if agg.Buckets[0].KeyAsString != nil {
- t.Fatalf("expected key_as_string = %v; got: %q", nil, *agg.Buckets[0].KeyAsString)
- }
- if agg.Buckets[0].DocCount != 2 {
- t.Errorf("expected doc count = %d; got: %d", 2, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != 50 {
- t.Errorf("expected key = %v; got: %v", 50, agg.Buckets[1].Key)
- }
- if agg.Buckets[1].KeyAsString != nil {
- t.Fatalf("expected key_as_string = %v; got: %q", nil, *agg.Buckets[1].KeyAsString)
- }
- if agg.Buckets[1].DocCount != 4 {
- t.Errorf("expected doc count = %d; got: %d", 4, agg.Buckets[1].DocCount)
- }
- if agg.Buckets[2].Key != 150 {
- t.Errorf("expected key = %v; got: %v", 150, agg.Buckets[2].Key)
- }
- if agg.Buckets[2].KeyAsString != nil {
- t.Fatalf("expected key_as_string = %v; got: %q", nil, *agg.Buckets[2].KeyAsString)
- }
- if agg.Buckets[2].DocCount != 3 {
- t.Errorf("expected doc count = %d; got: %d", 3, agg.Buckets[2].DocCount)
- }
-}
-
-func TestAggsDateHistogram(t *testing.T) {
- s := `{
- "articles_over_time": {
- "buckets": [
- {
- "key_as_string": "2013-02-02",
- "key": 1328140800000,
- "doc_count": 1
- },
- {
- "key_as_string": "2013-03-02",
- "key": 1330646400000,
- "doc_count": 2
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.DateHistogram("articles_over_time")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != 1328140800000 {
- t.Errorf("expected key %v; got: %v", 1328140800000, agg.Buckets[0].Key)
- }
- if agg.Buckets[0].KeyAsString == nil {
- t.Fatalf("expected key_as_string != nil; got: %v", agg.Buckets[0].KeyAsString)
- }
- if *agg.Buckets[0].KeyAsString != "2013-02-02" {
- t.Errorf("expected key_as_string %q; got: %q", "2013-02-02", *agg.Buckets[0].KeyAsString)
- }
- if agg.Buckets[0].DocCount != 1 {
- t.Errorf("expected doc count %d; got: %d", 1, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != 1330646400000 {
- t.Errorf("expected key %v; got: %v", 1330646400000, agg.Buckets[1].Key)
- }
- if agg.Buckets[1].KeyAsString == nil {
- t.Fatalf("expected key_as_string != nil; got: %v", agg.Buckets[1].KeyAsString)
- }
- if *agg.Buckets[1].KeyAsString != "2013-03-02" {
- t.Errorf("expected key_as_string %q; got: %q", "2013-03-02", *agg.Buckets[1].KeyAsString)
- }
- if agg.Buckets[1].DocCount != 2 {
- t.Errorf("expected doc count %d; got: %d", 2, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsGeoBounds(t *testing.T) {
- s := `{
- "viewport": {
- "bounds": {
- "top_left": {
- "lat": 80.45,
- "lon": -160.22
- },
- "bottom_right": {
- "lat": 40.65,
- "lon": 42.57
- }
- }
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.GeoBounds("viewport")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Bounds.TopLeft.Latitude != float64(80.45) {
- t.Fatalf("expected Bounds.TopLeft.Latitude != %v; got: %v", float64(80.45), agg.Bounds.TopLeft.Latitude)
- }
- if agg.Bounds.TopLeft.Longitude != float64(-160.22) {
- t.Fatalf("expected Bounds.TopLeft.Longitude != %v; got: %v", float64(-160.22), agg.Bounds.TopLeft.Longitude)
- }
- if agg.Bounds.BottomRight.Latitude != float64(40.65) {
- t.Fatalf("expected Bounds.BottomRight.Latitude != %v; got: %v", float64(40.65), agg.Bounds.BottomRight.Latitude)
- }
- if agg.Bounds.BottomRight.Longitude != float64(42.57) {
- t.Fatalf("expected Bounds.BottomRight.Longitude != %v; got: %v", float64(42.57), agg.Bounds.BottomRight.Longitude)
- }
-}
-
-func TestAggsGeoHash(t *testing.T) {
- s := `{
- "myLarge-GrainGeoHashGrid": {
- "buckets": [
- {
- "key": "svz",
- "doc_count": 10964
- },
- {
- "key": "sv8",
- "doc_count": 3198
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.GeoHash("myLarge-GrainGeoHashGrid")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(agg.Buckets))
- }
- if agg.Buckets[0].Key != "svz" {
- t.Errorf("expected key %q; got: %q", "svz", agg.Buckets[0].Key)
- }
- if agg.Buckets[0].DocCount != 10964 {
- t.Errorf("expected doc count %d; got: %d", 10964, agg.Buckets[0].DocCount)
- }
- if agg.Buckets[1].Key != "sv8" {
- t.Errorf("expected key %q; got: %q", "sv8", agg.Buckets[1].Key)
- }
- if agg.Buckets[1].DocCount != 3198 {
- t.Errorf("expected doc count %d; got: %d", 3198, agg.Buckets[1].DocCount)
- }
-}
-
-func TestAggsGeoDistance(t *testing.T) {
- s := `{
- "rings" : {
- "buckets": [
- {
- "unit": "km",
- "to": 100.0,
- "doc_count": 3
- },
- {
- "unit": "km",
- "from": 100.0,
- "to": 300.0,
- "doc_count": 1
- },
- {
- "unit": "km",
- "from": 300.0,
- "doc_count": 7
- }
- ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(s), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- agg, found := aggs.GeoDistance("rings")
- if !found {
- t.Fatalf("expected aggregation to be found; got: %v", found)
- }
- if agg == nil {
- t.Fatalf("expected aggregation != nil; got: %v", agg)
- }
- if agg.Buckets == nil {
- t.Fatalf("expected aggregation buckets != nil; got: %v", agg.Buckets)
- }
- if len(agg.Buckets) != 3 {
- t.Errorf("expected %d bucket entries; got: %d", 3, len(agg.Buckets))
- }
- if agg.Buckets[0].From != nil {
- t.Errorf("expected From = %v; got: %v", nil, agg.Buckets[0].From)
- }
- if agg.Buckets[0].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[0].To)
- }
- if *agg.Buckets[0].To != float64(100.0) {
- t.Errorf("expected To = %v; got: %v", float64(100.0), *agg.Buckets[0].To)
- }
- if agg.Buckets[0].DocCount != 3 {
- t.Errorf("expected DocCount = %d; got: %d", 4, agg.Buckets[0].DocCount)
- }
-
- if agg.Buckets[1].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[1].From)
- }
- if *agg.Buckets[1].From != float64(100.0) {
- t.Errorf("expected From = %v; got: %v", float64(100.0), *agg.Buckets[1].From)
- }
- if agg.Buckets[1].To == nil {
- t.Errorf("expected To != %v; got: %v", nil, agg.Buckets[1].To)
- }
- if *agg.Buckets[1].To != float64(300.0) {
- t.Errorf("expected From = %v; got: %v", float64(300.0), *agg.Buckets[1].To)
- }
- if agg.Buckets[1].DocCount != 1 {
- t.Errorf("expected DocCount = %d; got: %d", 1, agg.Buckets[1].DocCount)
- }
-
- if agg.Buckets[2].From == nil {
- t.Errorf("expected From != %v; got: %v", nil, agg.Buckets[2].From)
- }
- if *agg.Buckets[2].From != float64(300.0) {
- t.Errorf("expected From = %v; got: %v", float64(300.0), *agg.Buckets[2].From)
- }
- if agg.Buckets[2].To != nil {
- t.Errorf("expected To = %v; got: %v", nil, agg.Buckets[2].To)
- }
- if agg.Buckets[2].DocCount != 7 {
- t.Errorf("expected DocCount = %d; got: %d", 7, agg.Buckets[2].DocCount)
- }
-}
-
-func TestAggsSubAggregates(t *testing.T) {
- rs := `{
- "users" : {
- "doc_count_error_upper_bound" : 1,
- "sum_other_doc_count" : 2,
- "buckets" : [ {
- "key" : "olivere",
- "doc_count" : 2,
- "ts" : {
- "buckets" : [ {
- "key_as_string" : "2012-01-01T00:00:00.000Z",
- "key" : 1325376000000,
- "doc_count" : 2
- } ]
- }
- }, {
- "key" : "sandrae",
- "doc_count" : 1,
- "ts" : {
- "buckets" : [ {
- "key_as_string" : "2011-01-01T00:00:00.000Z",
- "key" : 1293840000000,
- "doc_count" : 1
- } ]
- }
- } ]
- }
-}`
-
- aggs := new(Aggregations)
- err := json.Unmarshal([]byte(rs), &aggs)
- if err != nil {
- t.Fatalf("expected no error decoding; got: %v", err)
- }
-
- // Access top-level aggregation
- users, found := aggs.Terms("users")
- if !found {
- t.Fatalf("expected users aggregation to be found; got: %v", found)
- }
- if users == nil {
- t.Fatalf("expected users aggregation; got: %v", users)
- }
- if users.Buckets == nil {
- t.Fatalf("expected users buckets; got: %v", users.Buckets)
- }
- if len(users.Buckets) != 2 {
- t.Errorf("expected %d bucket entries; got: %d", 2, len(users.Buckets))
- }
- if users.Buckets[0].Key != "olivere" {
- t.Errorf("expected key %q; got: %q", "olivere", users.Buckets[0].Key)
- }
- if users.Buckets[0].DocCount != 2 {
- t.Errorf("expected doc count %d; got: %d", 2, users.Buckets[0].DocCount)
- }
- if users.Buckets[1].Key != "sandrae" {
- t.Errorf("expected key %q; got: %q", "sandrae", users.Buckets[1].Key)
- }
- if users.Buckets[1].DocCount != 1 {
- t.Errorf("expected doc count %d; got: %d", 1, users.Buckets[1].DocCount)
- }
-
- // Access sub-aggregation
- ts, found := users.Buckets[0].DateHistogram("ts")
- if !found {
- t.Fatalf("expected ts aggregation to be found; got: %v", found)
- }
- if ts == nil {
- t.Fatalf("expected ts aggregation; got: %v", ts)
- }
- if ts.Buckets == nil {
- t.Fatalf("expected ts buckets; got: %v", ts.Buckets)
- }
- if len(ts.Buckets) != 1 {
- t.Errorf("expected %d bucket entries; got: %d", 1, len(ts.Buckets))
- }
- if ts.Buckets[0].Key != 1325376000000 {
- t.Errorf("expected key %v; got: %v", 1325376000000, ts.Buckets[0].Key)
- }
- if ts.Buckets[0].KeyAsString == nil {
- t.Fatalf("expected key_as_string != %v; got: %v", nil, ts.Buckets[0].KeyAsString)
- }
- if *ts.Buckets[0].KeyAsString != "2012-01-01T00:00:00.000Z" {
- t.Errorf("expected key_as_string %q; got: %q", "2012-01-01T00:00:00.000Z", *ts.Buckets[0].KeyAsString)
- }
-}
-
-/*
-// TestAggsRawMessage is a test for issue #51 (https://github.com/olivere/elastic/issues/51).
-// See also: http://play.golang.org/p/b8fzGMxrMC
-func TestAggsRawMessage(t *testing.T) {
- f := json.RawMessage([]byte(`42`))
- m := Aggregations(map[string]*json.RawMessage{
- "k": &f,
- })
- b, _ := json.Marshal(m)
- if string(b) != `{"k":42}` {
- t.Errorf("expected %s; got: %s", `{"k":42}`, string(b))
- }
-}
-*/
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_tophits_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_tophits_test.go
deleted file mode 100644
index 474b11ec84..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_tophits_test.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTopHitsAggregation(t *testing.T) {
- fsc := NewFetchSourceContext(true).Include("title")
- agg := NewTopHitsAggregation().
- Sort("last_activity_date", false).
- FetchSourceContext(fsc).
- Size(1)
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"top_hits":{"_source":{"excludes":[],"includes":["title"]},"size":1,"sort":[{"last_activity_date":{"order":"desc"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_value_count_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_value_count_test.go
deleted file mode 100644
index 247b5f577e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_aggs_value_count_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestValueCountAggregation(t *testing.T) {
- agg := NewValueCountAggregation().Field("grade")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"value_count":{"field":"grade"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestValueCountAggregationWithFormat(t *testing.T) {
- // Format comes with 1.5.0+
- agg := NewValueCountAggregation().Field("grade").Format("0000.0")
- data, err := json.Marshal(agg.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"value_count":{"field":"grade","format":"0000.0"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_date_histogram_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_date_histogram_test.go
deleted file mode 100644
index a9ff716496..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_date_histogram_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestDateHistogramFacetWithField(t *testing.T) {
- f := NewDateHistogramFacet().Field("field_name").Interval("day")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_histogram":{"field":"field_name","interval":"day"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateHistogramFacetWithValueField(t *testing.T) {
- f := NewDateHistogramFacet().
- KeyField("timestamp").
- ValueField("price").
- Interval("day")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_histogram":{"interval":"day","key_field":"timestamp","value_field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestDateHistogramFacetWithGlobals(t *testing.T) {
- f := NewDateHistogramFacet().
- KeyField("timestamp").
- ValueField("price").
- Interval("day").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"date_histogram":{"interval":"day","key_field":"timestamp","value_field":"price"},"facet_filter":{"term":{"user":"kimchy"}},"global":true}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_filter_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_filter_test.go
deleted file mode 100644
index 9566b84e48..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_filter_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFilterFacet(t *testing.T) {
- f := NewFilterFacet().Filter(NewTermFilter("tag", "wow"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"filter":{"term":{"tag":"wow"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFilterFacetWithGlobals(t *testing.T) {
- f := NewFilterFacet().Filter(NewTermFilter("tag", "wow")).
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"filter":{"term":{"tag":"wow"}},"global":true}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_geo_distance_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_geo_distance_test.go
deleted file mode 100644
index 65efa6678c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_geo_distance_test.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoDistanceFacet(t *testing.T) {
- f := NewGeoDistanceFacet().Field("pin.location").
- Point(40, -70).
- AddUnboundedFrom(10).
- AddRange(10, 20).
- AddRange(20, 100).
- AddUnboundedTo(100)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"pin.location":[40,-70],"ranges":[{"to":10},{"from":10,"to":20},{"from":20,"to":100},{"from":100}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceFacetWithGlobals(t *testing.T) {
- f := NewGeoDistanceFacet().Field("pin.location").
- Point(40, -70).
- AddUnboundedFrom(10).
- AddRange(10, 20).
- AddRange(20, 100).
- AddUnboundedTo(100).
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"geo_distance":{"pin.location":[40,-70],"ranges":[{"to":10},{"from":10,"to":20},{"from":20,"to":100},{"from":100}]},"global":true}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_script_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_script_test.go
deleted file mode 100644
index a354205ae0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_script_test.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHistogramScriptFacetWithKeyScripts(t *testing.T) {
- f := NewHistogramScriptFacet().
- KeyScript("doc['date'].date.minuteOfHour").
- ValueScript("doc['num1'].value")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"histogram":{"key_script":"doc['date'].date.minuteOfHour","value_script":"doc['num1'].value"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHistogramScriptFacetWithParams(t *testing.T) {
- f := NewHistogramScriptFacet().
- KeyScript("doc['date'].date.minuteOfHour * factor1").
- ValueScript("doc['num1'].value * factor2").
- Param("factor1", 2).
- Param("factor2", 3)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"histogram":{"key_script":"doc['date'].date.minuteOfHour * factor1","params":{"factor1":2,"factor2":3},"value_script":"doc['num1'].value * factor2"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHistogramScriptFacetWithGlobals(t *testing.T) {
- f := NewHistogramScriptFacet().
- KeyScript("doc['date'].date.minuteOfHour").
- ValueScript("doc['num1'].value").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"histogram":{"key_script":"doc['date'].date.minuteOfHour","value_script":"doc['num1'].value"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_test.go
deleted file mode 100644
index 5645b661e7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_histogram_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHistogramFacetWithField(t *testing.T) {
- f := NewHistogramFacet().Field("field_name").Interval(100)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"histogram":{"field":"field_name","interval":100}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHistogramFacetWithValueField(t *testing.T) {
- f := NewHistogramFacet().
- KeyField("timestamp").
- ValueField("price").
- TimeInterval("1.5d")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"histogram":{"key_field":"timestamp","time_interval":"1.5d","value_field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHistogramFacetWithGlobals(t *testing.T) {
- f := NewHistogramFacet().
- KeyField("timestamp").
- ValueField("price").
- Interval(1000).
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"histogram":{"interval":1000,"key_field":"timestamp","value_field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_query_test.go
deleted file mode 100644
index d5d9348ccc..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_query_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestQueryFacet(t *testing.T) {
- f := NewQueryFacet().Query(NewTermQuery("tag", "wow"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query":{"term":{"tag":"wow"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestQueryFacetWithGlobals(t *testing.T) {
- f := NewQueryFacet().Query(NewTermQuery("tag", "wow")).
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"query":{"term":{"tag":"wow"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_range_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_range_test.go
deleted file mode 100644
index 042393ceda..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_range_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRangeFacet(t *testing.T) {
- f := NewRangeFacet().Field("field_name").
- AddUnboundedFrom(50).
- AddRange(20, 70).
- AddRange(70, 120).
- AddUnboundedTo(150)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeFacetWithLtAndCo(t *testing.T) {
- f := NewRangeFacet().Field("field_name").
- Lt(50).
- Between(20, 70).
- Between(70, 120).
- Gt(150)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"field":"field_name","ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeFacetWithGlobals(t *testing.T) {
- f := NewRangeFacet().Field("field_name").
- AddUnboundedFrom(50).
- AddRange(20, 70).
- AddRange(70, 120).
- AddUnboundedTo(150).
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"range":{"field":"field_name","ranges":[{"to":50},{"from":20,"to":70},{"from":70,"to":120},{"from":150}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_script_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_script_test.go
deleted file mode 100644
index c1b5c9b62b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_script_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestStatisticalScriptFacet(t *testing.T) {
- f := NewStatisticalScriptFacet().Script("doc['num1'].value + doc['num2'].value")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"statistical":{"script":"doc['num1'].value + doc['num2'].value"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestStatisticalScriptFacetWithGlobals(t *testing.T) {
- f := NewStatisticalScriptFacet().Script("doc['num1'].value + doc['num2'].value").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"statistical":{"script":"doc['num1'].value + doc['num2'].value"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_test.go
deleted file mode 100644
index 2ef10ed38f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_statistical_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestStatisticalFacet(t *testing.T) {
- f := NewStatisticalFacet().Field("num1")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"statistical":{"field":"num1"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestStatisticalFacetWithGlobals(t *testing.T) {
- f := NewStatisticalFacet().Field("num1").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"statistical":{"field":"num1"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_stats_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_stats_test.go
deleted file mode 100644
index 0395592a3a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_stats_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermsStatsFacet(t *testing.T) {
- f := NewTermsStatsFacet().KeyField("tag").ValueField("price")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms_stats":{"key_field":"tag","value_field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermsStatsFacetWithGlobals(t *testing.T) {
- f := NewTermsStatsFacet().KeyField("tag").ValueField("price").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"terms_stats":{"key_field":"tag","value_field":"price"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_test.go
deleted file mode 100644
index aaddbe7a39..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_terms_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermsFacet(t *testing.T) {
- f := NewTermsFacet().Field("tag").Size(10).Order("term")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms":{"field":"tag","order":"term","size":10}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermsFacetWithGlobals(t *testing.T) {
- f := NewTermsFacet().Field("tag").Size(10).Order("term").
- Global(true).
- FacetFilter(NewTermFilter("user", "kimchy"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"facet_filter":{"term":{"user":"kimchy"}},"global":true,"terms":{"field":"tag","order":"term","size":10}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_test.go
deleted file mode 100644
index f102158430..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_facets_test.go
+++ /dev/null
@@ -1,533 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- _ "encoding/json"
- _ "net/http"
- "testing"
- "time"
-)
-
-func TestSearchFacets(t *testing.T) {
- client := setupTestClientAndCreateIndex(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))
-
- tweet1 := tweet{
- User: "olivere",
- Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere",
- Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae",
- Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
-
- // Terms Facet by user name
- userFacet := NewTermsFacet().Field("user").Size(10).Order("count")
-
- // Terms Facet with numerical key
- retweetsNumFacet := NewTermsFacet().Field("retweets")
-
- // Range Facet by retweets
- retweetsFacet := NewRangeFacet().Field("retweets").Lt(10).Between(10, 100).Gt(100)
-
- // Histogram Facet by retweets
- retweetsHistoFacet := NewHistogramFacet().KeyField("retweets").Interval(100)
-
- // Histogram Facet with time interval by retweets
- retweetsTimeHistoFacet := NewHistogramFacet().KeyField("retweets").TimeInterval("1m")
-
- // Date Histogram Facet by creation date
- dateHisto := NewDateHistogramFacet().Field("created").Interval("year")
-
- // Date Histogram Facet with Key and Value field by creation date
- dateHistoWithKeyValue := NewDateHistogramFacet().
- Interval("year").
- KeyField("created").
- ValueField("retweets")
-
- // Query Facet
- queryFacet := NewQueryFacet().Query(NewTermQuery("user", "olivere")).Global(true)
-
- // Range Facet by creation date
- dateRangeFacet := NewRangeFacet().Field("created").Lt("2012-01-01").Between("2012-01-01", "2013-01-01").Gt("2013-01-01")
-
- // Range Facet with time.Time by creation date
- d20120101 := time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC)
- d20130101 := time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC)
- dateRangeWithTimeFacet := NewRangeFacet().Field("created").
- Lt(d20120101).
- Between(d20120101, d20130101).
- Gt(d20130101)
-
- // Terms Stats Facet
- termsStatsFacet := NewTermsStatsFacet().KeyField("user").ValueField("retweets")
-
- // Run query
- searchResult, err := client.Search().Index(testIndexName).
- Query(&all).
- Facet("user", userFacet).
- Facet("retweetsNum", retweetsNumFacet).
- Facet("retweets", retweetsFacet).
- Facet("retweetsHistogram", retweetsHistoFacet).
- Facet("retweetsTimeHisto", retweetsTimeHistoFacet).
- Facet("dateHisto", dateHisto).
- Facet("createdWithKeyValue", dateHistoWithKeyValue).
- Facet("queryFacet", queryFacet).
- Facet("dateRangeFacet", dateRangeFacet).
- Facet("dateRangeWithTimeFacet", dateRangeWithTimeFacet).
- Facet("termsStatsFacet", termsStatsFacet).
- Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
- if searchResult.Facets == nil {
- t.Errorf("expected SearchResult.Facets != nil; got nil")
- }
-
- // Search for non-existent facet field should return (nil, false)
- facet, found := searchResult.Facets["no-such-field"]
- if found {
- t.Errorf("expected SearchResult.Facets.For(...) = %v; got %v", false, found)
- }
- if facet != nil {
- t.Errorf("expected SearchResult.Facets.For(...) = nil; got %v", facet)
- }
-
- // Search for existent facet should return (facet, true)
- facet, found = searchResult.Facets["user"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"user\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"user\"] != nil; got nil")
- }
-
- // Check facet details
- if facet.Type != "terms" {
- t.Errorf("expected searchResult.Facets[\"user\"].Type = %v; got %v", "terms", facet.Type)
- }
- if facet.Total != 3 {
- t.Errorf("expected searchResult.Facets[\"user\"].Total = %v; got %v", 3, facet.Total)
- }
- if len(facet.Terms) != 2 {
- t.Errorf("expected len(searchResult.Facets[\"user\"].Terms) = %v; got %v", 2, len(facet.Terms))
- }
-
- // Search for retweetsNum facet
- facet, found = searchResult.Facets["retweetsNum"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"retweetsNum\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"retweetsNum\"] != nil; got nil")
- }
- if facet.Type != "terms" {
- t.Errorf("expected searchResult.Facets[\"retweetsNum\"].Type = %v; got %v", "terms", facet.Type)
- }
- if facet.Total != 3 {
- t.Errorf("expected searchResult.Facets[\"retweetsNum\"].Total = %v; got %v", 3, facet.Total)
- }
- if len(facet.Terms) != 3 {
- t.Errorf("expected len(searchResult.Facets[\"retweetsNum\"].Terms) = %v; got %v", 2, len(facet.Terms))
- }
-
- // Search for range facet should return (facet, true)
- facet, found = searchResult.Facets["retweets"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"retweets\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"retweets\"] != nil; got nil")
- }
-
- // Check facet details
- if facet.Type != "range" {
- t.Errorf("expected searchResult.Facets[\"retweets\"].Type = %v; got %v", "range", facet.Type)
- }
- if len(facet.Ranges) != 3 {
- t.Errorf("expected len(searchResult.Facets[\"retweets\"].Ranges) = %v; got %v", 3, len(facet.Ranges))
- }
-
- if facet.Ranges[0].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][0].Count = %v; got %v", 1, facet.Ranges[0].Count)
- }
- if facet.Ranges[0].TotalCount != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][0].TotalCount = %v; got %v", 1, facet.Ranges[0].TotalCount)
- }
- if facet.Ranges[0].From != nil {
- t.Errorf("expected searchResult.Facets[\"retweets\"][0].From = %v; got %v", nil, facet.Ranges[0].From)
- }
- if to := facet.Ranges[0].To; to == nil || (*to) != 10.0 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][0].To = %v; got %v", 10.0, to)
- }
-
- if facet.Ranges[1].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][1].Count = %v; got %v", 1, facet.Ranges[1].Count)
- }
- if facet.Ranges[1].TotalCount != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][1].TotalCount = %v; got %v", 1, facet.Ranges[1].TotalCount)
- }
- if from := facet.Ranges[1].From; from == nil || (*from) != 10.0 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][1].From = %v; got %v", 10.0, from)
- }
- if to := facet.Ranges[1].To; to == nil || (*to) != 100.0 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][1].To = %v; got %v", 100.0, facet.Ranges[1].To)
- }
-
- if facet.Ranges[2].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][2].Count = %v; got %v", 1, facet.Ranges[2].Count)
- }
- if facet.Ranges[2].TotalCount != 1 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][2].TotalCount = %v; got %v", 1, facet.Ranges[2].TotalCount)
- }
- if from := facet.Ranges[2].From; from == nil || (*from) != 100.0 {
- t.Errorf("expected searchResult.Facets[\"retweets\"][2].From = %v; got %v", 100.0, facet.Ranges[2].From)
- }
- if facet.Ranges[2].To != nil {
- t.Errorf("expected searchResult.Facets[\"retweets\"][2].To = %v; got %v", nil, facet.Ranges[2].To)
- }
-
- // Search for histogram facet should return (facet, true)
- facet, found = searchResult.Facets["retweetsHistogram"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"] != nil; got nil")
- }
-
- // Check facet details
- if facet.Type != "histogram" {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"].Type = %v; got %v", "histogram", facet.Type)
- }
- if len(facet.Entries) != 2 {
- t.Errorf("expected len(searchResult.Facets[\"retweetsHistogram\"].Entries) = %v; got %v", 3, len(facet.Entries))
- }
- if facet.Entries[0].Key.(float64) != 0 {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"].Entries[0].Key = %v; got %v", 0, facet.Entries[0].Key)
- }
- if facet.Entries[0].Count != 2 {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"].Entries[0].Count = %v; got %v", 2, facet.Entries[0].Count)
- }
- if facet.Entries[1].Key.(float64) != 100 {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"].Entries[1].Key = %v; got %v", 100, facet.Entries[1].Key)
- }
- if facet.Entries[1].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"retweetsHistogram\"].Entries[1].Count = %v; got %v", 1, facet.Entries[1].Count)
- }
-
- // Search for histogram facet with time interval should return (facet, true)
- facet, found = searchResult.Facets["retweetsTimeHisto"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"retweetsTimeHisto\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"retweetsTimeHisto\"] != nil; got nil")
- }
-
- // Search for date histogram facet
- facet, found = searchResult.Facets["dateHisto"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"] != nil; got nil")
- }
- if facet.Entries[0].Time != 1293840000000 {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"].Entries[0].Time = %v; got %v", 1293840000000, facet.Entries[0].Time)
- }
- if facet.Entries[0].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"].Entries[0].Count = %v; got %v", 1, facet.Entries[0].Count)
- }
- if facet.Entries[1].Time != 1325376000000 {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"].Entries[1].Time = %v; got %v", 1325376000000, facet.Entries[0].Time)
- }
- if facet.Entries[1].Count != 2 {
- t.Errorf("expected searchResult.Facets[\"dateHisto\"].Entries[1].Count = %v; got %v", 2, facet.Entries[1].Count)
- }
-
- // Search for date histogram with key/value fields facet
- facet, found = searchResult.Facets["createdWithKeyValue"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"] != nil; got nil")
- }
- if len(facet.Entries) != 2 {
- t.Errorf("expected len(searchResult.Facets[\"createdWithKeyValue\"].Entries) = %v; got %v", 2, len(facet.Entries))
- }
- if facet.Entries[0].Time != 1293840000000 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Time = %v; got %v", 1293840000000, facet.Entries[0].Time)
- }
- if facet.Entries[0].Count != 1 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Count = %v; got %v", 1, facet.Entries[0].Count)
- }
- if facet.Entries[0].Min.(float64) != 12.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Min = %v; got %v", 12.0, facet.Entries[0].Min)
- }
- if facet.Entries[0].Max.(float64) != 12.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Max = %v; got %v", 12.0, facet.Entries[0].Max)
- }
- if facet.Entries[0].Total != 12.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Total = %v; got %v", 12.0, facet.Entries[0].Total)
- }
- if facet.Entries[0].TotalCount != 1 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].TotalCount = %v; got %v", 1, facet.Entries[0].TotalCount)
- }
- if facet.Entries[0].Mean != 12.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[0].Mean = %v; got %v", 12.0, facet.Entries[0].Mean)
- }
- if facet.Entries[1].Time != 1325376000000 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Time = %v; got %v", 1325376000000, facet.Entries[1].Time)
- }
- if facet.Entries[1].Count != 2 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Count = %v; got %v", 2, facet.Entries[1].Count)
- }
- if facet.Entries[1].Min.(float64) != 0.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Min = %v; got %v", 0.0, facet.Entries[1].Min)
- }
- if facet.Entries[1].Max.(float64) != 108.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Max = %v; got %v", 108.0, facet.Entries[1].Max)
- }
- if facet.Entries[1].Total != 108.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Total = %v; got %v", 108.0, facet.Entries[1].Total)
- }
- if facet.Entries[1].TotalCount != 2 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].TotalCount = %v; got %v", 2, facet.Entries[1].TotalCount)
- }
- if facet.Entries[1].Mean != 54.0 {
- t.Errorf("expected searchResult.Facets[\"createdWithKeyValue\"].Entries[1].Mean = %v; got %v", 54.0, facet.Entries[1].Mean)
- }
-
- // Search for date range facet
- facet, found = searchResult.Facets["dateRangeFacet"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"] != nil; got nil")
- }
- if len(facet.Ranges) != 3 {
- t.Errorf("expected len(searchResult.Facets[\"dateRangeFacet\"].Ranges) = %v; got %v", 3, len(facet.Ranges))
- }
- if facet.Ranges[0].From != nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[0].From to be nil")
- }
- if facet.Ranges[0].To == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[0].To to be != nil")
- }
- if *facet.Ranges[0].To != 1.325376e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[0].To = %v; got %v", 1.325376e+12, *facet.Ranges[0].To)
- }
- if facet.Ranges[0].ToStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[0].ToStr to be != nil")
- }
- if *facet.Ranges[0].ToStr != "2012-01-01" {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[0].ToStr = %v; got %v", "2012-01-01", *facet.Ranges[0].ToStr)
- }
- if facet.Ranges[1].From == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].From to be != nil")
- }
- if *facet.Ranges[1].From != 1.325376e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].From = %v; got %v", 1.325376e+12, *facet.Ranges[1].From)
- }
- if facet.Ranges[1].FromStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].FromStr to be != nil")
- }
- if *facet.Ranges[1].FromStr != "2012-01-01" {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].FromStr = %v; got %v", "2012-01-01", *facet.Ranges[1].FromStr)
- }
- if facet.Ranges[1].To == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].To to be != nil")
- }
- if *facet.Ranges[1].To != 1.3569984e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].To = %v; got %v", 1.3569984e+12, *facet.Ranges[1].To)
- }
- if facet.Ranges[1].ToStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].ToStr to be != nil")
- }
- if *facet.Ranges[1].ToStr != "2013-01-01" {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[1].ToStr = %v; got %v", "2013-01-01", *facet.Ranges[1].ToStr)
- }
- if facet.Ranges[2].To != nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[2].To to be nil")
- }
- if facet.Ranges[2].From == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[2].From to be != nil")
- }
- if *facet.Ranges[2].From != 1.3569984e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[2].From = %v; got %v", 1.3569984e+12, *facet.Ranges[2].From)
- }
- if facet.Ranges[2].FromStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[2].FromStr to be != nil")
- }
- if *facet.Ranges[2].FromStr != "2013-01-01" {
- t.Errorf("expected searchResult.Facets[\"dateRangeFacet\"].Ranges[2].FromStr = %v; got %v", "2013-01-01", *facet.Ranges[2].FromStr)
- }
-
- // Search for date range facet
- facet, found = searchResult.Facets["dateRangeWithTimeFacet"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"] != nil; got nil")
- }
- if len(facet.Ranges) != 3 {
- t.Errorf("expected len(searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges) = %v; got %v", 3, len(facet.Ranges))
- }
- if facet.Ranges[0].From != nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[0].From to be nil")
- }
- if facet.Ranges[0].To == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[0].To to be != nil")
- }
- if *facet.Ranges[0].To != 1.325376e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[0].To = %v; got %v", 1.325376e+12, *facet.Ranges[0].To)
- }
- if facet.Ranges[0].ToStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[0].ToStr to be != nil")
- }
- if *facet.Ranges[0].ToStr != "2012-01-01T00:00:00Z" {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[0].ToStr = %v; got %v", "2012-01-01T00:00:00Z", *facet.Ranges[0].ToStr)
- }
- if facet.Ranges[1].From == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].From to be != nil")
- }
- if *facet.Ranges[1].From != 1.325376e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].From = %v; got %v", 1.325376e+12, *facet.Ranges[1].From)
- }
- if facet.Ranges[1].FromStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].FromStr to be != nil")
- }
- if *facet.Ranges[1].FromStr != "2012-01-01T00:00:00Z" {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].FromStr = %v; got %v", "2012-01-01T00:00:00Z", *facet.Ranges[1].FromStr)
- }
- if facet.Ranges[1].To == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].To to be != nil")
- }
- if *facet.Ranges[1].To != 1.3569984e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].To = %v; got %v", 1.3569984e+12, *facet.Ranges[1].To)
- }
- if facet.Ranges[1].ToStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].ToStr to be != nil")
- }
- if *facet.Ranges[1].ToStr != "2013-01-01T00:00:00Z" {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[1].ToStr = %v; got %v", "2013-01-01T00:00:00Z", *facet.Ranges[1].ToStr)
- }
- if facet.Ranges[2].To != nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[2].To to be nil")
- }
- if facet.Ranges[2].From == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[2].From to be != nil")
- }
- if *facet.Ranges[2].From != 1.3569984e+12 {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[2].From = %v; got %v", 1.3569984e+12, *facet.Ranges[2].From)
- }
- if facet.Ranges[2].FromStr == nil {
- t.Fatalf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[2].FromStr to be != nil")
- }
- if *facet.Ranges[2].FromStr != "2013-01-01T00:00:00Z" {
- t.Errorf("expected searchResult.Facets[\"dateRangeWithTimeFacet\"].Ranges[2].FromStr = %v; got %v", "2013-01-01T00:00:00Z", *facet.Ranges[2].FromStr)
- }
-
- // Search for terms_stats facet
- facet, found = searchResult.Facets["termsStatsFacet"]
- if !found {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"] = %v; got %v", true, found)
- }
- if facet == nil {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"] != nil; got nil")
- }
-
- // Check facet details
- if got, want := facet.Type, "terms_stats"; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Type = %v; got %v", want, got)
- }
- if got, want := len(facet.Terms), 2; got != want {
- t.Errorf("expected len(searchResult.Facets[\"termsStatsFacet\"].Terms) = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].Term, "olivere"; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].Term = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].Count, 2; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].Count = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].TotalCount, 2; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].TotalCount = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].Min, 0.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].Min = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].Max, 108.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].Max = %v; got %v", want, got)
- }
- if got, want := facet.Terms[0].Mean, 54.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[0].Mean = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].Term, "sandrae"; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].Term = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].Count, 1; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].Count = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].TotalCount, 1; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].TotalCount = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].Min, 12.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].Min = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].Max, 12.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].Max = %v; got %v", want, got)
- }
- if got, want := facet.Terms[1].Mean, 12.0; got != want {
- t.Errorf("expected searchResult.Facets[\"termsStatsFacet\"].Terms[1].Mean = %v; got %v", want, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_and_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_and_test.go
deleted file mode 100644
index c1fb346729..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_and_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestAndFilter(t *testing.T) {
- f := NewAndFilter()
- postDateFilter := NewRangeFilter("postDate").From("2010-03-01").To("2010-04-01")
- f = f.Add(postDateFilter)
- prefixFilter := NewPrefixFilter("name.second", "ba")
- f = f.Add(prefixFilter)
- f = f.Cache(true)
- f = f.CacheKey("MyAndFilter")
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"and":{"_cache":true,"_cache_key":"MyAndFilter","_name":"MyFilterName","filters":[{"range":{"postDate":{"from":"2010-03-01","include_lower":true,"include_upper":true,"to":"2010-04-01"}}},{"prefix":{"name.second":"ba"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNewAndFilter1(t *testing.T) {
- f := NewAndFilter(NewTermFilter("user", "olivere"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"and":{"filters":[{"term":{"user":"olivere"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNewAndFilter2(t *testing.T) {
- tf := NewTermsFilter("user", "oliver", "test")
- mf := NewMissingFilter("user")
- f := NewAndFilter(tf, mf)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"and":{"filters":[{"terms":{"user":["oliver","test"]}},{"missing":{"field":"user"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_bool_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_bool_test.go
deleted file mode 100644
index 089dfd83d7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_bool_test.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestBoolFilter(t *testing.T) {
- f := NewBoolFilter()
- f = f.Must(NewTermFilter("tag", "wow"))
- f = f.MustNot(NewRangeFilter("age").From(10).To(20))
- f = f.Should(NewTermFilter("tag", "sometag"), NewTermFilter("tag", "sometagtag"))
- f = f.Cache(true)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"bool":{"_cache":true,"must":{"term":{"tag":"wow"}},"must_not":{"range":{"age":{"from":10,"include_lower":true,"include_upper":true,"to":20}}},"should":[{"term":{"tag":"sometag"}},{"term":{"tag":"sometagtag"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_exists_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_exists_test.go
deleted file mode 100644
index 8931ec3908..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_exists_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestExistsFilter(t *testing.T) {
- f := NewExistsFilter("user").FilterName("_my_filter")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"exists":{"_name":"_my_filter","field":"user"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_distance_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_distance_test.go
deleted file mode 100644
index 3eca10960a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_distance_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoDistanceFilter(t *testing.T) {
- f := NewGeoDistanceFilter("pin.location")
- f = f.Lat(40)
- f = f.Lon(-70)
- f = f.Distance("200km")
- f = f.DistanceType("plane")
- f = f.OptimizeBbox("memory")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"distance":"200km","distance_type":"plane","optimize_bbox":"memory","pin.location":{"lat":40,"lon":-70}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceFilterWithGeoPoint(t *testing.T) {
- f := NewGeoDistanceFilter("pin.location")
- f = f.GeoPoint(GeoPointFromLatLon(40, -70))
- f = f.Distance("200km")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"distance":"200km","pin.location":{"lat":40,"lon":-70}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceFilterWithGeoHash(t *testing.T) {
- f := NewGeoDistanceFilter("pin.location")
- f = f.GeoHash("drm3btev3e86")
- f = f.Distance("12km")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_distance":{"distance":"12km","pin.location":"drm3btev3e86"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_polygon_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_polygon_test.go
deleted file mode 100644
index c33a02f208..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_geo_polygon_test.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestGeoPolygonFilter(t *testing.T) {
- f := NewGeoPolygonFilter("person.location")
- f = f.AddPoint(&GeoPoint{Lat: 40, Lon: -70})
- f = f.AddPoint(GeoPointFromLatLon(30, -80))
- point, err := GeoPointFromString("20,-90")
- if err != nil {
- t.Fatalf("GeoPointFromString failed: %v", err)
- }
- f = f.AddPoint(point)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"geo_polygon":{"person.location":{"points":[{"lat":40,"lon":-70},{"lat":30,"lon":-80},{"lat":20,"lon":-90}]}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_child_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_child_test.go
deleted file mode 100644
index 34b55fda1b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_child_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHasChildFilter(t *testing.T) {
- f := NewHasChildFilter("blog_tag")
- f = f.Query(NewTermQuery("tag", "something"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasChildFilterWithInnerHits(t *testing.T) {
- f := NewHasChildFilter("blog_tag")
- f = f.Query(NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit())
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"inner_hits":{},"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasChildFilterWithInnerHitsName(t *testing.T) {
- f := NewHasChildFilter("blog_tag")
- f = f.Query(NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit().Name("comments"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"inner_hits":{"name":"comments"},"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasChildFilterWithInnerHitsQuery(t *testing.T) {
- f := NewHasChildFilter("blog_tag")
- f = f.Query(NewTermQuery("tag", "something"))
- hit := NewInnerHit().Query(NewTermQuery("user", "olivere"))
- f = f.InnerHit(hit)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"inner_hits":{"query":{"term":{"user":"olivere"}}},"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_parent_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_parent_test.go
deleted file mode 100644
index 3f59f91d72..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_has_parent_test.go
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHasParentFilter(t *testing.T) {
- f := NewHasParentFilter("blog")
- f = f.Query(NewTermQuery("tag", "something"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_parent":{"parent_type":"blog","query":{"term":{"tag":"something"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasParentFilterWithInnerHits(t *testing.T) {
- f := NewHasParentFilter("blog")
- f = f.Query(NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit())
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_parent":{"inner_hits":{},"parent_type":"blog","query":{"term":{"tag":"something"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasParentFilterWithInnerHitsName(t *testing.T) {
- f := NewHasParentFilter("blog")
- f = f.Query(NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit().Name("comments"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_parent":{"inner_hits":{"name":"comments"},"parent_type":"blog","query":{"term":{"tag":"something"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasParentFilterWithInnerHitsQuery(t *testing.T) {
- f := NewHasParentFilter("blog")
- f = f.Query(NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit().Query(NewTermQuery("user", "olivere")))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_parent":{"inner_hits":{"query":{"term":{"user":"olivere"}}},"parent_type":"blog","query":{"term":{"tag":"something"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_ids_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_ids_test.go
deleted file mode 100644
index 2e0837a010..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_ids_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestIdsFilter(t *testing.T) {
- f := NewIdsFilter("my_type").Ids("1", "4", "100")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"ids":{"type":"my_type","values":["1","4","100"]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_limit_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_limit_test.go
deleted file mode 100644
index d7ca265a04..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_limit_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestLimitFilter(t *testing.T) {
- f := NewLimitFilter(42)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"limit":{"value":42}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_match_all_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_match_all_test.go
deleted file mode 100644
index 0ce39a6c3c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_match_all_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMatchAllFilter(t *testing.T) {
- f := NewMatchAllFilter()
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match_all":{}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_missing_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_missing_test.go
deleted file mode 100644
index 88b4dc59bd..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_missing_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMissingFilter(t *testing.T) {
- f := NewMissingFilter("user").FilterName("_my_filter")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"missing":{"_name":"_my_filter","field":"user"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_nested_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_nested_test.go
deleted file mode 100644
index 8e0cec64ad..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_nested_test.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestNestedFilter(t *testing.T) {
- f := NewNestedFilter("obj1")
- bq := NewBoolQuery()
- bq = bq.Must(NewTermQuery("obj1.name", "blue"))
- bq = bq.Must(NewRangeQuery("obj1.count").Gt(5))
- f = f.Query(bq)
- f = f.Cache(true)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"nested":{"_cache":true,"path":"obj1","query":{"bool":{"must":[{"term":{"obj1.name":"blue"}},{"range":{"obj1.count":{"from":5,"include_lower":false,"include_upper":true,"to":null}}}]}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNestedFilterWithInnerHit(t *testing.T) {
- f := NewNestedFilter("obj1")
- bq := NewBoolQuery()
- bq = bq.Must(NewTermQuery("obj1.name", "blue"))
- bq = bq.Must(NewRangeQuery("obj1.count").Gt(5))
- f = f.Query(bq)
- f = f.Cache(true)
- f = f.InnerHit(NewInnerHit().Name("comments").Query(NewTermQuery("user", "olivere")))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"nested":{"_cache":true,"inner_hits":{"name":"comments","query":{"term":{"user":"olivere"}}},"path":"obj1","query":{"bool":{"must":[{"term":{"obj1.name":"blue"}},{"range":{"obj1.count":{"from":5,"include_lower":false,"include_upper":true,"to":null}}}]}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_not_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_not_test.go
deleted file mode 100644
index 76699110ca..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_not_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestNotFilter(t *testing.T) {
- f := NewNotFilter(NewTermFilter("user", "olivere"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"not":{"filter":{"term":{"user":"olivere"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNotFilterWithParams(t *testing.T) {
- postDateFilter := NewRangeFilter("postDate").From("2010-03-01").To("2010-04-01")
- f := NewNotFilter(postDateFilter)
- f = f.Cache(true)
- f = f.CacheKey("MyNotFilter")
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"not":{"_cache":true,"_cache_key":"MyNotFilter","_name":"MyFilterName","filter":{"range":{"postDate":{"from":"2010-03-01","include_lower":true,"include_upper":true,"to":"2010-04-01"}}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_or_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_or_test.go
deleted file mode 100644
index 4d86007f95..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_or_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestOrFilter(t *testing.T) {
- f := NewOrFilter()
- postDateFilter := NewRangeFilter("postDate").From("2010-03-01").To("2010-04-01")
- f = f.Add(postDateFilter)
- prefixFilter := NewPrefixFilter("name.second", "ba")
- f = f.Add(prefixFilter)
- f = f.Cache(true)
- f = f.CacheKey("MyOrFilter")
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"or":{"_cache":true,"_cache_key":"MyOrFilter","_name":"MyFilterName","filters":[{"range":{"postDate":{"from":"2010-03-01","include_lower":true,"include_upper":true,"to":"2010-04-01"}}},{"prefix":{"name.second":"ba"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNewOrFilter(t *testing.T) {
- tf := NewTermsFilter("user", "oliver", "test")
- mf := NewMissingFilter("user")
- f := NewOrFilter(tf, mf)
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"or":{"filters":[{"terms":{"user":["oliver","test"]}},{"missing":{"field":"user"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_prefix_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_prefix_test.go
deleted file mode 100644
index 7392572ba7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_prefix_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestPrefixFilter(t *testing.T) {
- f := NewPrefixFilter("user", "ki")
- f = f.Cache(true)
- f = f.CacheKey("MyPrefixFilter")
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"prefix":{"_cache":true,"_cache_key":"MyPrefixFilter","_name":"MyFilterName","user":"ki"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_query_test.go
deleted file mode 100644
index 9dffc455c5..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_query_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestQueryFilter(t *testing.T) {
- f := NewQueryFilter(NewQueryStringQuery("this AND that OR thus"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query":{"query_string":{"query":"this AND that OR thus"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestQueryFilterWithName(t *testing.T) {
- f := NewQueryFilter(NewQueryStringQuery("this AND that OR thus"))
- f = f.Cache(true)
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fquery":{"_cache":true,"_name":"MyFilterName","query":{"query_string":{"query":"this AND that OR thus"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_range_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_range_test.go
deleted file mode 100644
index 70aea53f1e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_range_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRangeFilter(t *testing.T) {
- f := NewRangeFilter("postDate").From("2010-03-01").To("2010-04-01")
- f = f.Cache(true)
- f = f.CacheKey("MyAndFilter")
- f = f.FilterName("MyFilterName")
- f = f.Execution("index")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"_cache":true,"_cache_key":"MyAndFilter","_name":"MyFilterName","execution":"index","postDate":{"from":"2010-03-01","include_lower":true,"include_upper":true,"to":"2010-04-01"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-/*
-func TestRangeFilterGte(t *testing.T) {
- f := NewRangeFilter("postDate").Gte("2010-03-01")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"postDate":{"gte":"2010-03-01"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-*/
-
-func TestRangeFilterWithTimeZone(t *testing.T) {
- f := NewRangeFilter("born").
- Gte("2012-01-01").
- Lte("now").
- TimeZone("+1:00")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"born":{"from":"2012-01-01","include_lower":true,"include_upper":true,"time_zone":"+1:00","to":"now"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeFilterWithFormat(t *testing.T) {
- f := NewRangeFilter("born").
- Gte("2012/01/01").
- Lte("now").
- Format("yyyy/MM/dd")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"born":{"format":"yyyy/MM/dd","from":"2012/01/01","include_lower":true,"include_upper":true,"to":"now"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_regexp_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_regexp_test.go
deleted file mode 100644
index 6498722eb1..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_regexp_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRegexpFilter(t *testing.T) {
- f := NewRegexpFilter("name.first", "s.*y")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"regexp":{"name.first":"s.*y"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRegexpFilterWithFlags(t *testing.T) {
- f := NewRegexpFilter("name.first", "s.*y")
- f = f.Flags("INTERSECTION|COMPLEMENT|EMPTY")
- f = f.FilterName("test").Cache(true).CacheKey("key")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"regexp":{"_cache":true,"_cache_key":"key","_name":"test","name.first":{"flags":"INTERSECTION|COMPLEMENT|EMPTY","value":"s.*y"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_term_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_term_test.go
deleted file mode 100644
index a0975b3f8a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_term_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermFilter(t *testing.T) {
- f := NewTermFilter("user", "ki")
- f = f.Cache(true)
- f = f.CacheKey("MyTermFilter")
- f = f.FilterName("MyFilterName")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"term":{"_cache":true,"_cache_key":"MyTermFilter","_name":"MyFilterName","user":"ki"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_terms_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_terms_test.go
deleted file mode 100644
index 6354084861..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_terms_test.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermsFilter(t *testing.T) {
- f := NewTermsFilter("user", "kimchy", "elasticsearch")
- f = f.Cache(true)
- f = f.CacheKey("MyTermsFilter")
- f = f.FilterName("MyFilterName")
- f = f.Execution("plain")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms":{"_cache":true,"_cache_key":"MyTermsFilter","_name":"MyFilterName","execution":"plain","user":["kimchy","elasticsearch"]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_type_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_type_test.go
deleted file mode 100644
index e172ed77e0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_filters_type_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTypeFilter(t *testing.T) {
- f := NewTypeFilter("my_type")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"type":{"value":"my_type"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_bool_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_bool_test.go
deleted file mode 100644
index 07ecc49cf9..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_bool_test.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestBoolQuery(t *testing.T) {
- q := NewBoolQuery()
- q = q.Must(NewTermQuery("tag", "wow"))
- q = q.MustNot(NewRangeQuery("age").From(10).To(20))
- q = q.Should(NewTermQuery("tag", "sometag"), NewTermQuery("tag", "sometagtag"))
- q = q.Boost(10)
- q = q.DisableCoord(true)
- q = q.QueryName("Test")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"bool":{"_name":"Test","boost":10,"disable_coord":true,"must":{"term":{"tag":"wow"}},"must_not":{"range":{"age":{"from":10,"include_lower":true,"include_upper":true,"to":20}}},"should":[{"term":{"tag":"sometag"}},{"term":{"tag":"sometagtag"}}]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_boosting_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_boosting_test.go
deleted file mode 100644
index 31364dca3a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_boosting_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestBoostingQuery(t *testing.T) {
- q := NewBoostingQuery()
- q = q.Positive(NewTermQuery("tag", "wow"))
- q = q.Negative(NewRangeQuery("age").From(10).To(20))
- q = q.NegativeBoost(0.2)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"boosting":{"negative":{"range":{"age":{"from":10,"include_lower":true,"include_upper":true,"to":20}}},"negative_boost":0.2,"positive":{"term":{"tag":"wow"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_common_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_common_test.go
deleted file mode 100644
index 85270b63ac..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_common_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestSearchQueriesCommon(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Common query
- q := NewCommonQuery("message", "Golang")
- searchResult, err := client.Search().Index(testIndexName).Query(&q).Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 1 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 1, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 1 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 1, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fsq_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fsq_test.go
deleted file mode 100644
index d0c071448f..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fsq_test.go
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFunctionScoreQuery(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- Add(NewTermFilter("name.last", "banon"), NewFactorFunction().BoostFactor(3)).
- AddScoreFunc(NewFactorFunction().BoostFactor(3)).
- AddScoreFunc(NewFactorFunction().BoostFactor(3)).
- Boost(3).
- MaxBoost(10).
- ScoreMode("avg")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"boost":3,"functions":[{"boost_factor":3,"filter":{"term":{"name.last":"banon"}}},{"boost_factor":3},{"boost_factor":3}],"max_boost":10,"query":{"term":{"name.last":"banon"}},"score_mode":"avg"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFunctionScoreQueryWithNilFilter(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("tag", "wow")).
- AddScoreFunc(NewRandomFunction()).
- Boost(2.0).
- MaxBoost(12.0).
- BoostMode("multiply").
- ScoreMode("max")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"boost":2,"boost_mode":"multiply","max_boost":12,"query":{"term":{"tag":"wow"}},"random_score":{},"score_mode":"max"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldValueFactor(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- AddScoreFunc(NewFieldValueFactorFunction().Modifier("sqrt").Factor(2).Field("income")).
- Boost(2.0).
- MaxBoost(12.0).
- BoostMode("multiply").
- ScoreMode("max")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"boost":2,"boost_mode":"multiply","field_value_factor":{"factor":2,"field":"income","modifier":"sqrt"},"max_boost":12,"query":{"term":{"name.last":"banon"}},"score_mode":"max"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldValueFactorWithWeight(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- AddScoreFunc(NewFieldValueFactorFunction().Modifier("sqrt").Factor(2).Field("income").Weight(2.5)).
- Boost(2.0).
- MaxBoost(12.0).
- BoostMode("multiply").
- ScoreMode("max")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"boost":2,"boost_mode":"multiply","field_value_factor":{"factor":2,"field":"income","modifier":"sqrt"},"max_boost":12,"query":{"term":{"name.last":"banon"}},"score_mode":"max","weight":2.5}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldValueFactorWithMultipleScoreFuncsAndWeights(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- AddScoreFunc(NewFieldValueFactorFunction().Modifier("sqrt").Factor(2).Field("income").Weight(2.5)).
- AddScoreFunc(NewScriptFunction("_score * doc['my_numeric_field'].value").Weight(1.25)).
- AddScoreFunc(NewWeightFactorFunction(0.5)).
- Boost(2.0).
- MaxBoost(12.0).
- BoostMode("multiply").
- ScoreMode("max")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"boost":2,"boost_mode":"multiply","functions":[{"field_value_factor":{"factor":2,"field":"income","modifier":"sqrt"},"weight":2.5},{"script_score":{"script":"_score * doc['my_numeric_field'].value"},"weight":1.25},{"weight":0.5}],"max_boost":12,"query":{"term":{"name.last":"banon"}},"score_mode":"max"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFunctionScoreQueryWithGaussScoreFunc(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- AddScoreFunc(NewGaussDecayFunction().FieldName("pin.location").Origin("11, 12").Scale("2km").Offset("0km").Decay(0.33))
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"gauss":{"pin.location":{"decay":0.33,"offset":"0km","origin":"11, 12","scale":"2km"}},"query":{"term":{"name.last":"banon"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFunctionScoreQueryWithGaussScoreFuncAndMultiValueMode(t *testing.T) {
- q := NewFunctionScoreQuery().
- Query(NewTermQuery("name.last", "banon")).
- AddScoreFunc(NewGaussDecayFunction().FieldName("pin.location").Origin("11, 12").Scale("2km").Offset("0km").Decay(0.33).MultiValueMode("avg"))
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"function_score":{"gauss":{"multi_value_mode":"avg","pin.location":{"decay":0.33,"offset":"0km","origin":"11, 12","scale":"2km"}},"query":{"term":{"name.last":"banon"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_field_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_field_query_test.go
deleted file mode 100644
index 20bb1c4f2c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_field_query_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFuzzyLikeThisFieldQuery(t *testing.T) {
- q := NewFuzzyLikeThisFieldQuery("name.first").LikeText("text like this one").MaxQueryTerms(12)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fuzzy_like_this_field":{"name.first":{"like_text":"text like this one","max_query_terms":12}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_query_test.go
deleted file mode 100644
index 42ad1a739e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_like_this_query_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFuzzyLikeThisQuery(t *testing.T) {
- q := NewFuzzyLikeThisQuery().Fields("name.first", "name.last").LikeText("text like this one").MaxQueryTerms(12)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fuzzy_like_this":{"fields":["name.first","name.last"],"like_text":"text like this one","max_query_terms":12}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_test.go
deleted file mode 100644
index 47e4efb5bf..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_fuzzy_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFuzzyQuery(t *testing.T) {
- q := NewFuzzyQuery().Name("user").Value("ki").Boost(1.5).Fuzziness(2).PrefixLength(0).MaxExpansions(100)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fuzzy":{"user":{"boost":1.5,"fuzziness":2,"max_expansions":100,"prefix_length":0,"value":"ki"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_child_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_child_test.go
deleted file mode 100644
index 6c16790b23..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_child_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHasChildQuery(t *testing.T) {
- f := NewHasChildQuery("blog_tag", NewTermQuery("tag", "something"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestHasChildQueryWithInnerHit(t *testing.T) {
- f := NewHasChildQuery("blog_tag", NewTermQuery("tag", "something"))
- f = f.InnerHit(NewInnerHit().Name("comments"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_child":{"inner_hits":{"name":"comments"},"query":{"term":{"tag":"something"}},"type":"blog_tag"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_parent_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_parent_test.go
deleted file mode 100644
index 08619c7502..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_has_parent_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestHasParentQueryTest(t *testing.T) {
- f := NewHasParentQuery("blog", NewTermQuery("tag", "something"))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"has_parent":{"parent_type":"blog","query":{"term":{"tag":"something"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_ids_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_ids_test.go
deleted file mode 100644
index c223c609c3..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_ids_test.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestIdsQuery(t *testing.T) {
- q := NewIdsQuery("my_type").Ids("1", "4", "100").Boost(10.5).QueryName("my_query")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"ids":{"_name":"my_query","boost":10.5,"type":"my_type","values":["1","4","100"]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_all_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_all_test.go
deleted file mode 100644
index 626c91208c..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_all_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMatchAllQuery(t *testing.T) {
- q := NewMatchAllQuery()
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match_all":{}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMatchAllQueryWithParams(t *testing.T) {
- q := NewMatchAllQuery().NormsField("field_name").Boost(3.14)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match_all":{"boost":3.14,"norms_field":"field_name"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_test.go
deleted file mode 100644
index 64ad82dd62..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_match_test.go
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMatchQuery(t *testing.T) {
- q := NewMatchQuery("message", "this is a test")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match":{"message":{"query":"this is a test"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMatchPhraseQuery(t *testing.T) {
- q := NewMatchPhraseQuery("message", "this is a test")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match":{"message":{"query":"this is a test","type":"phrase"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMatchPhrasePrefixQuery(t *testing.T) {
- q := NewMatchPhrasePrefixQuery("message", "this is a test")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match":{"message":{"query":"this is a test","type":"phrase_prefix"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMatchQueryWithOptions(t *testing.T) {
- q := NewMatchQuery("message", "this is a test").Analyzer("whitespace").Operator("or").Boost(2.5)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"match":{"message":{"analyzer":"whitespace","boost":2.5,"operator":"or","query":"this is a test"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_field_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_field_test.go
deleted file mode 100644
index 03f760f129..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_field_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestMoreLikeThisFieldQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another Golang topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Common query
- q := NewMoreLikeThisFieldQuery("message", "Golang topic.")
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&q).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_test.go
deleted file mode 100644
index 074474d87a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_more_like_this_test.go
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMoreLikeThisQuerySourceWithLikeText(t *testing.T) {
- q := NewMoreLikeThisQuery("Golang topic").Field("message")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatal(err)
- }
- got := string(data)
- expected := `{"mlt":{"fields":["message"],"like_text":"Golang topic"}}`
- if got != expected {
- t.Fatalf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMoreLikeThisQuerySourceWithIds(t *testing.T) {
- q := NewMoreLikeThisQuery("")
- q = q.Ids("1", "2")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatal(err)
- }
- got := string(data)
- expected := `{"mlt":{"ids":["1","2"]}}`
- if got != expected {
- t.Fatalf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMoreLikeThisQuerySourceWithDocs(t *testing.T) {
- q := NewMoreLikeThisQuery("")
- q = q.Docs(
- NewMoreLikeThisQueryItem().Id("1"),
- NewMoreLikeThisQueryItem().Index(testIndexName2).Type("comment").Id("2").Routing("routing_id"),
- )
- q = q.Include(false)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatal(err)
- }
- got := string(data)
- expected := `{"mlt":{"docs":[{"_id":"1"},{"_id":"2","_index":"elastic-test2","_routing":"routing_id","_type":"comment"}],"exclude":true}}`
- if got != expected {
- t.Fatalf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMoreLikeThisQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another Golang topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Common query
- q := NewMoreLikeThisQuery("Golang topic.")
- q = q.Fields("message")
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&q).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_multi_match_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_multi_match_test.go
deleted file mode 100644
index a7bd3471b3..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_multi_match_test.go
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestMultiMatchQuery(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryBestFields(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").Type("best_fields")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":0,"type":"best_fields"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryMostFields(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").Type("most_fields")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":1,"type":"most_fields"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryCrossFields(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").Type("cross_fields")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":0,"type":"cross_fields"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryPhrase(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").Type("phrase")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":0,"type":"phrase"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryPhrasePrefix(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").Type("phrase_prefix")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":0,"type":"phrase_prefix"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestMultiMatchQueryBestFieldsWithCustomTieBreaker(t *testing.T) {
- q := NewMultiMatchQuery("this is a test", "subject", "message").
- Type("best_fields").
- TieBreaker(0.3)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"multi_match":{"fields":["subject","message"],"query":"this is a test","tie_breaker":0.3,"type":"best_fields"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_nested_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_nested_test.go
deleted file mode 100644
index 58609d6ba7..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_nested_test.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestNestedQuery(t *testing.T) {
- f := NewNestedQuery("obj1")
- bq := NewBoolQuery()
- bq = bq.Must(NewTermQuery("obj1.name", "blue"))
- bq = bq.Must(NewRangeQuery("obj1.count").Gt(5))
- f = f.Query(bq)
- f = f.QueryName("qname")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"nested":{"_name":"qname","path":"obj1","query":{"bool":{"must":[{"term":{"obj1.name":"blue"}},{"range":{"obj1.count":{"from":5,"include_lower":false,"include_upper":true,"to":null}}}]}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestNestedQueryWithInnerHit(t *testing.T) {
- f := NewNestedQuery("obj1")
- bq := NewBoolQuery()
- bq = bq.Must(NewTermQuery("obj1.name", "blue"))
- bq = bq.Must(NewRangeQuery("obj1.count").Gt(5))
- f = f.Query(bq)
- f = f.QueryName("qname")
- f = f.InnerHit(NewInnerHit().Name("comments").Query(NewTermQuery("user", "olivere")))
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"nested":{"_name":"qname","inner_hits":{"name":"comments","query":{"term":{"user":"olivere"}}},"path":"obj1","query":{"bool":{"must":[{"term":{"obj1.name":"blue"}},{"range":{"obj1.count":{"from":5,"include_lower":false,"include_upper":true,"to":null}}}]}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_prefix_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_prefix_test.go
deleted file mode 100644
index 0c2ac929be..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_prefix_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestPrefixQuery(t *testing.T) {
- q := NewPrefixQuery("user", "ki")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"prefix":{"user":"ki"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPrefixQueryWithOptions(t *testing.T) {
- q := NewPrefixQuery("user", "ki")
- q = q.QueryName("my_query_name")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"prefix":{"user":{"_name":"my_query_name","prefix":"ki"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_query_string_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_query_string_test.go
deleted file mode 100644
index 20f41a0c34..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_query_string_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestQueryStringQuery(t *testing.T) {
- q := NewQueryStringQuery(`this AND that OR thus`)
- q = q.DefaultField("content")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query_string":{"default_field":"content","query":"this AND that OR thus"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_range_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_range_test.go
deleted file mode 100644
index b1da0b69e9..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_range_test.go
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRangeQuery(t *testing.T) {
- q := NewRangeQuery("postDate").From("2010-03-01").To("2010-04-01")
- q = q.QueryName("my_query")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"_name":"my_query","postDate":{"from":"2010-03-01","include_lower":true,"include_upper":true,"to":"2010-04-01"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-/*
-func TestRangeQueryGte(t *testing.T) {
- q := NewRangeQuery("postDate").Gte("2010-03-01")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"postDate":{"gte":"2010-03-01"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-*/
-
-func TestRangeQueryWithTimeZone(t *testing.T) {
- f := NewRangeQuery("born").
- Gte("2012-01-01").
- Lte("now").
- TimeZone("+1:00")
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"born":{"from":"2012-01-01","include_lower":true,"include_upper":true,"time_zone":"+1:00","to":"now"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRangeQueryWithFormat(t *testing.T) {
- q := NewRangeQuery("born").
- Gte("2012/01/01").
- Lte("now").
- Format("yyyy/MM/dd")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"range":{"born":{"format":"yyyy/MM/dd","from":"2012/01/01","include_lower":true,"include_upper":true,"to":"now"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_regexp_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_regexp_test.go
deleted file mode 100644
index cfd4b6ab54..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_regexp_test.go
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestRegexpQuery(t *testing.T) {
- q := NewRegexpQuery("name.first", "s.*y")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"regexp":{"name.first":{"value":"s.*y"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestRegexpQueryWithOptions(t *testing.T) {
- q := NewRegexpQuery("name.first", "s.*y").
- Boost(1.2).
- Flags("INTERSECTION|COMPLEMENT|EMPTY").
- QueryName("my_query_name")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"regexp":{"name.first":{"boost":1.2,"flags":"INTERSECTION|COMPLEMENT|EMPTY","name":"my_query_name","value":"s.*y"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_simple_query_string_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_simple_query_string_test.go
deleted file mode 100644
index 6f6ad7d8b0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_simple_query_string_test.go
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSimpleQueryStringQuery(t *testing.T) {
- q := NewSimpleQueryStringQuery(`"fried eggs" +(eggplant | potato) -frittata`)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"simple_query_string":{"query":"\"fried eggs\" +(eggplant | potato) -frittata"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSimpleQueryStringQueryExec(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- query := NewSimpleQueryStringQuery("+Golang +Elasticsearch")
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&query).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 1 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 1, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 1 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 1, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_template_query_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_template_query_test.go
deleted file mode 100644
index 74ba2a3ad5..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_template_query_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTemplateQueryInlineTest(t *testing.T) {
- f := NewTemplateQuery("\"match_{{template}}\": {}}\"").Vars(map[string]interface{}{"template": "all"})
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"template":{"params":{"template":"all"},"query":"\"match_{{template}}\": {}}\""}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTemplateQueryIndexedTest(t *testing.T) {
- f := NewTemplateQuery("indexedTemplate").
- TemplateType("id").
- Vars(map[string]interface{}{"template": "all"})
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"template":{"id":"indexedTemplate","params":{"template":"all"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTemplateQueryFileTest(t *testing.T) {
- f := NewTemplateQuery("storedTemplate").
- TemplateType("file").
- Vars(map[string]interface{}{"template": "all"})
- data, err := json.Marshal(f.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"template":{"file":"storedTemplate","params":{"template":"all"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_term_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_term_test.go
deleted file mode 100644
index 09da9840fd..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_term_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermQuery(t *testing.T) {
- q := NewTermQuery("user", "ki")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"term":{"user":"ki"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermQueryWithOptions(t *testing.T) {
- q := NewTermQuery("user", "ki")
- q = q.Boost(2.79)
- q = q.QueryName("my_tq")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"term":{"user":{"_name":"my_tq","boost":2.79,"value":"ki"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_terms_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_terms_test.go
deleted file mode 100644
index 020d87fe3a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_terms_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermsQuery(t *testing.T) {
- q := NewTermsQuery("user", "ki")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms":{"user":["ki"]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestTermQuerysWithOptions(t *testing.T) {
- q := NewTermsQuery("user", "ki", "ko")
- q = q.Boost(2.79)
- q = q.QueryName("my_tq")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"terms":{"_name":"my_tq","boost":2.79,"user":["ki","ko"]}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_wildcard_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_wildcard_test.go
deleted file mode 100644
index 65d775fc8b..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_queries_wildcard_test.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic_test
-
-import (
- "encoding/json"
- "testing"
-
- "github.com/olivere/elastic"
-)
-
-func ExampleWildcardQuery() {
- // Get a client to the local Elasticsearch instance.
- client, err := elastic.NewClient()
- if err != nil {
- // Handle error
- panic(err)
- }
-
- // Define wildcard query
- q := elastic.NewWildcardQuery("user", "oli*er?").Boost(1.2)
- searchResult, err := client.Search().
- Index("twitter"). // search in index "twitter"
- Query(q). // use wildcard query defined above
- Do() // execute
- if err != nil {
- // Handle error
- panic(err)
- }
- _ = searchResult
-}
-
-func TestWildcardQuery(t *testing.T) {
- q := elastic.NewWildcardQuery("user", "ki*y??")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"wildcard":{"user":{"wildcard":"ki*y??"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestWildcardQueryWithBoost(t *testing.T) {
- q := elastic.NewWildcardQuery("user", "ki*y??").Boost(1.2)
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"wildcard":{"user":{"boost":1.2,"wildcard":"ki*y??"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_request_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_request_test.go
deleted file mode 100644
index 1185643f89..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_request_test.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestSearchRequestIndex(t *testing.T) {
- builder := NewSearchRequest().Index("test")
- data, err := json.Marshal(builder.header())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"index":"test"}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchRequestIndices(t *testing.T) {
- builder := NewSearchRequest().Indices("test", "test2")
- data, err := json.Marshal(builder.header())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"indices":["test","test2"]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchRequestHasIndices(t *testing.T) {
- builder := NewSearchRequest()
- if builder.HasIndices() {
- t.Errorf("expected HasIndices to return true; got %v", builder.HasIndices())
- }
- builder = builder.Indices("test", "test2")
- if !builder.HasIndices() {
- t.Errorf("expected HasIndices to return false; got %v", builder.HasIndices())
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_source_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_source_test.go
deleted file mode 100644
index 918e464091..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_source_test.go
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSearchSourceMatchAllQuery(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceFromAndSize(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).From(21).Size(20)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"from":21,"query":{"match_all":{}},"size":20}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceNoFields(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).NoFields()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":[],"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceFields(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).Fields("message", "tags")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fields":["message","tags"],"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceFetchSourceDisabled(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).FetchSource(false)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_source":false,"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceFetchSourceByWildcards(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- fsc := NewFetchSourceContext(true).Include("obj1.*", "obj2.*").Exclude("*.description")
- builder := NewSearchSource().Query(matchAllQ).FetchSourceContext(fsc)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_source":{"excludes":["*.description"],"includes":["obj1.*","obj2.*"]},"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceFieldDataFields(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).FieldDataFields("test1", "test2")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"fielddata_fields":["test1","test2"],"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceScriptFields(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- sf1 := NewScriptField("test1", "doc['my_field_name'].value * 2", "", nil)
- sf2 := NewScriptField("test2", "doc['my_field_name'].value * factor", "", map[string]interface{}{"factor": 3.1415927})
- builder := NewSearchSource().Query(matchAllQ).ScriptFields(sf1, sf2)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query":{"match_all":{}},"script_fields":{"test1":{"script":"doc['my_field_name'].value * 2"},"test2":{"params":{"factor":3.1415927},"script":"doc['my_field_name'].value * factor"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourcePostFilter(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- pf := NewTermFilter("tag", "important")
- builder := NewSearchSource().Query(matchAllQ).PostFilter(pf)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"post_filter":{"term":{"tag":"important"}},"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceHighlight(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- hl := NewHighlight().Field("content")
- builder := NewSearchSource().Query(matchAllQ).Highlight(hl)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"highlight":{"fields":{"content":{}}},"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceRescoring(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- rescorerQuery := NewMatchQuery("field1", "the quick brown fox").Type("phrase").Slop(2)
- rescorer := NewQueryRescorer(rescorerQuery)
- rescorer = rescorer.QueryWeight(0.7)
- rescorer = rescorer.RescoreQueryWeight(1.2)
- rescore := NewRescore().WindowSize(50).Rescorer(rescorer)
- builder := NewSearchSource().Query(matchAllQ).AddRescore(rescore)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"query":{"match_all":{}},"rescore":{"query":{"query_weight":0.7,"rescore_query":{"match":{"field1":{"query":"the quick brown fox","slop":2,"type":"phrase"}}},"rescore_query_weight":1.2},"window_size":50}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceIndexBoost(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).IndexBoost("index1", 1.4).IndexBoost("index2", 1.3)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"indices_boost":{"index1":1.4,"index2":1.3},"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSearchSourceInnerHits(t *testing.T) {
- matchAllQ := NewMatchAllQuery()
- builder := NewSearchSource().Query(matchAllQ).
- InnerHit("comments", NewInnerHit().Type("comment").Query(NewMatchQuery("user", "olivere"))).
- InnerHit("views", NewInnerHit().Path("view"))
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"inner_hits":{"comments":{"type":{"comment":{"query":{"match":{"user":{"query":"olivere"}}}}}},"views":{"path":{"view":{}}}},"query":{"match_all":{}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_suggester_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_suggester_test.go
deleted file mode 100644
index c70cdf9b67..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_suggester_test.go
+++ /dev/null
@@ -1,259 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- _ "encoding/json"
- _ "net/http"
- "testing"
-)
-
-func TestTermSuggester(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
-
- tsName := "my-suggestions"
- ts := NewTermSuggester(tsName)
- ts = ts.Text("Goolang")
- ts = ts.Field("message")
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Suggester(ts).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Suggest == nil {
- t.Errorf("expected SearchResult.Suggest != nil; got nil")
- }
- mySuggestions, found := searchResult.Suggest[tsName]
- if !found {
- t.Errorf("expected to find SearchResult.Suggest[%s]; got false", tsName)
- }
- if mySuggestions == nil {
- t.Errorf("expected SearchResult.Suggest[%s] != nil; got nil", tsName)
- }
-
- if len(mySuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(mySuggestions))
- }
- mySuggestion := mySuggestions[0]
- if mySuggestion.Text != "goolang" {
- t.Errorf("expected Text = 'goolang'; got %s", mySuggestion.Text)
- }
- if mySuggestion.Offset != 0 {
- t.Errorf("expected Offset = %d; got %d", 0, mySuggestion.Offset)
- }
- if mySuggestion.Length != 7 {
- t.Errorf("expected Length = %d; got %d", 7, mySuggestion.Length)
- }
- if len(mySuggestion.Options) != 1 {
- t.Errorf("expected 1 option; got %d", len(mySuggestion.Options))
- }
- myOption := mySuggestion.Options[0]
- if myOption.Text != "golang" {
- t.Errorf("expected Text = 'golang'; got %s", myOption.Text)
- }
- if myOption.Score == float32(0.0) {
- t.Errorf("expected Score != 0.0; got %v", myOption.Score)
- }
- if myOption.Freq == 0 {
- t.Errorf("expected Freq != 0; got %v", myOption.Freq)
- }
-}
-
-func TestPhraseSuggester(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
-
- phraseSuggesterName := "my-suggestions"
- ps := NewPhraseSuggester(phraseSuggesterName)
- ps = ps.Text("Goolang")
- ps = ps.Field("message")
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Suggester(ps).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Suggest == nil {
- t.Errorf("expected SearchResult.Suggest != nil; got nil")
- }
- mySuggestions, found := searchResult.Suggest[phraseSuggesterName]
- if !found {
- t.Errorf("expected to find SearchResult.Suggest[%s]; got false", phraseSuggesterName)
- }
- if mySuggestions == nil {
- t.Errorf("expected SearchResult.Suggest[%s] != nil; got nil", phraseSuggesterName)
- }
-
- if len(mySuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(mySuggestions))
- }
- mySuggestion := mySuggestions[0]
- if mySuggestion.Text != "Goolang" {
- t.Errorf("expected Text = 'Goolang'; got %s", mySuggestion.Text)
- }
- if mySuggestion.Offset != 0 {
- t.Errorf("expected Offset = %d; got %d", 0, mySuggestion.Offset)
- }
- if mySuggestion.Length != 7 {
- t.Errorf("expected Length = %d; got %d", 7, mySuggestion.Length)
- }
- /*
- if len(mySuggestion.Options) != 1 {
- t.Errorf("expected 1 option; got %d", len(mySuggestion.Options))
- }
- myOption := mySuggestion.Options[0]
- if myOption.Text != "golang" {
- t.Errorf("expected Text = 'golang'; got %s", myOption.Text)
- }
- if myOption.Score == float32(0.0) {
- t.Errorf("expected Score != 0.0; got %v", myOption.Score)
- }
- */
-}
-
-// TODO(oe): I get a "Completion suggester not supported" exception on 0.90.2?!
-/*
-func TestCompletionSuggester(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
-
- suggesterName := "my-suggestions"
- cs := NewCompletionSuggester(suggesterName)
- cs = cs.Text("Goolang")
- cs = cs.Field("message")
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Suggester(cs).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Suggest == nil {
- t.Errorf("expected SearchResult.Suggest != nil; got nil")
- }
- mySuggestions, found := searchResult.Suggest[suggesterName]
- if !found {
- t.Errorf("expected to find SearchResult.Suggest[%s]; got false")
- }
- if mySuggestions == nil {
- t.Errorf("expected SearchResult.Suggest[%s] != nil; got nil", suggesterName)
- }
-
- if len(mySuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(mySuggestions))
- }
- mySuggestion := mySuggestions[0]
- if mySuggestion.Text != "Goolang" {
- t.Errorf("expected Text = 'Goolang'; got %s", mySuggestion.Text)
- }
- if mySuggestion.Offset != 0 {
- t.Errorf("expected Offset = %d; got %d", 0, mySuggestion.Offset)
- }
- if mySuggestion.Length != 7 {
- t.Errorf("expected Length = %d; got %d", 7, mySuggestion.Length)
- }
- if len(mySuggestion.Options) != 1 {
- t.Errorf("expected 1 option; got %d", len(mySuggestion.Options))
- }
- myOption := mySuggestion.Options[0]
- if myOption.Text != "golang" {
- t.Errorf("expected Text = 'golang'; got %s", myOption.Text)
- }
- if myOption.Score == float32(0.0) {
- t.Errorf("expected Score != 0.0; got %v", myOption.Score)
- }
-}
-//*/
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_templates_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_templates_test.go
deleted file mode 100644
index eebc97fc36..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_templates_test.go
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "testing"
-)
-
-func TestSearchTemplatesLifecycle(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Template
- tmpl := `{"template":{"query":{"match":{"title":"{{query_string}}"}}}}`
-
- // Create template
- cresp, err := client.PutTemplate().Id("elastic-test").BodyString(tmpl).Do()
- if err != nil {
- t.Fatal(err)
- }
- if cresp == nil {
- t.Fatalf("expected response != nil; got: %v", cresp)
- }
- if !cresp.Created {
- t.Errorf("expected created = %v; got: %v", true, cresp.Created)
- }
-
- // Get template
- resp, err := client.GetTemplate().Id("elastic-test").Do()
- if err != nil {
- t.Fatal(err)
- }
- if resp == nil {
- t.Fatalf("expected response != nil; got: %v", resp)
- }
- if resp.Template == "" {
- t.Errorf("expected template != %q; got: %q", "", resp.Template)
- }
-
- // Delete template
- dresp, err := client.DeleteTemplate().Id("elastic-test").Do()
- if err != nil {
- t.Fatal(err)
- }
- if dresp == nil {
- t.Fatalf("expected response != nil; got: %v", dresp)
- }
- if !dresp.Found {
- t.Fatalf("expected found = %v; got: %v", true, dresp.Found)
- }
-}
-
-func TestSearchTemplatesInlineQuery(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Run query with (inline) search template
- // See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html
- tq := NewTemplateQuery(`{"match_{{template}}": {}}`).Var("template", "all")
- resp, err := client.Search(testIndexName).Query(&tq).Do()
- if err != nil {
- t.Fatal(err)
- }
- if resp == nil {
- t.Fatalf("expected response != nil; got: %v", resp)
- }
- if resp.Hits == nil {
- t.Fatalf("expected response hits != nil; got: %v", resp.Hits)
- }
- if resp.Hits.TotalHits != 3 {
- t.Fatalf("expected 3 hits; got: %d", resp.Hits.TotalHits)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/search_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/search_test.go
deleted file mode 100644
index a4e71d8e9a..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/search_test.go
+++ /dev/null
@@ -1,882 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- _ "net/http"
- "reflect"
- "testing"
- "time"
-)
-
-func TestSearchMatchAll(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().Index(testIndexName).Query(&all).Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 4 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 4, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 4 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 4, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
-
-func BenchmarkSearchMatchAll(b *testing.B) {
- client := setupTestClientAndCreateIndexAndAddDocs(b)
-
- for n := 0; n < b.N; n++ {
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().Index(testIndexName).Query(&all).Do()
- if err != nil {
- b.Fatal(err)
- }
- if searchResult.Hits == nil {
- b.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 4 {
- b.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 4, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 4 {
- b.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 4, len(searchResult.Hits.Hits))
- }
- }
-}
-
-func TestSearchResultTotalHits(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- count, err := client.Count(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- all := NewMatchAllQuery()
- searchResult, err := client.Search().Index(testIndexName).Query(&all).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- got := searchResult.TotalHits()
- if got != count {
- t.Fatalf("expected %d hits; got: %d", count, got)
- }
-
- // No hits
- searchResult = &SearchResult{}
- got = searchResult.TotalHits()
- if got != 0 {
- t.Errorf("expected %d hits; got: %d", 0, got)
- }
-}
-
-func TestSearchResultEach(t *testing.T) {
- client := setupTestClientAndCreateIndexAndAddDocs(t)
-
- all := NewMatchAllQuery()
- searchResult, err := client.Search().Index(testIndexName).Query(&all).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Iterate over non-ptr type
- var aTweet tweet
- count := 0
- for _, item := range searchResult.Each(reflect.TypeOf(aTweet)) {
- count++
- _, ok := item.(tweet)
- if !ok {
- t.Fatalf("expected hit to be serialized as tweet; got: %v", reflect.ValueOf(item))
- }
- }
- if count == 0 {
- t.Errorf("expected to find some hits; got: %d", count)
- }
-
- // Iterate over ptr-type
- count = 0
- var aTweetPtr *tweet
- for _, item := range searchResult.Each(reflect.TypeOf(aTweetPtr)) {
- count++
- tw, ok := item.(*tweet)
- if !ok {
- t.Fatalf("expected hit to be serialized as tweet; got: %v", reflect.ValueOf(item))
- }
- if tw == nil {
- t.Fatal("expected hit to not be nil")
- }
- }
- if count == 0 {
- t.Errorf("expected to find some hits; got: %d", count)
- }
-
- // Does not iterate when no hits are found
- searchResult = &SearchResult{Hits: nil}
- count = 0
- for _, item := range searchResult.Each(reflect.TypeOf(aTweet)) {
- count++
- _ = item
- }
- if count != 0 {
- t.Errorf("expected to not find any hits; got: %d", count)
- }
- searchResult = &SearchResult{Hits: &SearchHits{Hits: make([]*SearchHit, 0)}}
- count = 0
- for _, item := range searchResult.Each(reflect.TypeOf(aTweet)) {
- count++
- _ = item
- }
- if count != 0 {
- t.Errorf("expected to not find any hits; got: %d", count)
- }
-}
-
-func TestSearchSorting(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Sort("created", false).
- Timeout("1s").
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
-
-func TestSearchSortingBySorters(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- SortBy(NewFieldSort("created").Desc(), NewScoreSort()).
- Timeout("1s").
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- item := make(map[string]interface{})
- err := json.Unmarshal(*hit.Source, &item)
- if err != nil {
- t.Fatal(err)
- }
- }
-}
-
-func TestSearchSpecificFields(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
- tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
- tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Fields("message").
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- if hit.Source != nil {
- t.Fatalf("expected SearchResult.Hits.Hit.Source to be nil; got: %q", hit.Source)
- }
- if hit.Fields == nil {
- t.Fatal("expected SearchResult.Hits.Hit.Fields to be != nil")
- }
- field, found := hit.Fields["message"]
- if !found {
- t.Errorf("expected SearchResult.Hits.Hit.Fields[%s] to be found", "message")
- }
- fields, ok := field.([]interface{})
- if !ok {
- t.Errorf("expected []interface{}; got: %v", reflect.TypeOf(fields))
- }
- if len(fields) != 1 {
- t.Errorf("expected a field with 1 entry; got: %d", len(fields))
- }
- message, ok := fields[0].(string)
- if !ok {
- t.Errorf("expected a string; got: %v", reflect.TypeOf(fields[0]))
- }
- if message == "" {
- t.Errorf("expected a message; got: %q", message)
- }
- }
-}
-
-func TestSearchExplain(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Match all should return all documents
- all := NewMatchAllQuery()
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(&all).
- Explain(true).
- Timeout("1s").
- // Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
-
- for _, hit := range searchResult.Hits.Hits {
- if hit.Index != testIndexName {
- t.Errorf("expected SearchResult.Hits.Hit.Index = %q; got %q", testIndexName, hit.Index)
- }
- if hit.Explanation == nil {
- t.Fatal("expected search explanation")
- }
- if hit.Explanation.Value <= 0.0 {
- t.Errorf("expected explanation value to be > 0.0; got: %v", hit.Explanation.Value)
- }
- if hit.Explanation.Description == "" {
- t.Errorf("expected explanation description != %q; got: %q", "", hit.Explanation.Description)
- }
- }
-}
-
-func TestSearchSource(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Set up the request JSON manually to pass to the search service via Source()
- source := map[string]interface{}{
- "query": map[string]interface{}{
- "match_all": map[string]interface{}{},
- },
- }
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Source(source). // sets the JSON request
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
-}
-
-func TestSearchSearchSource(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Set up the search source manually and pass it to the search service via SearchSource()
- ss := NewSearchSource().Query(NewMatchAllQuery()).From(0).Size(2)
-
- // One can use ss.Source() to get to the raw interface{} that will be used
- // as the search request JSON by the SearchService.
-
- searchResult, err := client.Search().
- Index(testIndexName).
- SearchSource(ss). // sets the SearchSource
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 2 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 2, len(searchResult.Hits.Hits))
- }
-}
-
-func TestSearchInnerHitsOnHasChild(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Check for valid ES version
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if esversion < "1.5.0" {
- t.Skip("InnerHits feature is only available for Elasticsearch 1.5+")
- return
- }
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- comment2a := comment{User: "sandrae", Comment: "What does that even mean?"}
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
- comment3a := comment{User: "nico", Comment: "You bet."}
- comment3b := comment{User: "olivere", Comment: "It sure is."}
-
- // Add all documents
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c2a").Parent("t2").BodyJson(&comment2a).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c3a").Parent("t3").BodyJson(&comment3a).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c3b").Parent("t3").BodyJson(&comment3b).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- fq := NewFilteredQuery(NewMatchAllQuery())
- fq = fq.Filter(
- NewHasChildFilter("comment").
- Query(NewMatchAllQuery()).
- InnerHit(NewInnerHit().Name("comments")))
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(fq).
- Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 2 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 2, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 2 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 2, len(searchResult.Hits.Hits))
- }
-
- hit := searchResult.Hits.Hits[0]
- if hit.Id != "t2" {
- t.Fatalf("expected tweet %q; got: %q", "t2", hit.Id)
- }
- if hit.InnerHits == nil {
- t.Fatalf("expected inner hits; got: %v", hit.InnerHits)
- }
- if len(hit.InnerHits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(hit.InnerHits))
- }
- innerHits, found := hit.InnerHits["comments"]
- if !found {
- t.Fatalf("expected inner hits for name %q", "comments")
- }
- if innerHits == nil || innerHits.Hits == nil {
- t.Fatal("expected inner hits != nil")
- }
- if len(innerHits.Hits.Hits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(innerHits.Hits.Hits))
- }
- if innerHits.Hits.Hits[0].Id != "c2a" {
- t.Fatalf("expected inner hit with id %q; got: %q", "c2a", innerHits.Hits.Hits[0].Id)
- }
-
- hit = searchResult.Hits.Hits[1]
- if hit.Id != "t3" {
- t.Fatalf("expected tweet %q; got: %q", "t3", hit.Id)
- }
- if hit.InnerHits == nil {
- t.Fatalf("expected inner hits; got: %v", hit.InnerHits)
- }
- if len(hit.InnerHits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(hit.InnerHits))
- }
- innerHits, found = hit.InnerHits["comments"]
- if !found {
- t.Fatalf("expected inner hits for name %q", "comments")
- }
- if innerHits == nil || innerHits.Hits == nil {
- t.Fatal("expected inner hits != nil")
- }
- if len(innerHits.Hits.Hits) != 2 {
- t.Fatalf("expected %d inner hits; got: %d", 2, len(innerHits.Hits.Hits))
- }
- if innerHits.Hits.Hits[0].Id != "c3a" {
- t.Fatalf("expected inner hit with id %q; got: %q", "c3a", innerHits.Hits.Hits[0].Id)
- }
- if innerHits.Hits.Hits[1].Id != "c3b" {
- t.Fatalf("expected inner hit with id %q; got: %q", "c3b", innerHits.Hits.Hits[1].Id)
- }
-}
-
-func TestSearchInnerHitsOnHasParent(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Check for valid ES version
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if esversion < "1.5.0" {
- t.Skip("InnerHits feature is only available for Elasticsearch 1.5+")
- return
- }
-
- tweet1 := tweet{
- User: "olivere", Retweets: 108,
- Message: "Welcome to Golang and Elasticsearch.",
- Created: time.Date(2012, 12, 12, 17, 38, 34, 0, time.UTC),
- }
- tweet2 := tweet{
- User: "olivere", Retweets: 0,
- Message: "Another unrelated topic.",
- Created: time.Date(2012, 10, 10, 8, 12, 03, 0, time.UTC),
- }
- comment2a := comment{User: "sandrae", Comment: "What does that even mean?"}
- tweet3 := tweet{
- User: "sandrae", Retweets: 12,
- Message: "Cycling is fun.",
- Created: time.Date(2011, 11, 11, 10, 58, 12, 0, time.UTC),
- }
- comment3a := comment{User: "nico", Comment: "You bet."}
- comment3b := comment{User: "olivere", Comment: "It sure is."}
-
- // Add all documents
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c2a").Parent("t2").BodyJson(&comment2a).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("t3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c3a").Parent("t3").BodyJson(&comment3a).Do()
- if err != nil {
- t.Fatal(err)
- }
- _, err = client.Index().Index(testIndexName).Type("comment").Id("c3b").Parent("t3").BodyJson(&comment3b).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- fq := NewFilteredQuery(NewMatchAllQuery())
- fq = fq.Filter(
- NewHasParentFilter("tweet").
- Query(NewMatchAllQuery()).
- InnerHit(NewInnerHit().Name("tweets")))
-
- searchResult, err := client.Search().
- Index(testIndexName).
- Query(fq).
- Pretty(true).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if searchResult.Hits == nil {
- t.Errorf("expected SearchResult.Hits != nil; got nil")
- }
- if searchResult.Hits.TotalHits != 3 {
- t.Errorf("expected SearchResult.Hits.TotalHits = %d; got %d", 3, searchResult.Hits.TotalHits)
- }
- if len(searchResult.Hits.Hits) != 3 {
- t.Errorf("expected len(SearchResult.Hits.Hits) = %d; got %d", 3, len(searchResult.Hits.Hits))
- }
-
- hit := searchResult.Hits.Hits[0]
- if hit.Id != "c2a" {
- t.Fatalf("expected tweet %q; got: %q", "c2a", hit.Id)
- }
- if hit.InnerHits == nil {
- t.Fatalf("expected inner hits; got: %v", hit.InnerHits)
- }
- if len(hit.InnerHits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(hit.InnerHits))
- }
- innerHits, found := hit.InnerHits["tweets"]
- if !found {
- t.Fatalf("expected inner hits for name %q", "tweets")
- }
- if innerHits == nil || innerHits.Hits == nil {
- t.Fatal("expected inner hits != nil")
- }
- if len(innerHits.Hits.Hits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(innerHits.Hits.Hits))
- }
- if innerHits.Hits.Hits[0].Id != "t2" {
- t.Fatalf("expected inner hit with id %q; got: %q", "t2", innerHits.Hits.Hits[0].Id)
- }
-
- hit = searchResult.Hits.Hits[1]
- if hit.Id != "c3a" {
- t.Fatalf("expected tweet %q; got: %q", "c3a", hit.Id)
- }
- if hit.InnerHits == nil {
- t.Fatalf("expected inner hits; got: %v", hit.InnerHits)
- }
- if len(hit.InnerHits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(hit.InnerHits))
- }
- innerHits, found = hit.InnerHits["tweets"]
- if !found {
- t.Fatalf("expected inner hits for name %q", "tweets")
- }
- if innerHits == nil || innerHits.Hits == nil {
- t.Fatal("expected inner hits != nil")
- }
- if len(innerHits.Hits.Hits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(innerHits.Hits.Hits))
- }
- if innerHits.Hits.Hits[0].Id != "t3" {
- t.Fatalf("expected inner hit with id %q; got: %q", "t3", innerHits.Hits.Hits[0].Id)
- }
-
- hit = searchResult.Hits.Hits[2]
- if hit.Id != "c3b" {
- t.Fatalf("expected tweet %q; got: %q", "c3b", hit.Id)
- }
- if hit.InnerHits == nil {
- t.Fatalf("expected inner hits; got: %v", hit.InnerHits)
- }
- if len(hit.InnerHits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(hit.InnerHits))
- }
- innerHits, found = hit.InnerHits["tweets"]
- if !found {
- t.Fatalf("expected inner hits for name %q", "tweets")
- }
- if innerHits == nil || innerHits.Hits == nil {
- t.Fatal("expected inner hits != nil")
- }
- if len(innerHits.Hits.Hits) != 1 {
- t.Fatalf("expected %d inner hits; got: %d", 1, len(innerHits.Hits.Hits))
- }
- if innerHits.Hits.Hits[0].Id != "t3" {
- t.Fatalf("expected inner hit with id %q; got: %q", "t3", innerHits.Hits.Hits[0].Id)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/sort_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/sort_test.go
deleted file mode 100644
index 394c8369c0..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/sort_test.go
+++ /dev/null
@@ -1,174 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSortInfo(t *testing.T) {
- builder := SortInfo{Field: "grade", Ascending: false}
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"grade":{"order":"desc"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestScoreSort(t *testing.T) {
- builder := NewScoreSort()
- if builder.ascending != false {
- t.Error("expected score sorter to be ascending by default")
- }
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_score":{}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestScoreSortOrderAscending(t *testing.T) {
- builder := NewScoreSort().Asc()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_score":{"reverse":true}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestScoreSortOrderDescending(t *testing.T) {
- builder := NewScoreSort().Desc()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_score":{}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldSort(t *testing.T) {
- builder := NewFieldSort("grade")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"grade":{"order":"asc"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldSortOrderDesc(t *testing.T) {
- builder := NewFieldSort("grade").Desc()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"grade":{"order":"desc"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFieldSortComplex(t *testing.T) {
- builder := NewFieldSort("price").Desc().
- SortMode("avg").
- Missing("_last").
- UnmappedType("product").
- NestedFilter(NewTermFilter("product.color", "blue")).
- NestedPath("variant")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"price":{"missing":"_last","mode":"avg","nested_filter":{"term":{"product.color":"blue"}},"nested_path":"variant","order":"desc","unmapped_type":"product"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceSort(t *testing.T) {
- builder := NewGeoDistanceSort("pin.location").
- Point(-70, 40).
- Order(true).
- Unit("km").
- SortMode("min").
- GeoDistance("sloppy_arc")
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_geo_distance":{"distance_type":"sloppy_arc","mode":"min","pin.location":[{"lat":-70,"lon":40}],"unit":"km"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestGeoDistanceSortOrderDesc(t *testing.T) {
- builder := NewGeoDistanceSort("pin.location").
- Point(-70, 40).
- Unit("km").
- SortMode("min").
- GeoDistance("sloppy_arc").
- Desc()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_geo_distance":{"distance_type":"sloppy_arc","mode":"min","pin.location":[{"lat":-70,"lon":40}],"reverse":true,"unit":"km"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-func TestScriptSort(t *testing.T) {
- builder := NewScriptSort("doc['field_name'].value * factor", "number").
- Param("factor", 1.1).
- Order(true)
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_script":{"params":{"factor":1.1},"script":"doc['field_name'].value * factor","type":"number"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestScriptSortOrderDesc(t *testing.T) {
- builder := NewScriptSort("doc['field_name'].value * factor", "number").
- Param("factor", 1.1).
- Desc()
- data, err := json.Marshal(builder.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"_script":{"params":{"factor":1.1},"reverse":true,"script":"doc['field_name'].value * factor","type":"number"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggest_field_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggest_field_test.go
deleted file mode 100644
index b01cf0af04..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggest_field_test.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSuggestField(t *testing.T) {
- field := NewSuggestField().
- Input("Welcome to Golang and Elasticsearch.", "Golang and Elasticsearch").
- Output("Golang and Elasticsearch: An introduction.").
- Weight(1).
- ContextQuery(
- NewSuggesterCategoryMapping("color").FieldName("color_field").DefaultValues("red", "green", "blue"),
- NewSuggesterGeoMapping("location").Precision("5m").Neighbors(true).DefaultLocations(GeoPointFromLatLon(52.516275, 13.377704)),
- )
- data, err := json.Marshal(field)
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"context":[{"color":{"default":["red","green","blue"],"path":"color_field","type":"category"}},{"location":{"default":{"lat":52.516275,"lon":13.377704},"neighbors":true,"precision":["5m"],"type":"geo"}}],"input":["Welcome to Golang and Elasticsearch.","Golang and Elasticsearch"],"output":"Golang and Elasticsearch: An introduction.","weight":1}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggest_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggest_test.go
deleted file mode 100644
index 50a4a0952e..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggest_test.go
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- _ "net/http"
- "testing"
-)
-
-func TestSuggestService(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- tweet1 := tweet{
- User: "olivere",
- Message: "Welcome to Golang and Elasticsearch.",
- Tags: []string{"golang", "elasticsearch"},
- Location: "48.1333,11.5667", // lat,lon
- Suggest: NewSuggestField().
- Input("Welcome to Golang and Elasticsearch.", "Golang and Elasticsearch").
- Output("Golang and Elasticsearch: An introduction.").
- Weight(0),
- }
- tweet2 := tweet{
- User: "olivere",
- Message: "Another unrelated topic.",
- Tags: []string{"golang"},
- Location: "48.1189,11.4289", // lat,lon
- Suggest: NewSuggestField().
- Input("Another unrelated topic.", "Golang topic.").
- Output("About Golang.").
- Weight(1),
- }
- tweet3 := tweet{
- User: "sandrae",
- Message: "Cycling is fun.",
- Tags: []string{"sports", "cycling"},
- Location: "47.7167,11.7167", // lat,lon
- Suggest: NewSuggestField().
- Input("Cycling is fun.").
- Output("Cycling is a fun sport."),
- }
-
- // Add all documents
- _, err := client.Index().Index(testIndexName).Type("tweet").Id("1").BodyJson(&tweet1).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("2").BodyJson(&tweet2).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Index().Index(testIndexName).Type("tweet").Id("3").BodyJson(&tweet3).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = client.Flush().Index(testIndexName).Do()
- if err != nil {
- t.Fatal(err)
- }
-
- // Test _suggest endpoint
- termSuggesterName := "my-term-suggester"
- termSuggester := NewTermSuggester(termSuggesterName).Text("Goolang").Field("message")
- phraseSuggesterName := "my-phrase-suggester"
- phraseSuggester := NewPhraseSuggester(phraseSuggesterName).Text("Goolang").Field("message")
- completionSuggesterName := "my-completion-suggester"
- completionSuggester := NewCompletionSuggester(completionSuggesterName).Text("Go").Field("suggest_field")
-
- result, err := client.Suggest().
- Index(testIndexName).
- Suggester(termSuggester).
- Suggester(phraseSuggester).
- Suggester(completionSuggester).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if result == nil {
- t.Errorf("expected result != nil; got nil")
- }
- if len(result) != 3 {
- t.Errorf("expected 3 suggester results; got %d", len(result))
- }
-
- termSuggestions, found := result[termSuggesterName]
- if !found {
- t.Errorf("expected to find Suggest[%s]; got false", termSuggesterName)
- }
- if termSuggestions == nil {
- t.Errorf("expected Suggest[%s] != nil; got nil", termSuggesterName)
- }
- if len(termSuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(termSuggestions))
- }
-
- phraseSuggestions, found := result[phraseSuggesterName]
- if !found {
- t.Errorf("expected to find Suggest[%s]; got false", phraseSuggesterName)
- }
- if phraseSuggestions == nil {
- t.Errorf("expected Suggest[%s] != nil; got nil", phraseSuggesterName)
- }
- if len(phraseSuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(phraseSuggestions))
- }
-
- completionSuggestions, found := result[completionSuggesterName]
- if !found {
- t.Errorf("expected to find Suggest[%s]; got false", completionSuggesterName)
- }
- if completionSuggestions == nil {
- t.Errorf("expected Suggest[%s] != nil; got nil", completionSuggesterName)
- }
- if len(completionSuggestions) != 1 {
- t.Errorf("expected 1 suggestion; got %d", len(completionSuggestions))
- }
- if len(completionSuggestions[0].Options) != 2 {
- t.Errorf("expected 2 suggestion options; got %d", len(completionSuggestions[0].Options))
- }
- if completionSuggestions[0].Options[0].Text != "About Golang." {
- t.Errorf("expected Suggest[%s][0].Options[0].Text == %q; got %q", completionSuggesterName, "About Golang.", completionSuggestions[0].Options[0].Text)
- }
- if completionSuggestions[0].Options[1].Text != "Golang and Elasticsearch: An introduction." {
- t.Errorf("expected Suggest[%s][0].Options[1].Text == %q; got %q", completionSuggesterName, "Golang and Elasticsearch: An introduction.", completionSuggestions[0].Options[1].Text)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_fuzzy_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_fuzzy_test.go
deleted file mode 100644
index a7d9afc844..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_fuzzy_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestFuzzyCompletionSuggesterSource(t *testing.T) {
- s := NewFuzzyCompletionSuggester("song-suggest").
- Text("n").
- Field("suggest").
- Fuzziness(2)
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"song-suggest":{"text":"n","completion":{"field":"suggest","fuzzy":{"fuzziness":2}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestFuzzyCompletionSuggesterWithStringFuzzinessSource(t *testing.T) {
- s := NewFuzzyCompletionSuggester("song-suggest").
- Text("n").
- Field("suggest").
- Fuzziness("1..4")
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"song-suggest":{"text":"n","completion":{"field":"suggest","fuzzy":{"fuzziness":"1..4"}}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_test.go
deleted file mode 100644
index 18d8745908..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_completion_test.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestCompletionSuggesterSource(t *testing.T) {
- s := NewCompletionSuggester("song-suggest").
- Text("n").
- Field("suggest")
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"song-suggest":{"text":"n","completion":{"field":"suggest"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_category_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_category_test.go
deleted file mode 100644
index 1d380fbaa6..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_category_test.go
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSuggesterCategoryMapping(t *testing.T) {
- q := NewSuggesterCategoryMapping("color").
- DefaultValues("red")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"color":{"default":"red","type":"category"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSuggesterCategoryMappingWithTwoDefaultValues(t *testing.T) {
- q := NewSuggesterCategoryMapping("color").
- DefaultValues("red", "orange")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"color":{"default":["red","orange"],"type":"category"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSuggesterCategoryMappingWithFieldName(t *testing.T) {
- q := NewSuggesterCategoryMapping("color").
- DefaultValues("red", "orange").
- FieldName("color_field")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"color":{"default":["red","orange"],"path":"color_field","type":"category"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSuggesterCategoryQuery(t *testing.T) {
- q := NewSuggesterCategoryQuery("color", "red")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"color":"red"}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSuggesterCategoryQueryWithTwoValues(t *testing.T) {
- q := NewSuggesterCategoryQuery("color", "red", "yellow")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"color":["red","yellow"]}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_geo_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_geo_test.go
deleted file mode 100644
index a6c346c5c3..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_context_geo_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestSuggesterGeoMapping(t *testing.T) {
- q := NewSuggesterGeoMapping("location").
- Precision("1km", "5m").
- Neighbors(true).
- FieldName("pin").
- DefaultLocations(GeoPointFromLatLon(0.0, 0.0))
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"location":{"default":{"lat":0,"lon":0},"neighbors":true,"path":"pin","precision":["1km","5m"],"type":"geo"}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestSuggesterGeoQuery(t *testing.T) {
- q := NewSuggesterGeoQuery("location", GeoPointFromLatLon(11.5, 62.71)).
- Precision("1km")
- data, err := json.Marshal(q.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"location":{"precision":"1km","value":{"lat":11.5,"lon":62.71}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_phrase_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_phrase_test.go
deleted file mode 100644
index 135c037785..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_phrase_test.go
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestPhraseSuggesterSource(t *testing.T) {
- s := NewPhraseSuggester("name").
- Text("Xor the Got-Jewel").
- Analyzer("body").
- Field("bigram").
- Size(1).
- RealWordErrorLikelihood(0.95).
- MaxErrors(0.5).
- GramSize(2).
- Highlight("", "")
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"name":{"text":"Xor the Got-Jewel","phrase":{"analyzer":"body","field":"bigram","gram_size":2,"highlight":{"post_tag":"\u003c/em\u003e","pre_tag":"\u003cem\u003e"},"max_errors":0.5,"real_word_error_likelihood":0.95,"size":1}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPhraseSuggesterSourceWithContextQuery(t *testing.T) {
- geomapQ := NewSuggesterGeoMapping("location").
- Precision("1km", "5m").
- Neighbors(true).
- FieldName("pin").
- DefaultLocations(GeoPointFromLatLon(0.0, 0.0))
-
- s := NewPhraseSuggester("name").
- Text("Xor the Got-Jewel").
- Analyzer("body").
- Field("bigram").
- Size(1).
- RealWordErrorLikelihood(0.95).
- MaxErrors(0.5).
- GramSize(2).
- Highlight("", "").
- ContextQuery(geomapQ)
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"name":{"text":"Xor the Got-Jewel","phrase":{"analyzer":"body","context":{"location":{"default":{"lat":0,"lon":0},"neighbors":true,"path":"pin","precision":["1km","5m"],"type":"geo"}},"field":"bigram","gram_size":2,"highlight":{"post_tag":"\u003c/em\u003e","pre_tag":"\u003cem\u003e"},"max_errors":0.5,"real_word_error_likelihood":0.95,"size":1}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPhraseSuggesterComplexSource(t *testing.T) {
- g1 := NewDirectCandidateGenerator("body").
- SuggestMode("always").
- MinWordLength(1)
-
- g2 := NewDirectCandidateGenerator("reverse").
- SuggestMode("always").
- MinWordLength(1).
- PreFilter("reverse").
- PostFilter("reverse")
-
- s := NewPhraseSuggester("simple_phrase").
- Text("Xor the Got-Jewel").
- Analyzer("body").
- Field("bigram").
- Size(4).
- RealWordErrorLikelihood(0.95).
- Confidence(2.0).
- GramSize(2).
- CandidateGenerators(g1, g2).
- CollateQuery(`"match":{"{{field_name}}" : "{{suggestion}}"}`).
- CollateParams(map[string]interface{}{"field_name": "title"}).
- CollatePreference("_primary").
- CollatePrune(true)
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"simple_phrase":{"text":"Xor the Got-Jewel","phrase":{"analyzer":"body","collate":{"params":{"field_name":"title"},"preference":"_primary","prune":true,"query":"\"match\":{\"{{field_name}}\" : \"{{suggestion}}\"}"},"confidence":2,"direct_generator":[{"field":"body","min_word_length":1,"suggest_mode":"always"},{"field":"reverse","min_word_length":1,"post_filter":"reverse","pre_filter":"reverse","suggest_mode":"always"}],"field":"bigram","gram_size":2,"real_word_error_likelihood":0.95,"size":4}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
-
-func TestPhraseStupidBackoffSmoothingModel(t *testing.T) {
- s := NewStupidBackoffSmoothingModel(0.42)
- data, err := json.Marshal(s.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- // The source does NOT include the smoothing model type!
- expected := `{"discount":0.42}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
- if s.Type() != "stupid_backoff" {
- t.Errorf("expected %q, got: %q", "stupid_backoff", s.Type())
- }
-}
-
-func TestPhraseLaplaceSmoothingModel(t *testing.T) {
- s := NewLaplaceSmoothingModel(0.63)
- data, err := json.Marshal(s.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- // The source does NOT include the smoothing model type!
- expected := `{"alpha":0.63}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
- if s.Type() != "laplace" {
- t.Errorf("expected %q, got: %q", "laplace", s.Type())
- }
-}
-
-func TestLinearInterpolationSmoothingModel(t *testing.T) {
- s := NewLinearInterpolationSmoothingModel(0.3, 0.2, 0.05)
- data, err := json.Marshal(s.Source())
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- // The source does NOT include the smoothing model type!
- expected := `{"bigram_lambda":0.2,"trigram_lambda":0.3,"unigram_lambda":0.05}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
- if s.Type() != "linear_interpolation" {
- t.Errorf("expected %q, got: %q", "linear_interpolation", s.Type())
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_term_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/suggester_term_test.go
deleted file mode 100644
index 6d71629214..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/suggester_term_test.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "testing"
-)
-
-func TestTermSuggesterSource(t *testing.T) {
- s := NewTermSuggester("name").
- Text("n").
- Field("suggest")
- data, err := json.Marshal(s.Source(true))
- if err != nil {
- t.Fatalf("marshaling to JSON failed: %v", err)
- }
- got := string(data)
- expected := `{"name":{"text":"n","term":{"field":"suggest"}}}`
- if got != expected {
- t.Errorf("expected\n%s\n,got:\n%s", expected, got)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/update_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/update_test.go
deleted file mode 100644
index fdb0d260cb..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/update_test.go
+++ /dev/null
@@ -1,344 +0,0 @@
-// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
-// Use of this source code is governed by a MIT-license.
-// See http://olivere.mit-license.org/license.txt for details.
-
-package elastic
-
-import (
- "encoding/json"
- "net/url"
- "testing"
- "time"
-)
-
-func TestUpdateViaScript(t *testing.T) {
- client := setupTestClient(t)
- update := client.Update().
- Index("test").Type("type1").Id("1").
- Script("ctx._source.tags += tag").
- ScriptParams(map[string]interface{}{"tag": "blue"}).
- ScriptLang("groovy")
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/test/type1/1/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"lang":"groovy","params":{"tag":"blue"},"script":"ctx._source.tags += tag"}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaScriptId(t *testing.T) {
- client := setupTestClient(t)
-
- scriptParams := map[string]interface{}{
- "pageViewEvent": map[string]interface{}{
- "url": "foo.com/bar",
- "response": 404,
- "time": "2014-01-01 12:32",
- },
- }
-
- update := client.Update().
- Index("sessions").Type("session").Id("dh3sgudg8gsrgl").
- ScriptId("my_web_session_summariser").
- ScriptedUpsert(true).
- ScriptParams(scriptParams).
- Upsert(map[string]interface{}{})
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/sessions/session/dh3sgudg8gsrgl/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"params":{"pageViewEvent":{"response":404,"time":"2014-01-01 12:32","url":"foo.com/bar"}},"script_id":"my_web_session_summariser","scripted_upsert":true,"upsert":{}}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaScriptFile(t *testing.T) {
- client := setupTestClient(t)
-
- scriptParams := map[string]interface{}{
- "pageViewEvent": map[string]interface{}{
- "url": "foo.com/bar",
- "response": 404,
- "time": "2014-01-01 12:32",
- },
- }
-
- update := client.Update().
- Index("sessions").Type("session").Id("dh3sgudg8gsrgl").
- ScriptFile("update_script").
- ScriptedUpsert(true).
- ScriptParams(scriptParams).
- Upsert(map[string]interface{}{})
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/sessions/session/dh3sgudg8gsrgl/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"params":{"pageViewEvent":{"response":404,"time":"2014-01-01 12:32","url":"foo.com/bar"}},"script_file":"update_script","scripted_upsert":true,"upsert":{}}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaScriptAndUpsert(t *testing.T) {
- client := setupTestClient(t)
- update := client.Update().
- Index("test").Type("type1").Id("1").
- Script("ctx._source.counter += count").
- ScriptParams(map[string]interface{}{"count": 4}).
- Upsert(map[string]interface{}{"counter": 1})
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/test/type1/1/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"params":{"count":4},"script":"ctx._source.counter += count","upsert":{"counter":1}}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaDoc(t *testing.T) {
- client := setupTestClient(t)
- update := client.Update().
- Index("test").Type("type1").Id("1").
- Doc(map[string]interface{}{"name": "new_name"}).
- DetectNoop(true)
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/test/type1/1/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"detect_noop":true,"doc":{"name":"new_name"}}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaDocAndUpsert(t *testing.T) {
- client := setupTestClient(t)
- update := client.Update().
- Index("test").Type("type1").Id("1").
- Doc(map[string]interface{}{"name": "new_name"}).
- DocAsUpsert(true).
- Timeout("1s").
- Refresh(true)
- path, params, err := update.url()
- if err != nil {
- t.Fatalf("expected to return URL, got: %v", err)
- }
- expectedPath := `/test/type1/1/_update`
- if expectedPath != path {
- t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path)
- }
- expectedParams := url.Values{"refresh": []string{"true"}, "timeout": []string{"1s"}}
- if expectedParams.Encode() != params.Encode() {
- t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode())
- }
- body, err := update.body()
- if err != nil {
- t.Fatalf("expected to return body, got: %v", err)
- }
- data, err := json.Marshal(body)
- if err != nil {
- t.Fatalf("expected to marshal body as JSON, got: %v", err)
- }
- got := string(data)
- expected := `{"doc":{"name":"new_name"},"doc_as_upsert":true}`
- if got != expected {
- t.Errorf("expected\n%s\ngot:\n%s", expected, got)
- }
-}
-
-func TestUpdateViaScriptIntegration(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- esversion, err := client.ElasticsearchVersion(DefaultURL)
- if err != nil {
- t.Fatal(err)
- }
- if esversion >= "1.4.3" || (esversion < "1.4.0" && esversion >= "1.3.8") {
- t.Skip("groovy scripting has been disabled as for [1.3.8,1.4.0) and 1.4.3+")
- return
- }
-
- tweet1 := tweet{User: "olivere", Retweets: 10, Message: "Welcome to Golang and Elasticsearch."}
-
- // Add a document
- indexResult, err := client.Index().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- BodyJson(&tweet1).
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if indexResult == nil {
- t.Errorf("expected result to be != nil; got: %v", indexResult)
- }
-
- // Update number of retweets
- increment := 1
- update, err := client.Update().Index(testIndexName).Type("tweet").Id("1").
- Script("ctx._source.retweets += num").
- ScriptParams(map[string]interface{}{"num": increment}).
- ScriptLang("groovy"). // Use "groovy" as default language as 1.3 uses MVEL by default
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if update == nil {
- t.Errorf("expected update to be != nil; got %v", update)
- }
- if update.Version != indexResult.Version+1 {
- t.Errorf("expected version to be %d; got %d", indexResult.Version+1, update.Version)
- }
-
- // Get document
- getResult, err := client.Get().
- Index(testIndexName).
- Type("tweet").
- Id("1").
- Do()
- if err != nil {
- t.Fatal(err)
- }
- if getResult.Index != testIndexName {
- t.Errorf("expected GetResult.Index %q; got %q", testIndexName, getResult.Index)
- }
- if getResult.Type != "tweet" {
- t.Errorf("expected GetResult.Type %q; got %q", "tweet", getResult.Type)
- }
- if getResult.Id != "1" {
- t.Errorf("expected GetResult.Id %q; got %q", "1", getResult.Id)
- }
- if getResult.Source == nil {
- t.Errorf("expected GetResult.Source to be != nil; got nil")
- }
-
- // Decode the Source field
- var tweetGot tweet
- err = json.Unmarshal(*getResult.Source, &tweetGot)
- if err != nil {
- t.Fatal(err)
- }
- if tweetGot.Retweets != tweet1.Retweets+increment {
- t.Errorf("expected Tweet.Retweets to be %d; got %d", tweet1.Retweets+increment, tweetGot.Retweets)
- }
-}
-
-func TestUpdateReturnsErrorOnFailure(t *testing.T) {
- client := setupTestClientAndCreateIndex(t)
-
- // Travis lags sometimes
- if isTravis() {
- time.Sleep(2 * time.Second)
- }
-
- // Ensure that no tweet with id #1 exists
- exists, err := client.Exists().Index(testIndexName).Type("tweet").Id("1").Do()
- if err != nil {
- t.Fatal(err)
- }
- if exists {
- t.Fatalf("expected no document; got: %v", exists)
- }
-
- // Update (non-existent) tweet with id #1
- update, err := client.Update().
- Index(testIndexName).Type("tweet").Id("1").
- Doc(map[string]interface{}{"retweets": 42}).
- Do()
- if err == nil {
- t.Fatalf("expected error to be != nil; got: %v", err)
- }
- if update != nil {
- t.Fatalf("expected update to be == nil; got %v", update)
- }
-}
diff --git a/Godeps/_workspace/src/github.com/olivere/elastic/uritemplates/utils_test.go b/Godeps/_workspace/src/github.com/olivere/elastic/uritemplates/utils_test.go
deleted file mode 100644
index 633949b6fc..0000000000
--- a/Godeps/_workspace/src/github.com/olivere/elastic/uritemplates/utils_test.go
+++ /dev/null
@@ -1,105 +0,0 @@
-package uritemplates
-
-import (
- "testing"
-)
-
-type ExpandTest struct {
- in string
- expansions map[string]string
- want string
-}
-
-var expandTests = []ExpandTest{
- // #0: no expansions
- {
- "http://www.golang.org/",
- map[string]string{},
- "http://www.golang.org/",
- },
- // #1: one expansion, no escaping
- {
- "http://www.golang.org/{bucket}/delete",
- map[string]string{
- "bucket": "red",
- },
- "http://www.golang.org/red/delete",
- },
- // #2: one expansion, with hex escapes
- {
- "http://www.golang.org/{bucket}/delete",
- map[string]string{
- "bucket": "red/blue",
- },
- "http://www.golang.org/red%2Fblue/delete",
- },
- // #3: one expansion, with space
- {
- "http://www.golang.org/{bucket}/delete",
- map[string]string{
- "bucket": "red or blue",
- },
- "http://www.golang.org/red%20or%20blue/delete",
- },
- // #4: expansion not found
- {
- "http://www.golang.org/{object}/delete",
- map[string]string{
- "bucket": "red or blue",
- },
- "http://www.golang.org//delete",
- },
- // #5: multiple expansions
- {
- "http://www.golang.org/{one}/{two}/{three}/get",
- map[string]string{
- "one": "ONE",
- "two": "TWO",
- "three": "THREE",
- },
- "http://www.golang.org/ONE/TWO/THREE/get",
- },
- // #6: utf-8 characters
- {
- "http://www.golang.org/{bucket}/get",
- map[string]string{
- "bucket": "£100",
- },
- "http://www.golang.org/%C2%A3100/get",
- },
- // #7: punctuations
- {
- "http://www.golang.org/{bucket}/get",
- map[string]string{
- "bucket": `/\@:,.*~`,
- },
- "http://www.golang.org/%2F%5C%40%3A%2C.%2A~/get",
- },
- // #8: mis-matched brackets
- {
- "http://www.golang.org/{bucket/get",
- map[string]string{
- "bucket": "red",
- },
- "",
- },
- // #9: "+" prefix for suppressing escape
- // See also: http://tools.ietf.org/html/rfc6570#section-3.2.3
- {
- "http://www.golang.org/{+topic}",
- map[string]string{
- "topic": "/topics/myproject/mytopic",
- },
- // The double slashes here look weird, but it's intentional
- "http://www.golang.org//topics/myproject/mytopic",
- },
-}
-
-func TestExpand(t *testing.T) {
- for i, test := range expandTests {
- got, _ := Expand(test.in, test.expansions)
- if got != test.want {
- t.Errorf("got %q expected %q in test %d", got, test.want, i)
- }
- }
-}