The cl-elastic Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-elastic Reference Manual

This is the cl-elastic Reference Manual, version 0.0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 03:43:35 2022 GMT+0.

Table of Contents


1 Introduction

Cl-Elastic - Elasticsearch client for Common Lisp

Motivation

This project is supposed to be a simple interface for Elasticsearch. The emphasis is on simple, i.e. this is not supposed to be a DSL on top of another DSL. You should be able go to the Elasticsearch docs and translate that immediatly into working code. If you are looking for a DSL checkout the section about other work.

Installation

Update: 29.11.2019

The library is now in quicklisp. You can now simply do (ql:quicklisp :cl-elastic) to load cl-elastic.

Usage

(ql:quicklisp :cl-elastic)
(use :cl-elastic)

(defvar *client* (make-instance '<client> :endpoint "http://localhost:9200"))

;; creates an index named `elasticsearch-test`
(send-request *client* '("elasticsearch-test") :method :put)

You can enable keyword arguments which lets you use keywords as keys in hashtable and parameter plists as well as uri construction. The transformation is always to lowercase.

(setq *enable-keywords* t)
(send-request *client* '(:elasticsearch-test) :method :put)

The library uses the yason library under the hood to map between lisp objects and JSON. As hashtables are therefore ubiquitous for JSON construction the library also exports a simple reader syntax for literal hashmap construction. The syntax is #{key1 value1 key2 value2 ...}. For the enabling and disabling of the syntax the library uses named-readtables.

(in-readtable hashtable-syntax)

(defvar foo "bar")
;; creates a hashmap with ("bar" 1) and ("foo" 2) as key/value pairs
#{foo 1 "foo" 2}

(in-readtable :standard)

For the remaining examples we are assuming that *enable-keywords* is set to true and the above hashtable syntax is enabled. The following examples assume that you are using Elasticsearch version 7.0.0 or above, otherwise you might need to adapt the index settings.

;; create a index with a test field of type text
(send-request *client* :elasticsearch-test :method :put 
              :data #{:settings #{:number_of_shards 1}
                      :mappings #{:properties #{:test #{:type "text"}}}})

;; create a document with id 3
(send-request *client* '(:elasticsearch-test :_doc 3) :method :put
              :data #{:test "toto"})
              
;; find a document by id
(send-request *client* '(:elasticsearch-test :_doc 3) :method :get)

;; search for something
(send-request *client* '(:elasticsearch-test :_search) :method :get
              :data #{:query #{:term #{:test "toto"}}})

;; delete the document
(send-request *client* '(:elasticsearch-test :_doc 3) :method :delete)

;; for bulk requests you can pass a list of operations as data
(send-request *client* :_bulk :method :post
              :data (list
                     #{:index #{:_index :elasticsearch-test :_id 3}}
                     #{:test "foo"}
                     #{:index #{:_index :elasticsearch-test :_id 2}}
                     #{:test "bar"}
                     #{:delete #{:_index :elasticsearch-test :_id 3}}))

Other work

There are a couple of other clients, although non of them are in quicklisp:
clesc
cl-elasticsearch
eclastic

Todo

Author

Licence

MIT Licence

Copyright

Copyright (c) 2019 Finn Völkel (firstname.lastname@gmail.com


2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-elastic

Elasticsearch client for Common Lisp

Author

Finn Völkel

License

MIT

Version

0.0.1

Dependencies
  • drakma (system).
  • named-readtables (system).
  • yason (system).
Source

cl-elastic.asd.

Child Component

cl-elastic.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 cl-elastic/cl-elastic.asd

Source

cl-elastic.asd.

Parent Component

cl-elastic (system).

ASDF Systems

cl-elastic.


3.1.2 cl-elastic/cl-elastic.lisp

Source

cl-elastic.asd.

Parent Component

cl-elastic (system).

Packages

cl-elastic.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 cl-elastic

Source

cl-elastic.lisp.

Nickname

elastic

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


Next: , Previous: , Up: Public Interface   [Contents][Index]

5.1.1 Special variables

Special Variable: *enable-keywords*

If set to a true value, keywords will be transformed to strings in JSON objects and read back as keywords.

Package

cl-elastic.

Source

cl-elastic.lisp.


5.1.2 Macros

Macro: disable-hashtable-syntax ()
Package

cl-elastic.

Source

cl-elastic.lisp.

Macro: enable-hashtable-syntax ()
Package

cl-elastic.

Source

cl-elastic.lisp.


5.1.3 Ordinary functions

Function: send-request (client uri &key method data parameters)

Sends a request to an Elasticsearch client.

Package

cl-elastic.

Source

cl-elastic.lisp.


5.1.4 Generic functions

Generic Reader: endpoint (object)
Package

cl-elastic.

Methods
Reader Method: endpoint ((<client> <client>))

automatically generated reader method

Source

cl-elastic.lisp.

Target Slot

endpoint.

Generic Reader: password (object)
Package

cl-elastic.

Methods
Reader Method: password ((<client> <client>))

automatically generated reader method

Source

cl-elastic.lisp.

Target Slot

password.

Generic Reader: user (object)
Package

cl-elastic.

Methods
Reader Method: user ((<client> <client>))

automatically generated reader method

Source

cl-elastic.lisp.

Target Slot

user.


5.1.5 Classes

Class: <client>
Package

cl-elastic.

Source

cl-elastic.lisp.

Direct methods
Direct slots
Slot: endpoint
Initform

"http://localhost:9200"

Initargs

:endpoint

Readers

endpoint.

Writers

This slot is read-only.

Slot: user
Initargs

:user

Readers

user.

Writers

This slot is read-only.

Slot: password
Initargs

:password

Readers

password.

Writers

This slot is read-only.


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Special variables

Special Variable: *previous-readtables*
Package

cl-elastic.

Source

cl-elastic.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.2 Ordinary functions

Function: #{-reader-} (stream char arg)
Package

cl-elastic.

Source

cl-elastic.lisp.

Function: concat-with-newlines (strings)

Concats STRINGS with newlines. Ends in a newline.

Package

cl-elastic.

Source

cl-elastic.lisp.

Function: create-uri (client uri)
Package

cl-elastic.

Source

cl-elastic.lisp.

Function: encode-json (data)

Transforms a lisp object into a JSON object in string form. A list is transformed into the newline seperated concatenation of JSON objects.

Package

cl-elastic.

Source

cl-elastic.lisp.

Function: keyword-downcase (keyword)
Package

cl-elastic.

Source

cl-elastic.lisp.

Function: keywords-to-strings (x)
Package

cl-elastic.

Source

cl-elastic.lisp.

Function: make-keyword (name)

Creates a keyword symbol for a given string NAME.

Package

cl-elastic.

Source

cl-elastic.lisp.

Function: parse-uri (uri)

Parses a URI in form of a string, keyword or list.

Package

cl-elastic.

Source

cl-elastic.lisp.


5.2.3 Conditions

Condition: odd-number-of-forms
Package

cl-elastic.

Source

cl-elastic.lisp.

Direct superclasses

error.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   #  
C   D   E   F   G   K   M   P   S   U  
Index Entry  Section

#
#{-reader-}: Private ordinary functions

C
concat-with-newlines: Private ordinary functions
create-uri: Private ordinary functions

D
disable-hashtable-syntax: Public macros

E
enable-hashtable-syntax: Public macros
encode-json: Private ordinary functions
endpoint: Public generic functions
endpoint: Public generic functions

F
Function, #{-reader-}: Private ordinary functions
Function, concat-with-newlines: Private ordinary functions
Function, create-uri: Private ordinary functions
Function, encode-json: Private ordinary functions
Function, keyword-downcase: Private ordinary functions
Function, keywords-to-strings: Private ordinary functions
Function, make-keyword: Private ordinary functions
Function, parse-uri: Private ordinary functions
Function, send-request: Public ordinary functions

G
Generic Function, endpoint: Public generic functions
Generic Function, password: Public generic functions
Generic Function, user: Public generic functions

K
keyword-downcase: Private ordinary functions
keywords-to-strings: Private ordinary functions

M
Macro, disable-hashtable-syntax: Public macros
Macro, enable-hashtable-syntax: Public macros
make-keyword: Private ordinary functions
Method, endpoint: Public generic functions
Method, password: Public generic functions
Method, user: Public generic functions

P
parse-uri: Private ordinary functions
password: Public generic functions
password: Public generic functions

S
send-request: Public ordinary functions

U
user: Public generic functions
user: Public generic functions

Jump to:   #  
C   D   E   F   G   K   M   P   S   U