Class: AzureSearch::Client
- Inherits:
-
Object
- Object
- AzureSearch::Client
- Defined in:
- lib/logstash/outputs/azuresearch/client.rb
Instance Method Summary collapse
- #add_documents(index_name, documents, merge = true) ⇒ Object
-
#initialize(api_url, api_key, api_version = AzureSearch::API_VERSION) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_url, api_key, api_version = AzureSearch::API_VERSION) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/logstash/outputs/azuresearch/client.rb', line 5 def initialize (api_url, api_key, api_version=AzureSearch::API_VERSION) require 'rest-client' require 'json' @api_url = api_url @api_version = api_version @headers = { 'Content-Type' => "application/json; charset=UTF-8", 'Api-Key' => api_key, 'Accept' => "application/json", 'Accept-Charset' => "UTF-8" } end |
Instance Method Details
#add_documents(index_name, documents, merge = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/logstash/outputs/azuresearch/client.rb', line 18 def add_documents(index_name, documents, merge=true) raise ConfigError, 'no index_name' if index_name.empty? raise ConfigError, 'no documents' if documents.empty? action = merge ? 'mergeOrUpload' : 'upload' for document in documents document['@search.action'] = action end req_body = { :value => documents }.to_json # p "REQ_BODY= #{req_body}" # p "URI= #{@api_url}/indexes/#{index_name}/docs/index?api-version=#{@api_version}" res = RestClient.post( "#{@api_url}/indexes/#{index_name}/docs/index?api-version=#{@api_version}", req_body, @headers) res end |