Module: Elastic::AppSearch::Client::Documents

Included in:
Elastic::AppSearch::Client
Defined in:
lib/elastic/app-search/client/documents.rb

Instance Method Summary collapse

Instance Method Details

#destroy_documents(engine_name, ids) ⇒ Array<Hash>

Destroy a batch of documents given a list of IDs

Parameters:

  • ids (Array<String>)

    an Array of Document IDs

Returns:

  • (Array<Hash>)

    an Array of Document destroy result hashes



79
80
81
# File 'lib/elastic/app-search/client/documents.rb', line 79

def destroy_documents(engine_name, ids)
  delete("engines/#{engine_name}/documents", ids)
end

#get_documents(engine_name, ids) ⇒ Hash

Retrieve Documents from the API by IDs for the App Search API

Parameters:

  • engine_name (String)

    the unique Engine name

  • ids (Array<String>)

    an Array of Document IDs

Returns:

  • (Hash)

    list results



26
27
28
# File 'lib/elastic/app-search/client/documents.rb', line 26

def get_documents(engine_name, ids)
  get("engines/#{engine_name}/documents", ids)
end

#index_document(engine_name, document) ⇒ Hash

Index a document using the App Search API.

Parameters:

  • engine_name (String)

    the unique Engine name

  • document (Array)

    a Document Hash

Returns:

  • (Hash)

    processed Document Status hash

Raises:



39
40
41
42
43
44
# File 'lib/elastic/app-search/client/documents.rb', line 39

def index_document(engine_name, document)
  response = index_documents(engine_name, [document])
  errors = response.first['errors']
  raise InvalidDocument.new(errors.join('; ')) if errors.any?
  response.first.tap { |h| h.delete('errors') }
end

#index_documents(engine_name, documents) ⇒ Array<Hash>

Index a batch of documents using the App Search API.

Parameters:

  • engine_name (String)

    the unique Engine name

  • documents (Array)

    an Array of Document Hashes

Returns:

  • (Array<Hash>)

    an Array of processed Document Status hashes

Raises:



55
56
57
58
# File 'lib/elastic/app-search/client/documents.rb', line 55

def index_documents(engine_name, documents)
  documents.map! { |document| normalize_document(document) }
  post("engines/#{engine_name}/documents", documents)
end

#list_documents(engine_name, options = {}) ⇒ Array<Hash>

Retrieve all Documents from the API for the App Search API

Parameters:

  • engine_name (String)

    the unique Engine name

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

Returns:

  • (Array<Hash>)

    an Array of Documents



15
16
17
18
# File 'lib/elastic/app-search/client/documents.rb', line 15

def list_documents(engine_name, options = {})
  params = Utils.symbolize_keys(options)
  request(:get, "engines/#{engine_name}/documents/list", params)
end

#update_documents(engine_name, documents) ⇒ Array<Hash>

Update a batch of documents using the App Search API.

Parameters:

  • engine_name (String)

    the unique Engine name

  • documents (Array)

    an Array of Document Hashes including valid ids

Returns:

  • (Array<Hash>)

    an Array of processed Document Status hashes

Raises:



69
70
71
72
# File 'lib/elastic/app-search/client/documents.rb', line 69

def update_documents(engine_name, documents)
  documents.map! { |document| normalize_document(document) }
  patch("engines/#{engine_name}/documents", documents)
end