Sha256: 22f038a9073f4a2fc122b74c387c52996cce5a294f72610fee2fb509eba9bc03

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Elasticsearch
  module API
    module Actions

      # Store a script in an internal index (`.scripts`), to be able to reference them
      # in search definitions (with dynamic scripting disabled)
      #
      # @example Storing an Mvel script in Elasticsearch and using it in function score
      #
      #     client.put_script lang: 'groovy', id: 'my_score', body: { script: 'log(_score * factor)' }
      #
      #     client.search body: {
      #       query: {
      #         function_score: {
      #           query: { match: { title: 'foo' } },
      #           functions: [ { script_score: { script_id: 'my_score', params: { factor: 3 } } } ]
      #         }
      #       }
      #     }
      #
      # @option arguments [String] :id Script ID (*Required*)
      # @option arguments [String] :lang Script language (*Required*)
      # @option arguments [Hash]   :body A JSON document containing the script (*Required*)
      #
      # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-scripting.html#_indexed_scripts
      #
      def put_script(arguments={})
        raise ArgumentError, "Required argument 'id' missing"   unless arguments[:id]
        raise ArgumentError, "Required argument 'lang' missing" unless arguments[:lang]
        raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

        method = 'PUT'
        path   = "_scripts/#{arguments[:lang]}/#{arguments[:id]}"

        params = {}

        body   = arguments[:body]

        perform_request(method, path, params, body).body
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elasticsearch-api-1.0.5 lib/elasticsearch/api/actions/put_script.rb