diff --git a/test/integration_test.go b/test/integration_test.go index 7dd2cf89..ea9d0b9c 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -139,5 +139,10 @@ func runTestDir(t *testing.T, dir string) { } } } + if search.Result.Facets != nil { + if !reflect.DeepEqual(search.Result.Facets, res.Facets) { + t.Errorf("expected facets: %#v got %#v", search.Result.Facets, res.Facets) + } + } } } diff --git a/test/tests/facet/data/a.json b/test/tests/facet/data/a.json new file mode 100644 index 00000000..777b21f9 --- /dev/null +++ b/test/tests/facet/data/a.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "book", + "rating": 2, + "updated": "2014-11-25" +} \ No newline at end of file diff --git a/test/tests/facet/data/b.json b/test/tests/facet/data/b.json new file mode 100644 index 00000000..c3c2c696 --- /dev/null +++ b/test/tests/facet/data/b.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "book", + "rating": 7, + "updated": "2013-07-25" +} \ No newline at end of file diff --git a/test/tests/facet/data/c.json b/test/tests/facet/data/c.json new file mode 100644 index 00000000..da3542cc --- /dev/null +++ b/test/tests/facet/data/c.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "book", + "rating": 1, + "updated": "2014-03-03" +} \ No newline at end of file diff --git a/test/tests/facet/data/d.json b/test/tests/facet/data/d.json new file mode 100644 index 00000000..20aaef1f --- /dev/null +++ b/test/tests/facet/data/d.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "book", + "rating": 9, + "updated": "2014-09-16" +} \ No newline at end of file diff --git a/test/tests/facet/data/e.json b/test/tests/facet/data/e.json new file mode 100644 index 00000000..8dbd28a8 --- /dev/null +++ b/test/tests/facet/data/e.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "book", + "rating": 5, + "updated": "2014-11-15" +} \ No newline at end of file diff --git a/test/tests/facet/data/f.json b/test/tests/facet/data/f.json new file mode 100644 index 00000000..74e8cd21 --- /dev/null +++ b/test/tests/facet/data/f.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "movie", + "rating": 3, + "updated": "2017-06-05" +} \ No newline at end of file diff --git a/test/tests/facet/data/g.json b/test/tests/facet/data/g.json new file mode 100644 index 00000000..ea5f29fc --- /dev/null +++ b/test/tests/facet/data/g.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "movie", + "rating": 9, + "updated": "2011-10-03" +} \ No newline at end of file diff --git a/test/tests/facet/data/h.json b/test/tests/facet/data/h.json new file mode 100644 index 00000000..f91c0d78 --- /dev/null +++ b/test/tests/facet/data/h.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "movie", + "rating": 9, + "updated": "2019-08-26" +} \ No newline at end of file diff --git a/test/tests/facet/data/i.json b/test/tests/facet/data/i.json new file mode 100644 index 00000000..e46e5b70 --- /dev/null +++ b/test/tests/facet/data/i.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "movie", + "rating": 1, + "updated": "2014-12-14" +} \ No newline at end of file diff --git a/test/tests/facet/data/j.json b/test/tests/facet/data/j.json new file mode 100644 index 00000000..263f07b5 --- /dev/null +++ b/test/tests/facet/data/j.json @@ -0,0 +1,6 @@ +{ + "category": "inventory", + "type": "game", + "rating": 9, + "updated": "2013-10-20" +} \ No newline at end of file diff --git a/test/tests/facet/mapping.json b/test/tests/facet/mapping.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/test/tests/facet/mapping.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/tests/facet/searches.json b/test/tests/facet/searches.json new file mode 100644 index 00000000..6752282a --- /dev/null +++ b/test/tests/facet/searches.json @@ -0,0 +1,144 @@ +[ + { + "search": { + "from": 0, + "size": 0, + "query": { + "field": "category", + "term": "inventory" + }, + "facets": { + "types": { + "size": 3, + "field": "type" + } + } + }, + "result": { + "total_hits": 10, + "hits": [], + "facets": { + "types": { + "field": "type", + "total": 10, + "missing": 0, + "other": 0, + "terms": [ + { + "term": "book", + "count": 5 + }, + { + "term": "movie", + "count": 4 + }, + { + "term": "game", + "count": 1 + } + ] + } + } + } + }, + { + "search": { + "from": 0, + "size": 0, + "query": { + "field": "category", + "term": "inventory" + }, + "facets": { + "types": { + "size": 3, + "field": "rating", + "numeric_ranges": [ + { + "name": "low", + "max": 5 + }, + { + "name": "high", + "min": 5 + } + ] + } + } + }, + "result": { + "total_hits": 10, + "hits": [], + "facets": { + "types": { + "field": "rating", + "total": 10, + "missing": 0, + "other": 0, + "numeric_ranges": [ + { + "name": "high", + "count": 6, + "min": 5 + }, + { + "name": "low", + "count": 4, + "max": 5 + } + ] + } + } + } + }, + { + "search": { + "from": 0, + "size": 0, + "query": { + "field": "category", + "term": "inventory" + }, + "facets": { + "types": { + "size": 3, + "field": "updated", + "date_ranges": [ + { + "name": "old", + "end": "2012-01-01" + }, + { + "name": "new", + "start": "2012-01-01" + } + ] + } + } + }, + "result": { + "total_hits": 10, + "hits": [], + "facets": { + "types": { + "field": "updated", + "total": 10, + "missing": 0, + "other": 0, + "date_ranges": [ + { + "name": "new", + "count": 9, + "start": "2012-01-01T00:00:00Z" + }, + { + "name": "old", + "count": 1, + "end": "2012-01-01T00:00:00Z" + } + ] + } + } + } + } +] \ No newline at end of file