opensearch-dsl 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
# encoding: UTF-8
|
|
28
|
+
|
|
29
|
+
require 'test_helper'
|
|
30
|
+
|
|
31
|
+
module OpenSearch
|
|
32
|
+
module Test
|
|
33
|
+
class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
34
|
+
include OpenSearch::DSL::Search
|
|
35
|
+
|
|
36
|
+
context "Filters integration" do
|
|
37
|
+
setup do
|
|
38
|
+
@client.indices.create index: 'test'
|
|
39
|
+
@client.index index: 'test', id: 1,
|
|
40
|
+
body: { name: 'Original',
|
|
41
|
+
color: 'red',
|
|
42
|
+
size: 'xxl',
|
|
43
|
+
category: 'unisex',
|
|
44
|
+
manufacturer: 'a' }
|
|
45
|
+
|
|
46
|
+
@client.index index: 'test', id: 2,
|
|
47
|
+
body: { name: 'Original',
|
|
48
|
+
color: 'red',
|
|
49
|
+
size: 'xl',
|
|
50
|
+
category: 'unisex',
|
|
51
|
+
manufacturer: 'a' }
|
|
52
|
+
|
|
53
|
+
@client.index index: 'test', id: 3,
|
|
54
|
+
body: { name: 'Original',
|
|
55
|
+
color: 'red',
|
|
56
|
+
size: 'l',
|
|
57
|
+
category: 'unisex',
|
|
58
|
+
manufacturer: 'a' }
|
|
59
|
+
|
|
60
|
+
@client.index index: 'test', id: 4,
|
|
61
|
+
body: { name: 'Western',
|
|
62
|
+
color: 'red',
|
|
63
|
+
size: 'm',
|
|
64
|
+
category: 'men',
|
|
65
|
+
manufacturer: 'c' }
|
|
66
|
+
|
|
67
|
+
@client.index index: 'test', id: 5,
|
|
68
|
+
body: { name: 'Modern',
|
|
69
|
+
color: 'grey',
|
|
70
|
+
size: 'l',
|
|
71
|
+
category: 'men',
|
|
72
|
+
manufacturer: 'b' }
|
|
73
|
+
|
|
74
|
+
@client.index index: 'test', id: 6,
|
|
75
|
+
body: { name: 'Modern',
|
|
76
|
+
color: 'grey',
|
|
77
|
+
size: 's',
|
|
78
|
+
category: 'men',
|
|
79
|
+
manufacturer: 'b' }
|
|
80
|
+
|
|
81
|
+
@client.index index: 'test', id: 7,
|
|
82
|
+
body: { name: 'Modern',
|
|
83
|
+
color: 'grey',
|
|
84
|
+
size: 's',
|
|
85
|
+
category: 'women',
|
|
86
|
+
manufacturer: 'b' }
|
|
87
|
+
|
|
88
|
+
@client.indices.refresh index: 'test'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "term filter" do
|
|
92
|
+
should "return matching documents" do
|
|
93
|
+
response = @client.search index: 'test', body: search {
|
|
94
|
+
query do
|
|
95
|
+
bool do
|
|
96
|
+
filter do
|
|
97
|
+
term color: 'red'
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
}.to_hash
|
|
102
|
+
|
|
103
|
+
assert_equal 4, response['hits']['total']['value']
|
|
104
|
+
assert response['hits']['hits'].all? { |h| h['_source']['color'] == 'red' }, response.inspect
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "terms filter" do
|
|
109
|
+
should "return matching documents" do
|
|
110
|
+
response = @client.search index: 'test', body: search {
|
|
111
|
+
query do
|
|
112
|
+
bool do
|
|
113
|
+
filter do
|
|
114
|
+
terms color: ['red', 'grey', 'gold']
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
}.to_hash
|
|
119
|
+
|
|
120
|
+
assert_equal 7, response['hits']['total']['value']
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "bool filter" do
|
|
125
|
+
should "return correct documents" do
|
|
126
|
+
response = @client.search index: 'test', body: search {
|
|
127
|
+
query do
|
|
128
|
+
bool do
|
|
129
|
+
filter do
|
|
130
|
+
bool do
|
|
131
|
+
must do
|
|
132
|
+
term size: 'l'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
should do
|
|
136
|
+
term color: 'red'
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should do
|
|
140
|
+
term category: 'men'
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
must_not do
|
|
144
|
+
term manufacturer: 'b'
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
}.to_hash
|
|
151
|
+
|
|
152
|
+
assert_equal 1, response['hits']['hits'].size
|
|
153
|
+
assert_equal '3', response['hits']['hits'][0]['_id'].to_s
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context "geographical filters" do
|
|
158
|
+
setup do
|
|
159
|
+
@client.indices.create index: 'places', body: {
|
|
160
|
+
mappings: {
|
|
161
|
+
properties: {
|
|
162
|
+
location: {
|
|
163
|
+
type: 'geo_point'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
@client.index index: 'places', id: 1,
|
|
169
|
+
body: { name: 'Vyšehrad',
|
|
170
|
+
location: '50.064399, 14.420018'}
|
|
171
|
+
|
|
172
|
+
@client.index index: 'places', id: 2,
|
|
173
|
+
body: { name: 'Karlštejn',
|
|
174
|
+
location: '49.939518, 14.188046'}
|
|
175
|
+
|
|
176
|
+
@client.indices.refresh index: 'places'
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
should "find documents within the bounding box" do
|
|
180
|
+
response = @client.search index: 'places', body: search {
|
|
181
|
+
query do
|
|
182
|
+
bool do
|
|
183
|
+
filter do
|
|
184
|
+
geo_bounding_box :location do
|
|
185
|
+
top_right "50.1815123678,14.7149200439"
|
|
186
|
+
bottom_left "49.9415476869,14.2162566185"
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
}.to_hash
|
|
192
|
+
|
|
193
|
+
assert_equal 1, response['hits']['hits'].size
|
|
194
|
+
assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
should "find documents within the distance specified with a hash" do
|
|
198
|
+
response = @client.search index: 'places', body: search {
|
|
199
|
+
query do
|
|
200
|
+
bool do
|
|
201
|
+
filter do
|
|
202
|
+
geo_distance location: '50.090223,14.399590', distance: '5km'
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
}.to_hash
|
|
207
|
+
|
|
208
|
+
assert_equal 1, response['hits']['hits'].size
|
|
209
|
+
assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
should "find documents within the distance specified with a block" do
|
|
213
|
+
response = @client.search index: 'places', body: search {
|
|
214
|
+
query do
|
|
215
|
+
bool do
|
|
216
|
+
filter do
|
|
217
|
+
geo_distance :location do
|
|
218
|
+
lat '50.090223'
|
|
219
|
+
lon '14.399590'
|
|
220
|
+
distance '5km'
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
}.to_hash
|
|
226
|
+
|
|
227
|
+
assert_equal 1, response['hits']['hits'].size
|
|
228
|
+
assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
should "find documents within the geographical distance range" do
|
|
232
|
+
response = @client.search index: 'places', body: search {
|
|
233
|
+
query do
|
|
234
|
+
bool do
|
|
235
|
+
filter do
|
|
236
|
+
geo_distance location: { lat: '50.090223', lon: '14.399590' },
|
|
237
|
+
distance: '50km'
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
aggregation :distance_ranges do
|
|
242
|
+
geo_distance do
|
|
243
|
+
field :location
|
|
244
|
+
origin '50.090223,14.399590'
|
|
245
|
+
unit 'km'
|
|
246
|
+
ranges [ { from: 10, to: 50 } ]
|
|
247
|
+
|
|
248
|
+
aggregation :results do
|
|
249
|
+
top_hits _source: { include: 'name' }
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
}.to_hash
|
|
254
|
+
|
|
255
|
+
assert_equal 2, response['hits']['hits'].size
|
|
256
|
+
|
|
257
|
+
bucket = response['aggregations']['distance_ranges']['buckets'][0]
|
|
258
|
+
|
|
259
|
+
assert_equal 1, bucket['doc_count']
|
|
260
|
+
assert_equal 1, bucket['results']['hits']['hits'].size
|
|
261
|
+
assert_equal 'Karlštejn', bucket['results']['hits']['hits'][0]['_source']['name']
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
should "find documents within the polygon" do
|
|
265
|
+
response = @client.search index: 'places', body: search {
|
|
266
|
+
query do
|
|
267
|
+
bool do
|
|
268
|
+
filter do
|
|
269
|
+
geo_polygon :location do
|
|
270
|
+
points [
|
|
271
|
+
[14.2244355,49.9419006],
|
|
272
|
+
[14.2244355,50.1774301],
|
|
273
|
+
[14.7067869,50.1774301],
|
|
274
|
+
[14.7067869,49.9419006],
|
|
275
|
+
[14.2244355,49.9419006]
|
|
276
|
+
]
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
}.to_hash
|
|
282
|
+
|
|
283
|
+
assert_equal 1, response['hits']['hits'].size
|
|
284
|
+
assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name']
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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 SearchOptionsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
32
|
+
include OpenSearch::DSL::Search
|
|
33
|
+
|
|
34
|
+
context "Search options" do
|
|
35
|
+
setup do
|
|
36
|
+
@client.indices.create index: 'test'
|
|
37
|
+
@client.index index: 'test', id: '1', body: { title: 'Test' }
|
|
38
|
+
@client.index index: 'test', id: '2', body: { title: 'Rest' }
|
|
39
|
+
@client.indices.refresh index: 'test'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should "explain the match" do
|
|
43
|
+
response = @client.search index: 'test', body: search {
|
|
44
|
+
query { match title: 'test' }
|
|
45
|
+
explain true
|
|
46
|
+
}.to_hash
|
|
47
|
+
|
|
48
|
+
assert_equal 1, response['hits']['total']['value']
|
|
49
|
+
assert_not_nil response['hits']['hits'][0]['_explanation']
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
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 QueryIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
32
|
+
include OpenSearch::DSL::Search
|
|
33
|
+
|
|
34
|
+
context "Queries integration" do
|
|
35
|
+
setup do
|
|
36
|
+
@client.indices.create index: 'test'
|
|
37
|
+
@client.index index: 'test', id: '1', body: { title: 'Test', tags: ['one'] }
|
|
38
|
+
@client.index index: 'test', id: '2', body: { title: 'Rest', tags: ['one', 'two'] }
|
|
39
|
+
@client.indices.refresh index: 'test'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "for match query" do
|
|
43
|
+
should "find the document" do
|
|
44
|
+
response = @client.search index: 'test', body: search { query { match title: 'test' } }.to_hash
|
|
45
|
+
|
|
46
|
+
assert_equal 1, response['hits']['total']['value']
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "for match_phrase_prefix query" do
|
|
51
|
+
should "find the document" do
|
|
52
|
+
response = @client.search index: 'test', body: search { query { match_phrase_prefix title: 'te' } }.to_hash
|
|
53
|
+
|
|
54
|
+
assert_equal 1, response['hits']['total']['value']
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "for query_string query" do
|
|
59
|
+
should "find the document" do
|
|
60
|
+
response = @client.search index: 'test', body: search { query { query_string { query 'te*' } } }.to_hash
|
|
61
|
+
|
|
62
|
+
assert_equal 1, response['hits']['total']['value']
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "for the bool query" do
|
|
67
|
+
should "find the document" do
|
|
68
|
+
response = @client.search index: 'test', body: search {
|
|
69
|
+
query do
|
|
70
|
+
bool do
|
|
71
|
+
must { terms tags: ['one'] }
|
|
72
|
+
should { match title: 'Test' }
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
}.to_hash
|
|
76
|
+
|
|
77
|
+
assert_equal 2, response['hits']['total']['value']
|
|
78
|
+
assert_equal 'Test', response['hits']['hits'][0]['_source']['title']
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
should "find the document with a filter" do
|
|
82
|
+
response = @client.search index: 'test', body: search {
|
|
83
|
+
query do
|
|
84
|
+
bool do
|
|
85
|
+
filter { terms tags: ['one'] }
|
|
86
|
+
filter { terms tags: ['two'] }
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
}.to_hash
|
|
90
|
+
|
|
91
|
+
assert_equal 1, response['hits']['total']['value']
|
|
92
|
+
assert_equal 'Rest', response['hits']['hits'][0]['_source']['title']
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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 SizeIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
32
|
+
include OpenSearch::DSL::Search
|
|
33
|
+
|
|
34
|
+
context "Search results pagination" do
|
|
35
|
+
setup do
|
|
36
|
+
@client.indices.create index: 'test', body: {
|
|
37
|
+
mappings: { properties: { title: { type: 'text', fields: { keyword: { type: 'keyword' } } } } } }
|
|
38
|
+
|
|
39
|
+
25.times { |i| @client.index index: 'test', id: i, body: { title: "Test #{sprintf('%03d', i)}" } }
|
|
40
|
+
|
|
41
|
+
@client.indices.refresh index: 'test'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
should "find the correct number of documents" do
|
|
45
|
+
response = @client.search index: 'test', body: search {
|
|
46
|
+
query { match title: 'test' }
|
|
47
|
+
size 15
|
|
48
|
+
}.to_hash
|
|
49
|
+
|
|
50
|
+
assert_equal 25, response['hits']['total']['value']
|
|
51
|
+
assert_equal 15, response['hits']['hits'].size
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
should "move the offset" do
|
|
55
|
+
response = @client.search index: 'test', body: search {
|
|
56
|
+
query { match(:title) { query 'test' } }
|
|
57
|
+
size 5
|
|
58
|
+
from 5
|
|
59
|
+
sort { by 'title.keyword' }
|
|
60
|
+
}.to_hash
|
|
61
|
+
|
|
62
|
+
assert_equal 25, response['hits']['total']['value']
|
|
63
|
+
assert_equal 5, response['hits']['hits'].size
|
|
64
|
+
assert_equal 'Test 005', response['hits']['hits'][0]['_source']['title']
|
|
65
|
+
assert_equal 'Test 009', response['hits']['hits'][4]['_source']['title']
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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 SortingIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
32
|
+
include OpenSearch::DSL::Search
|
|
33
|
+
|
|
34
|
+
context "Sorting integration" do
|
|
35
|
+
setup do
|
|
36
|
+
@client.indices.create index: 'test'
|
|
37
|
+
@client.index index: 'test', id: '1', body: { tags: ['one'], clicks: 15 }
|
|
38
|
+
@client.index index: 'test', id: '2', body: { tags: ['one', 'two'], clicks: 5 }
|
|
39
|
+
@client.index index: 'test', id: '3', body: { tags: ['one', 'three'], clicks: 20 }
|
|
40
|
+
@client.indices.refresh index: 'test'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "sorting by clicks" do
|
|
44
|
+
should "return documents in order" do
|
|
45
|
+
response = @client.search index: 'test', body: search {
|
|
46
|
+
sort do
|
|
47
|
+
by :clicks, order: 'desc'
|
|
48
|
+
end
|
|
49
|
+
}.to_hash
|
|
50
|
+
|
|
51
|
+
assert_same_elements ['3', '1', '2'], response['hits']['hits'].map { |d| d['_id'] }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
# encoding: UTF-8
|
|
28
|
+
|
|
29
|
+
require 'test_helper'
|
|
30
|
+
|
|
31
|
+
module OpenSearch
|
|
32
|
+
module Test
|
|
33
|
+
class SuggestIntegrationTest < ::OpenSearch::Test::IntegrationTestCase
|
|
34
|
+
include OpenSearch::DSL::Search
|
|
35
|
+
|
|
36
|
+
context "Suggest integration" do
|
|
37
|
+
setup do
|
|
38
|
+
@client.indices.create index: 'test', body: {
|
|
39
|
+
mappings: {
|
|
40
|
+
properties: {
|
|
41
|
+
title: {type: 'text'},
|
|
42
|
+
suggest: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
title: {type: 'completion'},
|
|
46
|
+
payload: {type: 'object', enabled: false}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@client.index index: 'test', id: '1', body: {
|
|
54
|
+
title: 'One',
|
|
55
|
+
suggest: {
|
|
56
|
+
title: { input: ['one', 'uno', 'jedna'] },
|
|
57
|
+
payload: { id: '1' }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
@client.index index: 'test', id: '2', body: {
|
|
61
|
+
title: 'Two',
|
|
62
|
+
suggest: {
|
|
63
|
+
title: { input: ['two', 'due', 'dvě'] },
|
|
64
|
+
payload: { id: '2' }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
@client.index index: 'test', id: '3', body: {
|
|
68
|
+
title: 'Three',
|
|
69
|
+
suggest: {
|
|
70
|
+
title: { input: ['three', 'tres', 'tři'] },
|
|
71
|
+
payload: { id: '3' }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
@client.indices.refresh index: 'test'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should "return suggestions" do
|
|
78
|
+
s = search do
|
|
79
|
+
suggest :title, text: 't', completion: { field: 'suggest.title' }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
response = @client.search index: 'test', body: s.to_hash
|
|
83
|
+
|
|
84
|
+
assert_equal 2, response['suggest']['title'][0]['options'].size
|
|
85
|
+
|
|
86
|
+
assert_same_elements %w[2 3], response['suggest']['title'][0]['options'].map { |d| d['_source']['suggest']['payload']['id'] }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "return a single suggestion" do
|
|
90
|
+
s = search do
|
|
91
|
+
suggest :title, text: 'th', completion: { field: 'suggest.title' }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
response = @client.search index: 'test', body: s.to_hash
|
|
95
|
+
|
|
96
|
+
assert_equal 1, response['suggest']['title'][0]['options'].size
|
|
97
|
+
|
|
98
|
+
assert_same_elements %w[3], response['suggest']['title'][0]['options'].map { |d| d['_source']['suggest']['payload']['id'] }
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|