diff --git a/.travis.yml b/.travis.yml index c776848a5b..de52c5f205 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ branches: - master - travis - 5.x - - 2.x matrix: include: @@ -31,14 +30,14 @@ matrix: - rvm: 2.4.0 jdk: oraclejdk8 - env: TEST_SUITE=integration SERVER=start TEST_CLUSTER_LOGS=/tmp/log TEST_BUILD_REF=origin/master TEST_CLUSTER_COMMAND=/tmp/elasticsearch-6.0.0-beta1-SNAPSHOT/bin/elasticsearch + env: TEST_SUITE=integration SERVER=start TEST_CLUSTER_LOGS=/tmp/log TEST_BUILD_REF=origin/5.5 TEST_CLUSTER_COMMAND=/tmp/elasticsearch-5.5.3/bin/elasticsearch before_install: - gem update --system - gem --version - gem install bundler -v 1.14.3 - bundle version - - curl -sS https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0-beta1-SNAPSHOT.tar.gz | tar xz -C /tmp + - curl -sS https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.3.tar.gz | tar xz -C /tmp - rake setup - rake elasticsearch:update diff --git a/CHANGELOG.md b/CHANGELOG.md index 099aadb041..a4b51a540f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,52 @@ -## DSL:0.1.5 - -* Added support for the ["Exists" Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html) -* Added missing `like` and `unlike` options to the ["More Like This" Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) -* Added missing `time_zone` option to the ["Query String" Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) -* Added missing `inner_hits` option to the [Nested Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html) -* Allow calling the `filter` method for the [Bool Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) multiple times -* Added missing `minimum_should_match`, `prefix_length`, `max_expansions`, `fuzzy_rewrite`, `analyzer`, `lenient`, `zero_terms_query` and `cutoff_frequency` options to the [Match Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) -* Added missing `minimum_should_match` and `boost` options to the [Bool Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) -* Refactored the [Aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html) collection into its own `AggregationsCollection` class - -## EXT:0.0.23 - -* Fixed removing the data directory for Elasticsearch 5 and 6 in the test cluster -* Added, that Elasticsearch process is properly killed when determining version -* Updated the test cluster class to be compatible Elasticsearch 6.x -* Added `the max_local_storage_nodes` setting to the start command arguments for Elasticsearch 5.x -* Improved the documentation and error messsages for the test cluster -* Updated the "Reindex" extension for Elasticsearch 5.x +## 5.0.4 + +### Client + +* Fixed incorrect test behaviour when the `QUIET` environment variable is set +* Fixed double logging of failed responses +* Swallow logging of exceptions when the `ignore` is specified +* Fixed the bug with `nil` value of `retry_on_status` + +### API + +* Added the "Field Capabilities" API +* Changed, that the YAML test content is not printed unless `DEBUG` is set +* Fixed the failing unit tests for "Scroll" APIs +* Added missing parameters to the "Search" API +* Added missing parameters to the "Multi Search" API +* Added missing parameters to the "Indices Clear Cache" API +* Added missing arguments to the "Exists" API +* Fixes for the "Scroll" API +* Improved the YAML test runner + +## 5.0.3 + +### Client + +* Added proper handling of headers in client options to the Manticore adapter + +## 5.0.2 + +### Client + +* Added default value 'application/json' for the 'Content-Type' header + +## 5.0.0 + +### API + +* Updated the parameters for Elasticsearch 5.x APIs +* Added Elasticsearch 5.x APIs + +## 2.0.0 + +* Added deprecation notices to API methods and parameters not supported on Elasticsearch 2.x + +## 1.1.0 + +### API + +* Added deprecation notices to API methods and arguments not supported on Elasticsearch 1.x ## DSL:0.1.4 diff --git a/Rakefile b/Rakefile index 429cfcccd4..1f8e94bc5b 100644 --- a/Rakefile +++ b/Rakefile @@ -172,6 +172,7 @@ namespace :test do desc "Run unit tests in all subprojects" task :unit do + Rake::Task['test:ci_reporter'].invoke if ENV['CI'] puts "Ruby [#{RUBY_VERSION}]" if defined? RUBY_VERSION subprojects.each do |project| puts '-'*80 diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/indices/flush.rb b/elasticsearch-api/lib/elasticsearch/api/actions/indices/flush.rb index 527d6f9ded..fa416f4902 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/indices/flush.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/indices/flush.rb @@ -12,14 +12,15 @@ module Actions # # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string for all indices # @option arguments [Boolean] :force Whether a flush should be forced even if it is not necessarily needed ie. + # if no changes will be committed to the index. (Internal) # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into # no concrete indices. (This includes `_all` string or when no # indices have been specified) # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that # are open, closed or both. (options: open, closed) + # @option arguments [Boolean] :wait_if_ongoing If set to true the flush operation will block until the flush can be executed if another flush operation is already executing. The default is true. If set to false the flush will be skipped iff if another flush operation is already running. # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when # unavailable (missing, closed, etc) - # @option arguments [Boolean] :wait_if_ongoing If set to true the flush operation will block until the flush can be executed if another flush operation is already executing. If set to false the flush will be skipped if another flush operation is already running. (Default: true) # # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/ # @@ -29,7 +30,8 @@ def flush(arguments={}) :wait_if_ongoing, :ignore_unavailable, :allow_no_indices, - :expand_wildcards ] + :expand_wildcards + ] method = HTTP_POST path = Utils.__pathify Utils.__listify(arguments[:index]), '_flush' diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/percolate.rb b/elasticsearch-api/lib/elasticsearch/api/actions/percolate.rb index e32f432aa5..d31dbaa199 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/percolate.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/percolate.rb @@ -7,48 +7,11 @@ module Actions # Percolator allows you to register queries and then evaluate a document against them: # the IDs of matching queries are returned in the response. # - # @example Register queries named "alert-1" and "alert-2" for the "my-index" index + # @deprecated The `_percolate` API has been deprecated in favour of a special field mapping and the + # `percolate` query; + # see https://www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_percolator.html # - # client.index index: 'my-index', - # type: '.percolator', - # id: 'alert-1', - # body: { query: { query_string: { query: 'foo' } } } - # - # client.index index: 'my-index', - # type: '.percolator', - # id: 'alert-2', - # body: { query: { query_string: { query: 'bar' } } } - # - # @example Evaluate a custom document (passed as `:doc`) against the queries - # - # client.percolate index: 'my-index', type: 'my-type', body: { doc: { title: "Foo" } } - # # => {..., matches: [ {_index: 'my-index', _id: 'alert-1'} ]} - # - # client.percolate index: 'my-index', type: 'my-type', body: { doc: { title: "Foo Bar" } } - # # => {..., matches: [ {_index: 'my-index', _id: 'alert-2'}, {_index: 'my-index', _id: 'alert-1'} ] } - # - # @example Evaluate an existing document against the queries - # - # client.index index: 'my-index', type: 'my-type', id: 123, body: { title: "Foo Bar" } - # - # client.percolate index: 'my-index', type: 'my-type', id: '123' - # # => { ..., matches: [ {_index: 'my-index', _id: 'alert-2'}, { _index: 'my-index', _id: 'alert-1'} ] } - # - # @example Register a query with custom `priority` property - # - # client.index index: 'my-index', - # type: '.percolator', - # id: 'alert-high-1', - # body: { query: { query_string: { query: 'foo' } }, - # priority: 'high' } - # - # @example Evaluate a document against "high priority" percolator queries - # - # client.percolate index: 'my-index', type: 'my-type', body: { - # doc: { title: "Foo" }, - # filter: { term: { priority: 'high' } } - # } - # # => {..., matches: [ {_index: 'my-index', _id: 'alert-high-1'} ]} + # See full example for Elasticsearch 5.x and higher in # # @option arguments [String] :index The index of the document being percolated. (*Required*) # @option arguments [String] :type The type of the document being percolated. (*Required*) @@ -75,6 +38,8 @@ module Actions # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-percolate.html # def percolate(arguments={}) + Utils.__report_unsupported_method :percolate + raise ArgumentError, "Required argument 'index' missing" unless arguments[:index] raise ArgumentError, "Required argument 'type' missing" unless arguments[:type] diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/reindex.rb b/elasticsearch-api/lib/elasticsearch/api/actions/reindex.rb index b00abeb9df..473c485f80 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/reindex.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/reindex.rb @@ -43,9 +43,11 @@ module Actions # @option arguments [String] :consistency Explicit write consistency setting for the operation # (Options: one, quorum, all) # @option arguments [Boolean] :wait_for_completion Whether the request should block and wait until - # the operation has completed + # the operation has completed # @option arguments [Float] :requests_per_second The throttling for this request in sub-requests per second. # 0 means set no throttling (default) + # @option arguments [Integer] :slices The number of slices this request should be divided into. + # Defaults to 1 meaning the request isn't sliced into sub-requests. # # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html # @@ -56,7 +58,8 @@ def reindex(arguments={}) :timeout, :consistency, :wait_for_completion, - :requests_per_second ] + :requests_per_second, + :slices ] method = 'POST' path = "_reindex" params = Utils.__validate_and_extract_params arguments, valid_params diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/search.rb b/elasticsearch-api/lib/elasticsearch/api/actions/search.rb index e059e24cae..66592b549a 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/search.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/search.rb @@ -116,8 +116,6 @@ module Actions # @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response # @option arguments [Boolean] :version Specify whether to return document version as part of a hit # @option arguments [Number] :batched_reduce_size The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. - # @option arguments [Number] :max_concurrent_shard_requests The number of concurrent shard requests this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests. The default grows with the number of nodes in the cluster but is at most 256. - # @option arguments [Number] :pre_filter_shard_size A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. (Default: 128) # # @return [Hash] # @@ -167,9 +165,7 @@ def search(arguments={}) :timeout, :typed_keys, :version, - :batched_reduce_size, - :max_concurrent_shard_requests, - :pre_filter_shard_size ] + :batched_reduce_size ] method = HTTP_GET path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), UNDERSCORE_SEARCH ) diff --git a/elasticsearch-api/lib/elasticsearch/api/utils.rb b/elasticsearch-api/lib/elasticsearch/api/utils.rb index 38504a741f..7dea58d427 100644 --- a/elasticsearch-api/lib/elasticsearch/api/utils.rb +++ b/elasticsearch-api/lib/elasticsearch/api/utils.rb @@ -235,10 +235,12 @@ def __report_unsupported_parameters(arguments, params=[]) end unless messages.empty? + messages << "Suppress this warning by the `-WO` command line flag." + if STDERR.tty? - STDERR.puts messages.map { |m| "\e[31;1m#{m}\e[0m" }.join("\n") + Kernel.warn messages.map { |m| "\e[31;1m#{m}\e[0m" }.join("\n") else - STDERR.puts messages.join("\n") + Kernel.warn messages.join("\n") end end end @@ -249,12 +251,12 @@ def __report_unsupported_method(name) message += " in `#{source}`" end - message += ". This method is not supported in the version you're using: #{Elasticsearch::API::VERSION}, and will be removed in the next release." + message += ". This method is not supported in the version you're using: #{Elasticsearch::API::VERSION}, and will be removed in the next release. Suppress this warning by the `-WO` command line flag." if STDERR.tty? - STDERR.puts "\e[31;1m#{message}\e[0m" + Kernel.warn "\e[31;1m#{message}\e[0m" else - STDERR.puts message + Kernel.warn message end end diff --git a/elasticsearch-api/lib/elasticsearch/api/version.rb b/elasticsearch-api/lib/elasticsearch/api/version.rb index d73c787525..35dd4fccc8 100644 --- a/elasticsearch-api/lib/elasticsearch/api/version.rb +++ b/elasticsearch-api/lib/elasticsearch/api/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module API - VERSION = "6.0.0.pre" + VERSION = "5.0.4" end end diff --git a/elasticsearch-api/test/unit/utils_test.rb b/elasticsearch-api/test/unit/utils_test.rb index 5d96d84b50..6fe19469b9 100644 --- a/elasticsearch-api/test/unit/utils_test.rb +++ b/elasticsearch-api/test/unit/utils_test.rb @@ -253,8 +253,8 @@ class UtilsTest < ::Test::Unit::TestCase arguments = { :foo => 'bar', :moo => 'bam', :baz => 'qux' } unsupported_params = [:foo, :moo] - STDERR.expects(:puts).with do |message| - assert_equal 2, message.split("\n").size + Kernel.expects(:warn).with do |message| + assert_equal 2, message.split("\n").reject { |l| l.include? 'Suppress this warning' }.size true end @@ -265,9 +265,9 @@ class UtilsTest < ::Test::Unit::TestCase arguments = { :foo => 'bar', :moo => 'bam', :baz => 'qux' } unsupported_params = [ { :foo => { :explanation => 'NOT_SUPPORTED' } } ] - STDERR.expects(:puts).with do |message| + Kernel.expects(:warn).with do |message| assert_match /NOT_SUPPORTED/, message - assert_equal 1, message.split("\n").size + assert_equal 1, message.split("\n").reject { |l| l.include? 'Suppress this warning' }.size true end @@ -278,9 +278,9 @@ class UtilsTest < ::Test::Unit::TestCase arguments = { :foo => 'bar', :moo => 'bam', :baz => 'qux' } unsupported_params = [ { :foo => { :explanation => 'NOT_SUPPORTED'} }, :moo ] - STDERR.expects(:puts).with do |message| + Kernel.expects(:warn).with do |message| assert_match /NOT_SUPPORTED/, message - assert_equal 2, message.split("\n").size + assert_equal 2, message.split("\n").reject { |l| l.include? 'Suppress this warning' }.size true end @@ -291,7 +291,7 @@ class UtilsTest < ::Test::Unit::TestCase arguments = { :moo => 'bam', :baz => 'qux' } unsupported_params = [:foo] - STDERR.expects(:puts).never + Kernel.expects(:warn).never __report_unsupported_parameters(arguments, unsupported_params) end @@ -299,7 +299,7 @@ class UtilsTest < ::Test::Unit::TestCase context "__report_unsupported_method" do should "print the warning" do - STDERR.expects(:puts).with do |message| + Kernel.expects(:warn).with do |message| assert_match /foo/, message true end diff --git a/elasticsearch-dsl/lib/elasticsearch/dsl/search/aggregation.rb b/elasticsearch-dsl/lib/elasticsearch/dsl/search/aggregation.rb index a6f6b61a45..ce77a46252 100644 --- a/elasticsearch-dsl/lib/elasticsearch/dsl/search/aggregation.rb +++ b/elasticsearch-dsl/lib/elasticsearch/dsl/search/aggregation.rb @@ -37,14 +37,14 @@ def method_missing(name, *args, &block) # Defines an aggregation nested in another one # def aggregation(*args, &block) - # call + #call @value.__send__ :aggregation, *args, &block end # Returns the aggregations # def aggregations - # call + #call @value.__send__ :aggregations end diff --git a/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/exists.rb b/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/exists.rb index dd537c4786..c0473f3d00 100644 --- a/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/exists.rb +++ b/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/exists.rb @@ -3,18 +3,35 @@ module DSL module Search module Queries - # A filter which returns documents which have at least one non-`null` value in the specified field - # (ie. the reverse of the `missing` filter) + # Returns documents that have at least one non-null value in the field. # - # @example + # @example Find documents with non-empty "name" property # # search do # query do - # exists field: 'occupation' + # exists do + # field 'name' + # end # end # end # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-exists-query.html + # @note The "Exists" query can be used as a "Missing" query in a "Bool" query "Must Not" context. + # + # @example Find documents with an empty "name" property + # + # search do + # query do + # bool do + # must_not do + # exists do + # field 'name' + # end + # end + # end + # end + # end + # + # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-exists-query.html # class Exists include BaseComponent diff --git a/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/match.rb b/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/match.rb index 29ce6d0422..1d795c1a81 100644 --- a/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/match.rb +++ b/elasticsearch-dsl/lib/elasticsearch/dsl/search/queries/match.rb @@ -24,17 +24,8 @@ class Match option_method :query option_method :operator - option_method :minimum_should_match - option_method :type option_method :boost option_method :fuzziness - option_method :prefix_length - option_method :max_expansions - option_method :fuzzy_rewrite - option_method :analyzer - option_method :lenient - option_method :zero_terms_query - option_method :cutoff_frequency option_method :max_expansions end diff --git a/elasticsearch-dsl/test/test_helper.rb b/elasticsearch-dsl/test/test_helper.rb index fefa681936..a06bace878 100644 --- a/elasticsearch-dsl/test/test_helper.rb +++ b/elasticsearch-dsl/test/test_helper.rb @@ -70,7 +70,7 @@ def setup ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n" end - @client = Elasticsearch::Client.new host: "localhost:#{@port}", logger: (ENV['QUIET'] ? nil : @logger) + @client = Elasticsearch::Client.new host: "localhost:#{@port}", logger: @logger @version = @client.info['version']['number'] end diff --git a/elasticsearch-dsl/test/unit/queries/bool_test.rb b/elasticsearch-dsl/test/unit/queries/bool_test.rb index 9ffe055702..b9f7e53ea5 100644 --- a/elasticsearch-dsl/test/unit/queries/bool_test.rb +++ b/elasticsearch-dsl/test/unit/queries/bool_test.rb @@ -37,13 +37,13 @@ class BoolTest < ::Elasticsearch::Test::UnitTestCase end assert_equal( { bool: - { + { minimum_should_match: 1, boost: 1.0, should: [ {term: { tag: 'wow' }}, {term: { tag: 'elasticsearch' }} ] } }, - subject.to_hash ) + subject.to_hash ) end should "take a block with multiple methods" do diff --git a/elasticsearch-dsl/test/unit/queries/exists_test.rb b/elasticsearch-dsl/test/unit/queries/exists_test.rb index 2b1df2def3..bf9f061039 100644 --- a/elasticsearch-dsl/test/unit/queries/exists_test.rb +++ b/elasticsearch-dsl/test/unit/queries/exists_test.rb @@ -3,7 +3,7 @@ module Elasticsearch module Test module Queries - class ExistsTest < ::Elasticsearch::Test::UnitTestCase + class ExistsTest < ::Test::Unit::TestCase include Elasticsearch::DSL::Search::Queries context "Exists query" do diff --git a/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb b/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb index 4d23802e1a..d28eeba8d7 100644 --- a/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb +++ b/elasticsearch-dsl/test/unit/queries/match_phrase_prefix_test.rb @@ -3,7 +3,7 @@ module Elasticsearch module Test module Queries - class MatchPhrasePrefixTest < ::Elasticsearch::Test::UnitTestCase + class MatchPhrasePrefixTest < ::Test::Unit::TestCase include Elasticsearch::DSL::Search::Queries context "Match Phrase Prefix Query" do diff --git a/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb b/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb index 971814c7b8..2dbe6e7965 100644 --- a/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb +++ b/elasticsearch-dsl/test/unit/queries/match_phrase_test.rb @@ -3,7 +3,7 @@ module Elasticsearch module Test module Queries - class MatchPhraseTest < ::Elasticsearch::Test::UnitTestCase + class MatchPhraseTest < ::Test::Unit::TestCase include Elasticsearch::DSL::Search::Queries context "Match Phrase Query" do diff --git a/elasticsearch-dsl/test/unit/queries/match_test.rb b/elasticsearch-dsl/test/unit/queries/match_test.rb index d987e81573..ce49fe4cf7 100644 --- a/elasticsearch-dsl/test/unit/queries/match_test.rb +++ b/elasticsearch-dsl/test/unit/queries/match_test.rb @@ -24,9 +24,8 @@ class MatchTest < ::Elasticsearch::Test::UnitTestCase subject.query 'bar' subject.operator 'bar' - subject.type 'bar' - assert_equal %w[ operator query type ], + assert_equal %w[ operator query ], subject.to_hash[:match].keys.map(&:to_s).sort assert_equal 'bar', subject.to_hash[:match][:query] end @@ -41,12 +40,11 @@ class MatchTest < ::Elasticsearch::Test::UnitTestCase subject = Match.new :message do query 'test' operator 'and' - type 'phrase_prefix' boost 2 fuzziness 'AUTO' end - assert_equal({match: {message: {query: "test", operator: "and", type: 'phrase_prefix', boost: 2, fuzziness: 'AUTO'}}}, + assert_equal({match: {message: {query: "test", operator: "and", boost: 2, fuzziness: 'AUTO'}}}, subject.to_hash) end diff --git a/elasticsearch-extensions/elasticsearch-extensions.gemspec b/elasticsearch-extensions/elasticsearch-extensions.gemspec index 9cb48015c4..d38278b1f6 100644 --- a/elasticsearch-extensions/elasticsearch-extensions.gemspec +++ b/elasticsearch-extensions/elasticsearch-extensions.gemspec @@ -19,9 +19,10 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency "ansi" - s.add_dependency "elasticsearch" - s.add_dependency "oj" - s.add_dependency "patron" + + unless File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__) + s.add_dependency "elasticsearch" + end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9' s.add_dependency "ruby-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius) diff --git a/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb b/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb index 35cb71c453..9240948096 100644 --- a/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb +++ b/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb @@ -174,26 +174,6 @@ class Cluster -E logger.level=#{ENV['DEBUG'] ? 'DEBUG' : 'INFO'} \ #{arguments[:es_params]} COMMAND - }, - - '6.0' => lambda { |arguments, node_number| - <<-COMMAND.gsub(/ /, '').gsub(/\n$/, '') - #{arguments[:command]} \ - -E cluster.name=#{arguments[:cluster_name]} \ - -E node.name=#{arguments[:node_name]}-#{node_number} \ - -E http.port=#{arguments[:port].to_i + (node_number-1)} \ - -E path.data=#{arguments[:path_data]} \ - -E path.logs=#{arguments[:path_logs]} \ - -E cluster.routing.allocation.disk.threshold_enabled=false \ - -E network.host=#{arguments[:network_host]} \ - -E node.attr.testattr=test \ - -E path.repo=/tmp \ - -E repositories.url.allowed_urls=http://snapshot.test* \ - -E discovery.zen.minimum_master_nodes=#{arguments[:number_of_nodes]-1} \ - -E node.max_local_storage_nodes=#{arguments[:number_of_nodes]} \ - -E logger.level=#{ENV['DEBUG'] ? 'DEBUG' : 'INFO'} \ - #{arguments[:es_params]} - COMMAND } } COMMANDS.freeze diff --git a/elasticsearch-extensions/test/test/cluster/integration/cluster_test.rb b/elasticsearch-extensions/test/test/cluster/integration/cluster_test.rb index 515e6edaf7..9785f5cd8b 100644 --- a/elasticsearch-extensions/test/test/cluster/integration/cluster_test.rb +++ b/elasticsearch-extensions/test/test/cluster/integration/cluster_test.rb @@ -22,26 +22,19 @@ class Elasticsearch::Extensions::TestClusterIntegrationTest < Elasticsearch::Tes [] end - STDOUT.puts %Q|Builds: \n#{@builds.map { |b| " * #{b}"}.join("\n")}| unless ENV['QUIET'] + STDOUT.puts %Q|Builds: \n#{@builds.map { |b| " * #{b}"}.join("\n")}| @builds.each do |build| should "start and stop #{build.to_s}" do puts ("----- #{build.to_s} " + "-"*(80-7-build.to_s.size)).to_s.ansi(:bold) begin - Elasticsearch::Extensions::Test::Cluster.start \ - command: PATH_TO_BUILDS.join(build.join('bin/elasticsearch')).to_s, - port: 9260, - cluster_name: 'elasticsearch-ext-integration-test', - path_data: '/tmp/elasticsearch-ext-integration-test' + Elasticsearch::Extensions::Test::Cluster.start command: PATH_TO_BUILDS.join(build.join('bin/elasticsearch')).to_s # Index some data to create the data directory - client = Elasticsearch::Client.new host: "localhost:9260" + client = Elasticsearch::Client.new host: "localhost:9250" client.index index: 'test1', type: 'd', id: 1, body: { title: 'TEST' } ensure - Elasticsearch::Extensions::Test::Cluster.stop \ - command: PATH_TO_BUILDS.join(build.join('bin/elasticsearch')).to_s, - port: 9260, - cluster_name: 'elasticsearch-ext-integration-test' + Elasticsearch::Extensions::Test::Cluster.stop command: PATH_TO_BUILDS.join(build.join('bin/elasticsearch')).to_s end end end diff --git a/elasticsearch-transport/lib/elasticsearch/transport/client.rb b/elasticsearch-transport/lib/elasticsearch/transport/client.rb index 9bd6859dd2..5a7957c106 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/client.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/client.rb @@ -181,6 +181,9 @@ def __extract_hosts(hosts_config, options={}) @arguments[:http][k] ||= v end + # Remove the trailing slash + host_parts[:path].chomp!('/') if host_parts[:path] + host_parts end diff --git a/elasticsearch-transport/lib/elasticsearch/transport/version.rb b/elasticsearch-transport/lib/elasticsearch/transport/version.rb index 1a2b7c0d11..96d8f22bef 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/version.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/version.rb @@ -1,5 +1,5 @@ module Elasticsearch module Transport - VERSION = "6.0.0.pre" + VERSION = "5.0.4" end end diff --git a/elasticsearch-transport/test/integration/client_test.rb b/elasticsearch-transport/test/integration/client_test.rb index e5578dbb05..7b3b2b6ca1 100644 --- a/elasticsearch-transport/test/integration/client_test.rb +++ b/elasticsearch-transport/test/integration/client_test.rb @@ -54,11 +54,11 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int end should "ignore specified response codes" do - response = @client.perform_request 'PUT', '_foobar', ignore: 400 + response = @client.perform_request 'GET', '/_foobar', ignore: 400 assert_equal 400, response.status assert_instance_of Hash, response.body - assert_match /invalid_index_name_exception/, response.body.inspect + assert_match /illegal_argument_exception/, response.body.inspect end should "pass options to the transport" do diff --git a/elasticsearch-transport/test/unit/client_test.rb b/elasticsearch-transport/test/unit/client_test.rb index bd5f8ea95a..d9d5cb7b3b 100644 --- a/elasticsearch-transport/test/unit/client_test.rb +++ b/elasticsearch-transport/test/unit/client_test.rb @@ -228,6 +228,14 @@ def initialize(*); end assert_equal 'bar', hosts[1][:host] end + should "remove trailing slash from URL path" do + hosts = @client.__extract_hosts 'http://myhost/' + assert_equal '', hosts[0][:path] + + hosts = @client.__extract_hosts 'http://myhost/foo/bar/' + assert_equal '/foo/bar', hosts[0][:path] + end + should "raise error for incompatible argument" do assert_raise ArgumentError do @client.__extract_hosts 123 diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 5ddc99682e..266ddd2eaf 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -29,6 +29,7 @@ just use a release matching major version of Elasticsearch. | 0.90 | → | 0.90 | | 1.x | → | 1.x | | 2.x | → | 2.x | +| 5.x | → | 5.x | | master | → | master | ## Installation diff --git a/elasticsearch/elasticsearch.gemspec b/elasticsearch/elasticsearch.gemspec index 2ddd6c8de6..60ec2f9656 100644 --- a/elasticsearch/elasticsearch.gemspec +++ b/elasticsearch/elasticsearch.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |s| s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ] s.rdoc_options = [ "--charset=UTF-8" ] - s.add_dependency "elasticsearch-transport", '6.0.0.pre' - s.add_dependency "elasticsearch-api", '6.0.0.pre' + s.add_dependency "elasticsearch-transport", '5.0.4' + s.add_dependency "elasticsearch-api", '5.0.4' s.add_development_dependency "bundler", "> 1" diff --git a/elasticsearch/lib/elasticsearch/version.rb b/elasticsearch/lib/elasticsearch/version.rb index 0995c40dbe..984160d67d 100644 --- a/elasticsearch/lib/elasticsearch/version.rb +++ b/elasticsearch/lib/elasticsearch/version.rb @@ -1,3 +1,3 @@ module Elasticsearch - VERSION = "6.0.0.pre" + VERSION = "5.0.4" end diff --git a/examples/percolator/percolator_alerts.rb b/examples/percolator/percolator_alerts.rb new file mode 100644 index 0000000000..ba65794514 --- /dev/null +++ b/examples/percolator/percolator_alerts.rb @@ -0,0 +1,96 @@ +# An example of using the percolator with Elasticsearch 5.x and higher +# ==================================================================== +# +# See: +# +# * https://www.elastic.co/blog/elasticsearch-percolator-continues-to-evolve +# * https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html + +require 'ansi' +require 'elasticsearch' + +client = Elasticsearch::Client.new log: true +client.transport.logger.formatter = proc do |severity, datetime, progname, msg| "\e[2m#{msg}\e[0m\n" end + +# Delete the indices used for the example +# +client.indices.delete index: ['my-alerts','my-messages'], ignore: 404 + +# Set up the mapping for the index +# +# * Register the "percolate" type for the `query` field +# * Set up the mapping for the `message` field +# +client.indices.create index: 'my-alerts', + body: { + mappings: { + doc: { + properties: { + query: { + type: 'percolator' + }, + message: { + type: 'text' + } + } + } + } + } + +# Store alert for messages containing "foo" +# +client.index index: 'my-alerts', + type: 'doc', + id: 'alert-1', + body: { query: { match: { message: 'foo' } } } + + +# Store alert for messages containing "bar" +# +client.index index: 'my-alerts', + type: 'doc', + id: 'alert-2', + body: { query: { match: { message: 'bar' } } } + +# Store alert for messages containing "baz" +# +client.index index: 'my-alerts', + type: 'doc', + id: 'alert-3', + body: { query: { match: { message: 'baz' } } } + +client.indices.refresh index: 'my-alerts' + +# Percolate a piece of text against the queries +# +results = client.search index: 'my-alerts', body: { + query: { + percolate: { + field: 'query', + document: { + message: "Foo Bar" + } + } + } +} + +puts "Which alerts match the text 'Foo Bar'?".ansi(:bold), + '> ' + results['hits']['hits'].map { |r| r['_id'] }.join(', ') + +client.index index: 'my-messages', type: 'doc', id: 123, body: { message: "Foo Bar Baz" } + +client.indices.refresh index: 'my-messages' + +results = client.search index: 'my-alerts', body: { + query: { + percolate: { + field: 'query', + index: 'my-messages', + type: 'doc', + id: 123 + } + } +} + +puts "Which alerts match the document [my-messages/doc/123]?".ansi(:bold), + '> ' + results['hits']['hits'].map { |r| r['_id'] }.join(', ')