opensearch-dsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +17 -0
- data/Gemfile +51 -0
- data/LICENSE +202 -0
- data/README.md +149 -0
- data/Rakefile +234 -0
- data/lib/opensearch/dsl/search/aggregation.rb +110 -0
- data/lib/opensearch/dsl/search/aggregations/avg.rb +51 -0
- data/lib/opensearch/dsl/search/aggregations/cardinality.rb +58 -0
- data/lib/opensearch/dsl/search/aggregations/children.rb +65 -0
- data/lib/opensearch/dsl/search/aggregations/composite.rb +68 -0
- data/lib/opensearch/dsl/search/aggregations/date_histogram.rb +66 -0
- data/lib/opensearch/dsl/search/aggregations/date_range.rb +60 -0
- data/lib/opensearch/dsl/search/aggregations/extended_stats.rb +50 -0
- data/lib/opensearch/dsl/search/aggregations/filter.rb +56 -0
- data/lib/opensearch/dsl/search/aggregations/filters.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/geo_bounds.rb +70 -0
- data/lib/opensearch/dsl/search/aggregations/geo_distance.rb +65 -0
- data/lib/opensearch/dsl/search/aggregations/geohash_grid.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/global.rb +54 -0
- data/lib/opensearch/dsl/search/aggregations/histogram.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/ip_range.rb +57 -0
- data/lib/opensearch/dsl/search/aggregations/max.rb +51 -0
- data/lib/opensearch/dsl/search/aggregations/min.rb +51 -0
- data/lib/opensearch/dsl/search/aggregations/missing.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/nested.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/percentile_ranks.rb +60 -0
- data/lib/opensearch/dsl/search/aggregations/percentiles.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/avg_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/bucket_script.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/bucket_selector.rb +60 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/bucket_sort.rb +114 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/cumulative_sum.rb +58 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/derivative.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/max_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/min_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/moving_avg.rb +67 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/serial_diff.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/stats_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/pipeline/sum_bucket.rb +59 -0
- data/lib/opensearch/dsl/search/aggregations/range.rb +79 -0
- data/lib/opensearch/dsl/search/aggregations/reverse_nested.rb +63 -0
- data/lib/opensearch/dsl/search/aggregations/scripted_metric.rb +65 -0
- data/lib/opensearch/dsl/search/aggregations/significant_terms.rb +71 -0
- data/lib/opensearch/dsl/search/aggregations/stats.rb +63 -0
- data/lib/opensearch/dsl/search/aggregations/sum.rb +51 -0
- data/lib/opensearch/dsl/search/aggregations/terms.rb +68 -0
- data/lib/opensearch/dsl/search/aggregations/top_hits.rb +61 -0
- data/lib/opensearch/dsl/search/aggregations/value_count.rb +51 -0
- data/lib/opensearch/dsl/search/base_aggregation_component.rb +90 -0
- data/lib/opensearch/dsl/search/base_component.rb +193 -0
- data/lib/opensearch/dsl/search/base_compound_filter_component.rb +123 -0
- data/lib/opensearch/dsl/search/filter.rb +81 -0
- data/lib/opensearch/dsl/search/filters/and.rb +71 -0
- data/lib/opensearch/dsl/search/filters/bool.rb +105 -0
- data/lib/opensearch/dsl/search/filters/exists.rb +58 -0
- data/lib/opensearch/dsl/search/filters/geo_bounding_box.rb +71 -0
- data/lib/opensearch/dsl/search/filters/geo_distance.rb +83 -0
- data/lib/opensearch/dsl/search/filters/geo_distance_range.rb +58 -0
- data/lib/opensearch/dsl/search/filters/geo_polygon.rb +67 -0
- data/lib/opensearch/dsl/search/filters/geo_shape.rb +61 -0
- data/lib/opensearch/dsl/search/filters/geohash_cell.rb +72 -0
- data/lib/opensearch/dsl/search/filters/has_child.rb +100 -0
- data/lib/opensearch/dsl/search/filters/has_parent.rb +99 -0
- data/lib/opensearch/dsl/search/filters/ids.rb +58 -0
- data/lib/opensearch/dsl/search/filters/indices.rb +103 -0
- data/lib/opensearch/dsl/search/filters/limit.rb +57 -0
- data/lib/opensearch/dsl/search/filters/match_all.rb +54 -0
- data/lib/opensearch/dsl/search/filters/missing.rb +60 -0
- data/lib/opensearch/dsl/search/filters/nested.rb +93 -0
- data/lib/opensearch/dsl/search/filters/not.rb +99 -0
- data/lib/opensearch/dsl/search/filters/or.rb +71 -0
- data/lib/opensearch/dsl/search/filters/prefix.rb +55 -0
- data/lib/opensearch/dsl/search/filters/query.rb +80 -0
- data/lib/opensearch/dsl/search/filters/range.rb +65 -0
- data/lib/opensearch/dsl/search/filters/regexp.rb +60 -0
- data/lib/opensearch/dsl/search/filters/script.rb +58 -0
- data/lib/opensearch/dsl/search/filters/term.rb +57 -0
- data/lib/opensearch/dsl/search/filters/terms.rb +58 -0
- data/lib/opensearch/dsl/search/filters/type.rb +60 -0
- data/lib/opensearch/dsl/search/highlight.rb +117 -0
- data/lib/opensearch/dsl/search/options.rb +81 -0
- data/lib/opensearch/dsl/search/queries/bool.rb +111 -0
- data/lib/opensearch/dsl/search/queries/boosting.rb +59 -0
- data/lib/opensearch/dsl/search/queries/common.rb +64 -0
- data/lib/opensearch/dsl/search/queries/constant_score.rb +92 -0
- data/lib/opensearch/dsl/search/queries/dis_max.rb +61 -0
- data/lib/opensearch/dsl/search/queries/exists.rb +69 -0
- data/lib/opensearch/dsl/search/queries/filtered.rb +103 -0
- data/lib/opensearch/dsl/search/queries/function_score.rb +128 -0
- data/lib/opensearch/dsl/search/queries/fuzzy.rb +71 -0
- data/lib/opensearch/dsl/search/queries/fuzzy_like_this.rb +63 -0
- data/lib/opensearch/dsl/search/queries/fuzzy_like_this_field.rb +62 -0
- data/lib/opensearch/dsl/search/queries/geo_shape.rb +56 -0
- data/lib/opensearch/dsl/search/queries/has_child.rb +84 -0
- data/lib/opensearch/dsl/search/queries/has_parent.rb +84 -0
- data/lib/opensearch/dsl/search/queries/ids.rb +54 -0
- data/lib/opensearch/dsl/search/queries/indices.rb +60 -0
- data/lib/opensearch/dsl/search/queries/match.rb +69 -0
- data/lib/opensearch/dsl/search/queries/match_all.rb +52 -0
- data/lib/opensearch/dsl/search/queries/match_phrase.rb +58 -0
- data/lib/opensearch/dsl/search/queries/match_phrase_prefix.rb +57 -0
- data/lib/opensearch/dsl/search/queries/more_like_this.rb +90 -0
- data/lib/opensearch/dsl/search/queries/multi_match.rb +71 -0
- data/lib/opensearch/dsl/search/queries/nested.rb +82 -0
- data/lib/opensearch/dsl/search/queries/prefix.rb +56 -0
- data/lib/opensearch/dsl/search/queries/query_string.rb +77 -0
- data/lib/opensearch/dsl/search/queries/range.rb +73 -0
- data/lib/opensearch/dsl/search/queries/regexp.rb +57 -0
- data/lib/opensearch/dsl/search/queries/simple_query_string.rb +66 -0
- data/lib/opensearch/dsl/search/queries/span_first.rb +54 -0
- data/lib/opensearch/dsl/search/queries/span_multi.rb +54 -0
- data/lib/opensearch/dsl/search/queries/span_near.rb +58 -0
- data/lib/opensearch/dsl/search/queries/span_not.rb +59 -0
- data/lib/opensearch/dsl/search/queries/span_or.rb +54 -0
- data/lib/opensearch/dsl/search/queries/span_term.rb +52 -0
- data/lib/opensearch/dsl/search/queries/template.rb +57 -0
- data/lib/opensearch/dsl/search/queries/term.rb +52 -0
- data/lib/opensearch/dsl/search/queries/terms.rb +53 -0
- data/lib/opensearch/dsl/search/queries/top_children.rb +84 -0
- data/lib/opensearch/dsl/search/queries/wildcard.rb +56 -0
- data/lib/opensearch/dsl/search/query.rb +80 -0
- data/lib/opensearch/dsl/search/sort.rb +84 -0
- data/lib/opensearch/dsl/search/suggest.rb +53 -0
- data/lib/opensearch/dsl/search.rb +288 -0
- data/lib/opensearch/dsl/utils.rb +51 -0
- data/lib/opensearch/dsl/version.rb +31 -0
- data/lib/opensearch/dsl.rb +72 -0
- data/lib/opensearch-dsl.rb +27 -0
- data/opensearch-dsl.gemspec +81 -0
- data/spec/opensearch/dsl/search/aggregations/avg_spec.rb +52 -0
- data/spec/opensearch/dsl/search/aggregations/cardinality_spec.rb +119 -0
- data/spec/opensearch/dsl/search/aggregations/children_spec.rb +75 -0
- data/spec/opensearch/dsl/search/aggregations/composite_spec.rb +108 -0
- data/spec/opensearch/dsl/search/aggregations/date_histogram_spec.rb +198 -0
- data/spec/opensearch/dsl/search/aggregations/date_range_spec.rb +98 -0
- data/spec/opensearch/dsl/search/aggregations/extended_stats_spec.rb +52 -0
- data/spec/opensearch/dsl/search/aggregations/filter_spec.rb +57 -0
- data/spec/opensearch/dsl/search/aggregations/filters_spec.rb +98 -0
- data/spec/opensearch/dsl/search/aggregations/geo_bounds_spec.rb +86 -0
- data/spec/opensearch/dsl/search/aggregations/geo_distance_spec.rb +122 -0
- data/spec/opensearch/dsl/search/aggregations/geo_grid_spec.rb +109 -0
- data/spec/opensearch/dsl/search/aggregations/global_spec.rb +71 -0
- data/spec/opensearch/dsl/search/aggregations/historgram_spec.rb +131 -0
- data/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb +102 -0
- data/spec/opensearch/dsl/search/aggregations/max_spec.rb +52 -0
- data/spec/opensearch/dsl/search/aggregations/min_spec.rb +52 -0
- data/spec/opensearch/dsl/search/aggregations/missing_spec.rb +90 -0
- data/spec/opensearch/dsl/search/aggregations/nested_spec.rb +95 -0
- data/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb +135 -0
- data/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb +134 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/avg_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/bucket_script_spec.rb +108 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/bucket_selector_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb +113 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/cumulative_sum_spec.rb +86 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/derivative_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/max_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/min_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/moving_avg_test_spec.rb +141 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket_spec.rb +108 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/serial_diff_spec.rb +108 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/stats_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/pipeline/sum_bucket_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/range_spec.rb +128 -0
- data/spec/opensearch/dsl/search/aggregations/reverse_nested_spec.rb +41 -0
- data/spec/opensearch/dsl/search/aggregations/scripted_metric_spec.rb +130 -0
- data/spec/opensearch/dsl/search/aggregations/significant_terms_spec.rb +185 -0
- data/spec/opensearch/dsl/search/aggregations/stats_spec.rb +65 -0
- data/spec/opensearch/dsl/search/aggregations/sum_spec.rb +52 -0
- data/spec/opensearch/dsl/search/aggregations/terms_spec.rb +174 -0
- data/spec/opensearch/dsl/search/aggregations/top_hits_spec.rb +97 -0
- data/spec/opensearch/dsl/search/aggregations/value_count_spec.rb +52 -0
- data/spec/opensearch/dsl/search/filters/and_spec.rb +83 -0
- data/spec/opensearch/dsl/search/filters/bool_spec.rb +208 -0
- data/spec/opensearch/dsl/search/filters/exists_spec.rb +75 -0
- data/spec/opensearch/dsl/search/filters/geo_bounding_box_spec.rb +153 -0
- data/spec/opensearch/dsl/search/filters/geo_distance_range_spec.rb +112 -0
- data/spec/opensearch/dsl/search/filters/geo_distance_spec.rb +135 -0
- data/spec/opensearch/dsl/search/filters/geo_polygon_spec.rb +75 -0
- data/spec/opensearch/dsl/search/filters/geo_shape_spec.rb +86 -0
- data/spec/opensearch/dsl/search/filters/geohash_cell_spec.rb +108 -0
- data/spec/opensearch/dsl/search/filters/has_child_spec.rb +148 -0
- data/spec/opensearch/dsl/search/filters/has_parent_spec.rb +137 -0
- data/spec/opensearch/dsl/search/filters/ids_spec.rb +87 -0
- data/spec/opensearch/dsl/search/filters/indices_spec.rb +118 -0
- data/spec/opensearch/dsl/search/filters/limit_spec.rb +75 -0
- data/spec/opensearch/dsl/search/filters/match_all_spec.rb +41 -0
- data/spec/opensearch/dsl/search/filters/missing_spec.rb +75 -0
- data/spec/opensearch/dsl/search/filters/nested_spec.rb +100 -0
- data/spec/opensearch/dsl/search/filters/not_spec.rb +68 -0
- data/spec/opensearch/dsl/search/filters/or_spec.rb +84 -0
- data/spec/opensearch/dsl/search/filters/prefix_spec.rb +55 -0
- data/spec/opensearch/dsl/search/filters/query_spec.rb +68 -0
- data/spec/opensearch/dsl/search/filters/range_spec.rb +120 -0
- data/spec/opensearch/dsl/search/filters/regexp_spec.rb +97 -0
- data/spec/opensearch/dsl/search/filters/script_spec.rb +86 -0
- data/spec/opensearch/dsl/search/filters/term_spec.rb +66 -0
- data/spec/opensearch/dsl/search/filters/terms_spec.rb +55 -0
- data/spec/opensearch/dsl/search/filters/type_spec.rb +75 -0
- data/spec/opensearch/dsl/search/queries/bool_spec.rb +276 -0
- data/spec/opensearch/dsl/search/queries/boosting_spec.rb +99 -0
- data/spec/opensearch/dsl/search/queries/common_spec.rb +141 -0
- data/spec/opensearch/dsl/search/queries/constant_score_spec.rb +99 -0
- data/spec/opensearch/dsl/search/queries/dis_max_spec.rb +97 -0
- data/spec/opensearch/dsl/search/queries/exists_spec.rb +75 -0
- data/spec/opensearch/dsl/search/queries/filtered_spec.rb +102 -0
- data/spec/opensearch/dsl/search/queries/function_score_spec.rb +173 -0
- data/spec/opensearch/dsl/search/queries/fuzzy_like_this_field_spec.rb +141 -0
- data/spec/opensearch/dsl/search/queries/fuzzy_like_this_spec.rb +143 -0
- data/spec/opensearch/dsl/search/queries/fuzzy_spec.rb +119 -0
- data/spec/opensearch/dsl/search/queries/geo_shape_spec.rb +86 -0
- data/spec/opensearch/dsl/search/queries/has_child_spec.rb +135 -0
- data/spec/opensearch/dsl/search/queries/has_parent_spec.rb +109 -0
- data/spec/opensearch/dsl/search/queries/ids_spec.rb +87 -0
- data/spec/opensearch/dsl/search/queries/indices_spec.rb +98 -0
- data/spec/opensearch/dsl/search/queries/match_all_spec.rb +75 -0
- data/spec/opensearch/dsl/search/queries/match_phrase_prefix_spec.rb +112 -0
- data/spec/opensearch/dsl/search/queries/match_phrase_spec.rb +123 -0
- data/spec/opensearch/dsl/search/queries/match_spec.rb +116 -0
- data/spec/opensearch/dsl/search/queries/more_like_this_spec.rb +96 -0
- data/spec/opensearch/dsl/search/queries/multi_match_spec.rb +83 -0
- data/spec/opensearch/dsl/search/queries/nested_spec.rb +107 -0
- data/spec/opensearch/dsl/search/queries/prefix_spec.rb +79 -0
- data/spec/opensearch/dsl/search/queries/query_string_spec.rb +98 -0
- data/spec/opensearch/dsl/search/queries/range_spec.rb +87 -0
- data/spec/opensearch/dsl/search/queries/regexp_spec.rb +91 -0
- data/spec/opensearch/dsl/search/queries/simple_query_string_spec.rb +83 -0
- data/spec/opensearch/dsl/search/queries/span_first_spec.rb +78 -0
- data/spec/opensearch/dsl/search/queries/span_multi_spec.rb +78 -0
- data/spec/opensearch/dsl/search/queries/span_near_spec.rb +81 -0
- data/spec/opensearch/dsl/search/queries/span_not_spec.rb +82 -0
- data/spec/opensearch/dsl/search/queries/span_or_spec.rb +78 -0
- data/spec/opensearch/dsl/search/queries/span_term_spec.rb +55 -0
- data/spec/opensearch/dsl/search/queries/template_spec.rb +93 -0
- data/spec/opensearch/dsl/search/queries/term_spec.rb +66 -0
- data/spec/opensearch/dsl/search/queries/terms_spec.rb +55 -0
- data/spec/opensearch/dsl/search/queries/top_children_spec.rb +102 -0
- data/spec/opensearch/dsl/search/queries/wildcard_spec.rb +90 -0
- data/spec/spec_helper.rb +33 -0
- data/test/integration/search_aggregation_children_test.rb +91 -0
- data/test/integration/search_aggregation_geo_test.rb +111 -0
- data/test/integration/search_aggregation_nested_test.rb +128 -0
- data/test/integration/search_aggregations_test.rb +287 -0
- data/test/integration/search_filters_test.rb +290 -0
- data/test/integration/search_options_test.rb +54 -0
- data/test/integration/search_query_test.rb +99 -0
- data/test/integration/search_size_from_test.rb +71 -0
- data/test/integration/search_sort_test.rb +58 -0
- data/test/integration/search_suggest_test.rb +103 -0
- data/test/integration/search_test.rb +82 -0
- data/test/test_helper.rb +95 -0
- data/test/unit/dsl_test.rb +44 -0
- data/test/unit/search_aggregation_test.rb +98 -0
- data/test/unit/search_base_aggregation_component_test.rb +67 -0
- data/test/unit/search_base_component_test.rb +212 -0
- data/test/unit/search_filter_test.rb +87 -0
- data/test/unit/search_highlight_test.rb +103 -0
- data/test/unit/search_options_test.rb +114 -0
- data/test/unit/search_query_test.rb +91 -0
- data/test/unit/search_size_from_test.rb +69 -0
- data/test/unit/search_sort_test.rb +91 -0
- data/test/unit/search_suggest_test.rb +46 -0
- data/test/unit/search_test.rb +270 -0
- data/test/unit/utils_test.rb +47 -0
- data.tar.gz.sig +3 -0
- metadata +654 -0
- metadata.gz.sig +0 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
#
|
10
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
11
|
+
# license agreements. See the NOTICE file distributed with
|
12
|
+
# this work for additional information regarding copyright
|
13
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
14
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
15
|
+
# not use this file except in compliance with the License.
|
16
|
+
# You may obtain a copy of the License at
|
17
|
+
#
|
18
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
#
|
20
|
+
# Unless required by applicable law or agreed to in writing,
|
21
|
+
# software distributed under the License is distributed on an
|
22
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
23
|
+
# KIND, either express or implied. See the License for the
|
24
|
+
# specific language governing permissions and limitations
|
25
|
+
# under the License.
|
26
|
+
|
27
|
+
require 'opensearch'
|
28
|
+
require 'opensearch-dsl'
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.formatter = 'documentation'
|
32
|
+
config.color = true
|
33
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
#
|
10
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
11
|
+
# license agreements. See the NOTICE file distributed with
|
12
|
+
# this work for additional information regarding copyright
|
13
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
14
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
15
|
+
# not use this file except in compliance with the License.
|
16
|
+
# You may obtain a copy of the License at
|
17
|
+
#
|
18
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
#
|
20
|
+
# Unless required by applicable law or agreed to in writing,
|
21
|
+
# software distributed under the License is distributed on an
|
22
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
23
|
+
# KIND, either express or implied. See the License for the
|
24
|
+
# specific language governing permissions and limitations
|
25
|
+
# under the License.
|
26
|
+
|
27
|
+
require 'test_helper'
|
28
|
+
|
29
|
+
module OpenSearch
|
30
|
+
module Test
|
31
|
+
class ChildrenAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
32
|
+
include OpenSearch::DSL::Search
|
33
|
+
|
34
|
+
context "A children aggregation" do
|
35
|
+
|
36
|
+
setup do
|
37
|
+
@client.indices.create index: 'articles-and-comments', body: {
|
38
|
+
mappings: {
|
39
|
+
properties: {
|
40
|
+
title: {type: 'text'},
|
41
|
+
category: {type: 'keyword'},
|
42
|
+
join_field: {type: 'join', relations: {article: 'comment'}},
|
43
|
+
author: {type: 'keyword'}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
@client.index index: 'articles-and-comments', id: 1,
|
49
|
+
body: { title: 'A', category: 'one', join_field: 'article' }
|
50
|
+
@client.index index: 'articles-and-comments', id: 2,
|
51
|
+
body: { title: 'B', category: 'one', join_field: 'article' }
|
52
|
+
@client.index index: 'articles-and-comments', id: 3,
|
53
|
+
body: { title: 'C', category: 'two', join_field: 'article' }
|
54
|
+
|
55
|
+
@client.index index: 'articles-and-comments', routing: '1',
|
56
|
+
body: { author: 'John', join_field: { name: 'comment', parent: 1 } }
|
57
|
+
@client.index index: 'articles-and-comments', routing: '1',
|
58
|
+
body: { author: 'Mary', join_field: { name: 'comment', parent: 1 } }
|
59
|
+
@client.index index: 'articles-and-comments', routing: '2',
|
60
|
+
body: { author: 'John', join_field: { name: 'comment', parent: 2 } }
|
61
|
+
@client.index index: 'articles-and-comments', routing: '2',
|
62
|
+
body: { author: 'Dave', join_field: { name: 'comment', parent: 2 } }
|
63
|
+
@client.index index: 'articles-and-comments', routing: '3',
|
64
|
+
body: { author: 'Ruth', join_field: { name: 'comment', parent: 3 } }
|
65
|
+
@client.indices.refresh index: 'articles-and-comments'
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return the top commenters per article category" do
|
69
|
+
response = @client.search index: 'articles-and-comments', size: 0, body: search {
|
70
|
+
aggregation :top_categories do
|
71
|
+
terms field: 'category' do
|
72
|
+
aggregation :comments do
|
73
|
+
children type: 'comment' do
|
74
|
+
aggregation :top_authors do
|
75
|
+
terms field: 'author'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
}.to_hash
|
82
|
+
|
83
|
+
assert_equal 'one', response['aggregations']['top_categories']['buckets'][0]['key']
|
84
|
+
assert_equal 3, response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'].size
|
85
|
+
assert_equal 'John', response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'][0]['key']
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
#
|
10
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
11
|
+
# license agreements. See the NOTICE file distributed with
|
12
|
+
# this work for additional information regarding copyright
|
13
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
14
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
15
|
+
# not use this file except in compliance with the License.
|
16
|
+
# You may obtain a copy of the License at
|
17
|
+
#
|
18
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
#
|
20
|
+
# Unless required by applicable law or agreed to in writing,
|
21
|
+
# software distributed under the License is distributed on an
|
22
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
23
|
+
# KIND, either express or implied. See the License for the
|
24
|
+
# specific language governing permissions and limitations
|
25
|
+
# under the License.
|
26
|
+
|
27
|
+
require 'test_helper'
|
28
|
+
|
29
|
+
module OpenSearch
|
30
|
+
module Test
|
31
|
+
class GeoAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
32
|
+
include OpenSearch::DSL::Search
|
33
|
+
|
34
|
+
context "A geo aggregation" do
|
35
|
+
|
36
|
+
setup do
|
37
|
+
@client.indices.create index: 'venues-test', body: {
|
38
|
+
mappings: {
|
39
|
+
properties: {
|
40
|
+
location: {type: 'geo_point'}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
@client.index index: 'venues-test',
|
45
|
+
body: { name: 'Space', location: "38.886214,1.403889" }
|
46
|
+
@client.index index: 'venues-test',
|
47
|
+
body: { name: 'Pacha', location: "38.9184427,1.4433646" }
|
48
|
+
@client.index index: 'venues-test',
|
49
|
+
body: { name: 'Amnesia', location: "38.948045,1.408341" }
|
50
|
+
@client.index index: 'venues-test',
|
51
|
+
body: { name: 'Privilege', location: "38.958082,1.408288" }
|
52
|
+
@client.index index: 'venues-test',
|
53
|
+
body: { name: 'Es Paradis', location: "38.979071,1.307394" }
|
54
|
+
@client.indices.refresh index: 'venues-test'
|
55
|
+
end
|
56
|
+
|
57
|
+
should "return the geo distances from a location" do
|
58
|
+
response = @client.search index: 'venues-test', size: 0, body: search {
|
59
|
+
aggregation :venue_distances do
|
60
|
+
geo_distance do
|
61
|
+
field :location
|
62
|
+
origin '38.9126352,1.4350621'
|
63
|
+
unit 'km'
|
64
|
+
ranges [ { to: 1 }, { from: 1, to: 5 }, { from: 5, to: 10 }, { from: 10 } ]
|
65
|
+
|
66
|
+
aggregation :top_venues do
|
67
|
+
top_hits _source: { include: 'name' }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
}.to_hash
|
72
|
+
|
73
|
+
result = response['aggregations']['venue_distances']
|
74
|
+
|
75
|
+
assert_equal 4, result['buckets'].size
|
76
|
+
assert_equal 1, result['buckets'][0]['doc_count']
|
77
|
+
assert_equal 'Pacha', result['buckets'][0]['top_venues']['hits']['hits'][0]['_source']['name']
|
78
|
+
|
79
|
+
assert_equal 2, result['buckets'][1]['top_venues']['hits']['total']['value']
|
80
|
+
end
|
81
|
+
|
82
|
+
should "return the geohash grid distribution" do
|
83
|
+
#
|
84
|
+
# See the geohash plot eg. at http://openlocation.org/geohash/geohash-js/
|
85
|
+
# See the locations visually eg. at http://geohash.org/sncj8h17r2
|
86
|
+
#
|
87
|
+
response = @client.search index: 'venues-test', size: 0, body: search {
|
88
|
+
aggregation :venue_distributions do
|
89
|
+
geohash_grid do
|
90
|
+
field :location
|
91
|
+
precision 5
|
92
|
+
|
93
|
+
aggregation :top_venues do
|
94
|
+
top_hits _source: { include: 'name' }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
}.to_hash
|
99
|
+
|
100
|
+
result = response['aggregations']['venue_distributions']
|
101
|
+
|
102
|
+
assert_equal 4, result['buckets'].size
|
103
|
+
assert_equal 'sncj8', result['buckets'][0]['key']
|
104
|
+
assert_equal 2, result['buckets'][0]['doc_count']
|
105
|
+
|
106
|
+
assert_same_elements %w[ Privilege Amnesia ], result['buckets'][0]['top_venues']['hits']['hits'].map { |h| h['_source']['name'] }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
#
|
10
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
11
|
+
# license agreements. See the NOTICE file distributed with
|
12
|
+
# this work for additional information regarding copyright
|
13
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
14
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
15
|
+
# not use this file except in compliance with the License.
|
16
|
+
# You may obtain a copy of the License at
|
17
|
+
#
|
18
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
#
|
20
|
+
# Unless required by applicable law or agreed to in writing,
|
21
|
+
# software distributed under the License is distributed on an
|
22
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
23
|
+
# KIND, either express or implied. See the License for the
|
24
|
+
# specific language governing permissions and limitations
|
25
|
+
# under the License.
|
26
|
+
|
27
|
+
require 'test_helper'
|
28
|
+
|
29
|
+
module OpenSearch
|
30
|
+
module Test
|
31
|
+
class NestedAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
32
|
+
include OpenSearch::DSL::Search
|
33
|
+
|
34
|
+
context "A nested aggregation" do
|
35
|
+
|
36
|
+
setup do
|
37
|
+
@client.indices.create index: 'products-test', body: {
|
38
|
+
mappings: {
|
39
|
+
properties: {
|
40
|
+
title: {type: 'text'},
|
41
|
+
category: {type: 'keyword'},
|
42
|
+
offers: {
|
43
|
+
type: 'nested',
|
44
|
+
properties: {
|
45
|
+
name: {type: 'text'},
|
46
|
+
price: {type: 'double'}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
@client.index index: 'products-test',
|
54
|
+
body: { title: 'A',
|
55
|
+
category: 'audio',
|
56
|
+
offers: [ { name: 'A1', price: 100 }, { name: 'A2', price: 120 } ] }
|
57
|
+
@client.index index: 'products-test',
|
58
|
+
body: { title: 'B',
|
59
|
+
category: 'audio',
|
60
|
+
offers: [ { name: 'B1', price: 200 }, { name: 'B2', price: 180 } ] }
|
61
|
+
@client.index index: 'products-test',
|
62
|
+
body: { title: 'C',
|
63
|
+
category: 'video',
|
64
|
+
offers: [ { name: 'C1', price: 300 }, { name: 'C2', price: 350 } ] }
|
65
|
+
@client.indices.refresh index: 'products-test'
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return the minimal price from offers" do
|
69
|
+
response = @client.search index: 'products-test', body: search {
|
70
|
+
query { match title: 'A' }
|
71
|
+
|
72
|
+
aggregation :offers do
|
73
|
+
nested do
|
74
|
+
path 'offers'
|
75
|
+
aggregation :min_price do
|
76
|
+
min field: 'offers.price'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
}.to_hash
|
81
|
+
|
82
|
+
assert_equal 100, response['aggregations']['offers']['min_price']['value'].to_i
|
83
|
+
end
|
84
|
+
|
85
|
+
should "return the top categories for offer price range" do
|
86
|
+
response = @client.search index: 'products-test', body: search {
|
87
|
+
query do
|
88
|
+
bool do
|
89
|
+
must do
|
90
|
+
nested do
|
91
|
+
path 'offers'
|
92
|
+
query do
|
93
|
+
bool do
|
94
|
+
filter do
|
95
|
+
range 'offers.price' do
|
96
|
+
gte 100
|
97
|
+
lte 300
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
aggregation :offers do
|
108
|
+
nested do
|
109
|
+
path 'offers'
|
110
|
+
aggregation :top_categories do
|
111
|
+
reverse_nested do
|
112
|
+
aggregation :top_category_per_offer do
|
113
|
+
terms field: 'category'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
}.to_hash
|
120
|
+
|
121
|
+
assert_equal 2, response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'].size
|
122
|
+
assert_equal 'audio', response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][0]['key']
|
123
|
+
assert_equal 'video', response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][1]['key']
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,287 @@
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
|
+
#
|
3
|
+
# The OpenSearch Contributors require contributions made to
|
4
|
+
# this file be licensed under the Apache-2.0 license or a
|
5
|
+
# compatible open source license.
|
6
|
+
#
|
7
|
+
# Modifications Copyright OpenSearch Contributors. See
|
8
|
+
# GitHub history for details.
|
9
|
+
#
|
10
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
11
|
+
# license agreements. See the NOTICE file distributed with
|
12
|
+
# this work for additional information regarding copyright
|
13
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
14
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
15
|
+
# not use this file except in compliance with the License.
|
16
|
+
# You may obtain a copy of the License at
|
17
|
+
#
|
18
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
19
|
+
#
|
20
|
+
# Unless required by applicable law or agreed to in writing,
|
21
|
+
# software distributed under the License is distributed on an
|
22
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
23
|
+
# KIND, either express or implied. See the License for the
|
24
|
+
# specific language governing permissions and limitations
|
25
|
+
# under the License.
|
26
|
+
|
27
|
+
require 'test_helper'
|
28
|
+
|
29
|
+
module OpenSearch
|
30
|
+
module Test
|
31
|
+
class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
32
|
+
include OpenSearch::DSL::Search
|
33
|
+
|
34
|
+
context "Aggregations integration" do
|
35
|
+
setup do
|
36
|
+
@client.indices.create index: 'test', body: {
|
37
|
+
mappings: {
|
38
|
+
properties: {
|
39
|
+
tags: {type: 'keyword'}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
@client.index index: 'test', id: '1', body: { title: 'A', tags: %w[one], clicks: 5 }
|
44
|
+
@client.index index: 'test', id: '2', body: { title: 'B', tags: %w[one two], clicks: 15 }
|
45
|
+
@client.index index: 'test', id: '3', body: { title: 'C', tags: %w[one three], clicks: 20 }
|
46
|
+
@client.indices.refresh index: 'test'
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a terms aggregation" do
|
50
|
+
should "return tag counts" do
|
51
|
+
response = @client.search index: 'test', body: search {
|
52
|
+
aggregation :tags do
|
53
|
+
terms field: 'tags'
|
54
|
+
end
|
55
|
+
}.to_hash
|
56
|
+
|
57
|
+
assert_equal 3, response['aggregations']['tags']['buckets'].size
|
58
|
+
assert_equal 'one', response['aggregations']['tags']['buckets'][0]['key']
|
59
|
+
end
|
60
|
+
|
61
|
+
should "return approximate tag counts" do
|
62
|
+
response = @client.search index: 'test', body: search {
|
63
|
+
aggregation :tags do
|
64
|
+
cardinality field: 'tags'
|
65
|
+
end
|
66
|
+
}.to_hash
|
67
|
+
|
68
|
+
assert_equal 3, response['aggregations']['tags']['value']
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return tag counts per clicks range as an inner (nested) aggregation" do
|
72
|
+
response = @client.search index: 'test', body: search {
|
73
|
+
aggregation :clicks do
|
74
|
+
range field: 'clicks' do
|
75
|
+
key :low, to: 10
|
76
|
+
key :mid, from: 10, to: 20
|
77
|
+
|
78
|
+
aggregation :tags do
|
79
|
+
terms field: 'tags'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
}.to_hash
|
84
|
+
|
85
|
+
assert_equal 2, response['aggregations']['clicks']['buckets'].size
|
86
|
+
assert_equal 1, response['aggregations']['clicks']['buckets']['low']['doc_count']
|
87
|
+
assert_equal 'one', response['aggregations']['clicks']['buckets']['low']['tags']['buckets'][0]['key']
|
88
|
+
end
|
89
|
+
|
90
|
+
should "define multiple aggregations" do
|
91
|
+
response = @client.search index: 'test', body: search {
|
92
|
+
aggregation :clicks do
|
93
|
+
range field: 'clicks' do
|
94
|
+
key :low, to: 10
|
95
|
+
key :mid, from: 10, to: 20
|
96
|
+
|
97
|
+
aggregation :tags do
|
98
|
+
terms { field 'tags' }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
aggregation :min_clicks do
|
104
|
+
min field: 'clicks'
|
105
|
+
end
|
106
|
+
|
107
|
+
aggregation :max_clicks do
|
108
|
+
max field: 'clicks'
|
109
|
+
end
|
110
|
+
|
111
|
+
aggregation :sum_clicks do
|
112
|
+
sum field: 'clicks'
|
113
|
+
end
|
114
|
+
|
115
|
+
aggregation :avg_clicks do
|
116
|
+
avg field: 'clicks'
|
117
|
+
end
|
118
|
+
}.to_hash
|
119
|
+
|
120
|
+
assert_equal 2, response['aggregations']['clicks']['buckets'].size
|
121
|
+
assert_equal 1, response['aggregations']['clicks']['buckets']['low']['doc_count']
|
122
|
+
assert_equal 'one', response['aggregations']['clicks']['buckets']['low']['tags']['buckets'][0]['key']
|
123
|
+
|
124
|
+
assert_equal 5, response['aggregations']['min_clicks']['value']
|
125
|
+
assert_equal 20, response['aggregations']['max_clicks']['value']
|
126
|
+
assert_equal 40, response['aggregations']['sum_clicks']['value']
|
127
|
+
assert_equal 13, response['aggregations']['avg_clicks']['value'].to_i
|
128
|
+
end
|
129
|
+
|
130
|
+
should "define a global aggregation" do
|
131
|
+
response = @client.search index: 'test', body: search {
|
132
|
+
query do
|
133
|
+
bool filter: { terms: { tags: ['two'] } }
|
134
|
+
end
|
135
|
+
|
136
|
+
aggregation :avg_clicks do
|
137
|
+
avg field: 'clicks'
|
138
|
+
end
|
139
|
+
|
140
|
+
aggregation :all_documents do
|
141
|
+
global do
|
142
|
+
aggregation :avg_clicks do
|
143
|
+
avg field: 'clicks'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
}.to_hash
|
148
|
+
|
149
|
+
assert_equal 15, response['aggregations']['avg_clicks']['value'].to_i
|
150
|
+
assert_equal 13, response['aggregations']['all_documents']['avg_clicks']['value'].to_i
|
151
|
+
end
|
152
|
+
|
153
|
+
should "return statistics on clicks" do
|
154
|
+
response = @client.search index: 'test', body: search {
|
155
|
+
aggregation :stats_clicks do
|
156
|
+
stats field: 'clicks'
|
157
|
+
end
|
158
|
+
aggregation :value_count do
|
159
|
+
value_count field: 'clicks'
|
160
|
+
end
|
161
|
+
}.to_hash
|
162
|
+
|
163
|
+
assert_equal 3, response['aggregations']['stats_clicks']['count']
|
164
|
+
assert_equal 5, response['aggregations']['stats_clicks']['min']
|
165
|
+
assert_equal 20, response['aggregations']['stats_clicks']['max']
|
166
|
+
assert_equal 40, response['aggregations']['stats_clicks']['sum']
|
167
|
+
assert_equal 13, response['aggregations']['stats_clicks']['avg'].to_i
|
168
|
+
assert_equal 3, response['aggregations']['value_count']['value']
|
169
|
+
end
|
170
|
+
|
171
|
+
should "return percentiles on clicks" do
|
172
|
+
response = @client.search index: 'test', body: search {
|
173
|
+
aggregation :percentiles do
|
174
|
+
percentiles field: 'clicks'
|
175
|
+
end
|
176
|
+
}.to_hash
|
177
|
+
|
178
|
+
assert_equal 20, response['aggregations']['percentiles']['values']['99.0'].round
|
179
|
+
end
|
180
|
+
|
181
|
+
should "return percentile ranks on clicks" do
|
182
|
+
response = @client.search index: 'test', body: search {
|
183
|
+
aggregation :percentiles do
|
184
|
+
percentile_ranks field: 'clicks', values: [5]
|
185
|
+
end
|
186
|
+
}.to_hash
|
187
|
+
|
188
|
+
assert_equal 17, response['aggregations']['percentiles']['values']['5.0'].round
|
189
|
+
end
|
190
|
+
|
191
|
+
should "return top hits per tag" do
|
192
|
+
response = @client.search index: 'test', body: search {
|
193
|
+
aggregation :tags do
|
194
|
+
terms do
|
195
|
+
field 'tags'
|
196
|
+
size 5
|
197
|
+
|
198
|
+
aggregation :top_hits do
|
199
|
+
top_hits sort: [ clicks: { order: 'desc' } ], _source: { include: 'title' }
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
}.to_hash
|
204
|
+
|
205
|
+
assert_equal 3, response['aggregations']['tags']['buckets'][0]['top_hits']['hits']['hits'].size
|
206
|
+
assert_equal 'C', response['aggregations']['tags']['buckets'][0]['top_hits']['hits']['hits'][0]['_source']['title']
|
207
|
+
end
|
208
|
+
|
209
|
+
should "calculate clicks for a tag" do
|
210
|
+
response = @client.search index: 'test', body: search {
|
211
|
+
aggregation :clicks_for_one do
|
212
|
+
scripted_metric do
|
213
|
+
init_script "state.transactions = []"
|
214
|
+
map_script "if (doc['tags'].value.contains('one')) { state.transactions.add(doc['clicks'].value) }"
|
215
|
+
combine_script "double sum = 0; for (t in state.transactions) { sum += t } return sum"
|
216
|
+
reduce_script "double sum = 0; for (a in states) { sum += a } return sum"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
}.to_hash
|
220
|
+
|
221
|
+
assert_equal 40, response['aggregations']['clicks_for_one']['value']
|
222
|
+
end
|
223
|
+
|
224
|
+
should "limit the scope with a filter" do
|
225
|
+
response = @client.search index: 'test', body: search {
|
226
|
+
aggregation :clicks_for_one do
|
227
|
+
filter terms: { tags: ['one'] } do
|
228
|
+
aggregation :sum_clicks do
|
229
|
+
sum field: 'clicks'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
}.to_hash
|
234
|
+
|
235
|
+
assert_equal 40, response['aggregations']['clicks_for_one']['sum_clicks']['value']
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
should "return aggregations for multiple filters" do
|
240
|
+
response = @client.search index: 'test', body: search {
|
241
|
+
aggregation :avg_clicks_per_tag do
|
242
|
+
filters do
|
243
|
+
filters one: { terms: { tags: ['one'] } },
|
244
|
+
two: { terms: { tags: ['two'] } }
|
245
|
+
aggregation :avg do
|
246
|
+
avg field: 'clicks'
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
}.to_hash
|
251
|
+
|
252
|
+
assert_equal 13, response['aggregations']['avg_clicks_per_tag']['buckets']['one']['avg']['value'].to_i
|
253
|
+
assert_equal 15, response['aggregations']['avg_clicks_per_tag']['buckets']['two']['avg']['value'].to_i
|
254
|
+
end
|
255
|
+
|
256
|
+
should "return a histogram on clicks" do
|
257
|
+
response = @client.search index: 'test', body: search {
|
258
|
+
aggregation :clicks_histogram do
|
259
|
+
histogram do
|
260
|
+
field 'clicks'
|
261
|
+
interval 10
|
262
|
+
end
|
263
|
+
end
|
264
|
+
}.to_hash
|
265
|
+
|
266
|
+
assert_equal 3, response['aggregations']['clicks_histogram']['buckets'].size
|
267
|
+
assert_equal 10, response['aggregations']['clicks_histogram']['buckets'][1]['key']
|
268
|
+
assert_equal 1, response['aggregations']['clicks_histogram']['buckets'][1]['doc_count']
|
269
|
+
end
|
270
|
+
|
271
|
+
should "return a histogram with empty buckets on clicks" do
|
272
|
+
response = @client.search index: 'test', body: search {
|
273
|
+
aggregation :clicks_histogram do
|
274
|
+
histogram do
|
275
|
+
field 'clicks'
|
276
|
+
interval 2
|
277
|
+
min_doc_count 0
|
278
|
+
end
|
279
|
+
end
|
280
|
+
}.to_hash
|
281
|
+
|
282
|
+
assert_equal 9, response['aggregations']['clicks_histogram']['buckets'].size
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|