BASE
Base Object
"content": [
{
"field": {
"name": "firstname",
"datatype": "Text",
"required": false,
"alias": "First Name",
"multivalued": false,
"indices": [],
"description": "placeholder"
}
},
{
"field": {
"name": "lastname",
"datatype": "Text",
"required": false,
"alias": "Last Name",
"multivalued": false,
"indices": [],
"description": "placeholder"
}
}
],
"metadata": {
"name": "contact"
}
}
Create Base
Creates a base, according to the structure provided. Returns the base id on success.
- json_base*: Framework/Template Template .
Definition
Request Example
-d json_base='{
"content": [
{
"field": {
"name": "nome",
"datatype": "Text",
"required": false,
"alias": "Primeiro Nome",
"multivalued": false,
"indices": [],
"description": "Primeiro nome do contato"
}
},
{
"field": {
"name": "sobrenome",
"datatype": "Text",
"required": false,
"alias": "Último Nome",
"multivalued": false,
"indices": [],
"description": "Último nome do contato"
}
}
],
"metadata": {
"name": "put_something_here"
}
}'
Change Base
Changes the structure of {base}, according to the structure provided. Returns “UPDATED” on success.
- json_base*: Base structure.
put /{base}
Delete Base
Delete the base. Returns “DELETED” on success.
delete /{base}
Import Base
Imports data to a {base}.
- File: “tar.gz” file, containing only 1 text file in utf8 format to be imported, the file must contain 1 JSON per line, each line will be a JSON represented in the “model” of the selected base.
- Workers *: 5, number of processes that will be created to process the amount, the default value is 15
post {base}/_import
- Return:
{ "success":<int_quantidade_sucesso>, "failure": <int_quantidade_falhas> }
Export Base
Exports a base, specified in {base}. It has no implementation.
get {base}/_export
DOCUMENTS
Create Document
Insert a new document in {base}. Returns the id of the document on success.
- value*: Document to be inserted.
- validate*: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation
post /{base}/doc
Recover Document
Returns the {base} document represented by {id}.
get /{base}/doc/{id}
Recover Full Document
Returns the {base} document represented by {id}, with all attributes of the files.
get /{base}/doc/{id}/full
Change Document
Changes the {base} document represented by {id} to the new document. Returns “UPDATED” on success.
- value *: Document to be changed.
- validate *: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation.
put /{base}/doc/{id}
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field. Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
Partially Change a Document (PATCH)
Changes only the fields sent in the “value” of the {base} document represented by {id}. Returns “UPDATED” on success.
- Value *: JSON with document fields to be changed.
- Validate *: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation.
patch /{base}/doc/{id}
In case of multi-valued fields, it is possible to pass:
- The entire list of items to replace or update all elements;
- A list of commands (see below) to change just a few elements and keep the rest as they were;
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field. Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
Commands for Multi-valued Fields
You can send commands instead of multi-valued elements to manipulate the list.
Change Value (set)
{ "$set#pos": (value) }
- pos: indicates the position of the repeat to be changed. Ex: “$ set # 0” changes the first element of the list.
- (value): the value to be inserted. Its type depends on the type of field.
Add Value (add)
{ "$add": (value) }
OR
{ "$add#[pos]": (value) }
- pos (optional): indicates the position where the new value will be inserted. If not specified, the new value will be inserted at the bottom of the list. Ex: “$ add # 0” inserts a new element at the top of the list.
- (value): the value to be inserted. Its type depends on the type of field.
Delete Value (remove)
{ "$remove": null }
OR
{ "$remove#[pos]": null }
- pos (optional): indicates the position of the value to be erased. If it is not specified, the last value in the list will be deleted. Ex: “$ remove # 0” delete the first element from the list.
Example
Consider a document in the base “example_base” with doc_id equal to 1 and with the following structure:
{ "name" : "Doc 1", "letters": [ "A", "B", "C" ], "numbers": [ 0, 1, 2 ] }
And the PATCH / example_base / doc / 1 request with the following value:
{ "letters": [ { "$set#1": "X" }, { "$remove": null }, { "$add#0": "Z" } ], "numbers": [ 3, 4, 5 ] }
After executing this operation, the document will have the following structure:
{ "name" : "Doc 1", "letters": [ "Z", "A", "X" ], "numbers": [ 3, 4, 5 ] }
Because the “name” field is not present in the transaction data, it remains as it was.
The “letters” field of the operation data contains a list of partial change commands that indicate the following changes:
- {“$ Set # 1”: “X”}: changes the second element of the list to the value “X”. Result: [“A”, “X”, “C”]
- {“$ Remove”: null}: Removes the last element from the list. Result: [“A”, “X”]
- {“$ Add # 0:” Z “}: Enter the value” Z “at the beginning of the list Result: [” Z “,” A “,” X “]
The field “numbers” has been completely replaced by the value sent in the request.
Remove Document
Removes the {base} document represented by {id}. Returns “DELETED” on success.
delete /{base}/doc/{id}
Cache Search
Uses document cache:
GET /cached/{base}/doc?cache_key=short_term GET /cached/{base}/doc?cache_key=default_term GET /cached/{base}/doc?cache_key=long_term
- Cache by Document ID:
GET /cached/{base}/doc/{id_doc}?cache_key=short_term GET /cached/{base}/doc/{id_doc}?cache_key=default_term GET /cached/{base}/doc/{id_doc}?cache_key=long_term
The keys are as follows:
- Short_term: cache expires in 60 seconds
- Default_term: The cache expires in 300 seconds
- Long_term: cache expires in 3600 seconds
Each update of a document updates all caches from that database. That is: changing or deleting a document clears the cache of all documents from that database.
COLLECTIONS OF DOCUMENTS
Returns a list of existing documents, according to the search provided. For more details, see the neo.Brlight – REST – Select.odt file.
- $$: JSON Search.
- Result_count: false
get /{base}/doc
Change Document Node
Changes the node of each document found in the search.
put /{base}/doc
- $$: JSON Search.
- path: JSON in format:
[ { "path":"_metadata/dt_idx", "mode":"update", "fn": null, "args":[null] } ]
- Return:
{ "success":10, "failure": 0 }
Insert
Insert a new group in path org
[ { "path": "organ", "fn": null, "mode": "insert", "args": [ { "sg_gr_orgao": "ORGANEX", "nm_gr_orgao": "ORGAN > ORGAN > ORGAN > ORGANEX - Org name in full" } ] } ]
Update
Change the phone number that is equal to 06135251421 to 06135251425
[ { "path": "phone/*", "fn": "equals", "mode": "update", "args": [ "06135251421", "06135251425" ] } ]
Change the phone that starts with 061 to 06135251425
[ { "path": "phone/*", "fn": "starts_with", "mode": "update", "args": [ "061", "06135251425" ] } ]
Replace part of the text on the phone from 061 to 062
[ { "path": "phone/*", "fn": "replace", "mode": "update", "args": [ "061", "062" ] } ]
Change the sg_gr_orgao field of the group group that is equal to COJPN for CCJPN
[ { "path": "organ/*", "fn": "attr_equals", "mode": "update", "args": [ "sg_gr_orgao", "COJPN", "CCJPN" ] } ]
Change the sg_gr_orgao and nm_gr_orgao fields of the group group where id_gr_orgao is equal to 11
[ { "path": "organ/*", "fn": "attr_equals", "mode": "update", "args": [ "id_gr_orgao", 11,{ "sg_gr_orgao":"ORGANEX", "nm_gr_orgao": "ORGAN > ORGAN > ORGAN > ORGANEX - Name of organization in full" } ] } ]
Delete
Delete all phones equal to 06135251421
[ { "path": "phone/*", "fn": "equals", "mode": "delete", "args": [ "06135251421" ] } ]
Delete any organization repeat in which the field id_gr_orgao is null or does not exist
[ { "path": "organ/*", "fn": "attr_equals", "mode": "delete", "args": [ "id_gr_orgao", null ] } ]
Delete all group groups in which the field id_gr_orgao equals 11 or does not exist
[ { "path": "organ/*", "fn": "attr_equals", "mode": "delete", "args": [ "id_gr_orgao",11, true ] } ]
Partially Change Document Node (PATCH)
Changes only the fields sent from the node of each document found in the search.
patch /{base}/doc
- $$: JSON Search.
- path: JSON in format:
[ { "path":"_metadata/dt_idx", "mode":"patch", "fn": null, "args":[null] } ]
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field. Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
- Return:
{ "success":10, "failure": 0 }
It has the same conditional update functions available in the update mode of the PUT route: equals, starts_with, replace, attr_equals.
There are 3 modes: PATCH, MERGE, MANUAL. They affect how lists (multivalued fields) are updated.
Mode: "patch"
Replaces each item in a multi-valued field with the position.
Example
Original Record:
{ "campo": "valor", "grupo": { "campo_a": "valor_a", "campo_b": "valor_b" }, "campo_multi": ["a", "b", "c"], "grupo_multi": [ { "campo_multi_a": "valor_multi_a1", "campo_multi_b": "valor_multi_b1" }, { "campo_multi_a": "valor_multi_a2", "campo_multi_b": "valor_multi_b2" }, { "campo_multi_a": "valor_multi_a3", "campo_multi_b": "valor_multi_b3" } ] }
Request:
PATCH /lbg/base/doc?$$={“literal”: “id_doc = 1”}
{ "path": "/", "mode": "patch", "fn": null, "args": [ { "campo": "valor - PATCHED", "campo_multi": ["d", "e"], "grupo_multi": [ { "campo_multi_a": "valor_multi_a1 - PATCHED" }, { "campo_multi_b": "valor_multi_b2 - PATCHED" }, { "campo_multi_a": "valor_multi_a3 - PATCHED", "campo_multi_b": "valor_multi_b3 - PATCHED" } ] } ] }
Result:
{ "campo": "valor - PATCHED", "grupo": { "campo_a": "valor_a", "campo_b": "valor_b" }, "campo_multi": ["d", "e", "c"], "grupo_multi": [ { "campo_multi_a": "valor_multi_a1 - PATCHED", "campo_multi_b": "valor_multi_b1" }, { "campo_multi_a": "valor_multi_a2", "campo_multi_b": "valor_multi_b2 - PATCHED" }, { "campo_multi_a": "valor_multi_a3 - PATCHED", "campo_multi_b": "valor_multi_b3 - PATCHED" } ] }
Mode: "merge"
It joins all the items present in the request and in the bank, inserting new items at the end of the list.
Example
Request:
PATCH /lbg/base/doc?$$={“literal”: “id_doc = 1”}
{ "path": "/", "mode": "merge", "fn": null, "args": [ { "campo": "valor - PATCHED", "campo_multi": ["d", "e"], "grupo_multi": [ { "campo_multi_a": "valor_multi_a1 - PATCHED", }, { "campo_multi_b": "valor_multi_b2 - PATCHED" }, { "campo_multi_a": "valor_multi_a3 - PATCHED", "campo_multi_b": "valor_multi_b3 - PATCHED" } ] } ] }
Result:
{ "campo": "valor - PATCHED", "grupo": { "campo_a": "valor_a", "campo_b": "valor_b" }, "campo_multi": ["a", "b", "c", "d", "e"], "grupo_multi": [ { "campo_multi_a": "valor_multi_a1", "campo_multi_b": "valor_multi_b1" }, { "campo_multi_a": "valor_multi_a2", "campo_multi_b": "valor_multi_b2" }, { "campo_multi_a": "valor_multi_a3", "campo_multi_b": "valor_multi_b3" }, { "campo_multi_a": "valor_multi_a1 - PATCHED", }, { "campo_multi_b": "valor_multi_b2 - PATCHED" }, { "campo_multi_a": "valor_multi_a3 - PATCHED", "campo_multi_b": "valor_multi_b3 - PATCHED" } ] }
Mode: "manual"
Manipulation of multivalued fields is done manually by means of commands. View details for each command in the Commands section for Multi-valued Fields
Example
Request:
PATCH /lbg/base/doc?$$={“literal”: “id_doc = 1”}
{ "path": "/", "mode": "manual", "fn": null, "args": [ { "campo": "valor - PATCHED", "campo_multi": [ { "$remove#1": null }, { "$add#0": "d" }, { "$add": "e" } ], "grupo_multi": [ { "$set#0": { "campo_multi_a": "valor_multi_a1 - PATCHED" } }, { "$remove#1": null }, { "$add": { "campo_multi_a": "valor_multi_a4", "campo_multi_b": "valor_multi_b4" } } ] } ] }
Result:
{ "campo": "valor - PATCHED", "grupo": { "campo_a": "valor_a", "campo_b": "valor_b" }, "campo_multi": ["d", "a", "c", "e"], # e o "b" (position 1) was removed "grupo_multi": [ { "campo_multi_a": "valor_multi_a1 - PATCHED", "campo_multi_b": "valor_multi_b1" }, { "campo_multi_a": "valor_multi_a3", "campo_multi_b": "valor_multi_b3" }, { "campo_multi_a": "valor_multi_a4", "campo_multi_b": "valor_multi_b4" } ] }
DOCUMENTS NODES
Recover node from a Document
Returns part of the {base} document represented by {id} and the path of nodes {n1} / {n2} / …
get /{base}/doc/{id}/{n1}/{n2}/...
Enter value in the node of a Document
Inserts a JSON object into the {base} document represented by {id} and node path {n1} / {n2} / … Works only for multi-valued Fields or Groups. Returns the last index in the list where the object was inserted.
- value *: Object to be inserted in the path represented by nodes {n1} / {n2} / …
- validate *: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation
post /{base}/doc/{id}/{n1}/{n2}/...
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field.
Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
Change value in the node of a Document
Changes a JSON object in the {base} document represented by {id} and node path {n1} / {n2} / … Returns “UPDATED” on success.
- value *: Object to be changed in the path represented by nodes {n1} / {n2} / …
- validate *: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation
put /{base}/doc/{id}/{n1}/{n2}/...
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field.
Exemplo:
If-Not-Modified-Since: 28/12/2016 15:54:00
Partially Change Value in a Document's Node (PATCH)
Change only the fields sent in the request of a JSON object in the {base} document represented by {id} and node path {n1} / {n2} / … Returns “UPDATED” on success.
- value *: JSON object containing the fields to be changed in the path represented by nodes {n1} / {n2} / …
- validate *: 0, when passing parameter validate = 0 the sent json will not be validated, it will be entered into the system without going through validation
patch /{base}/doc/{id}/{n1}/{n2}/...
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field.
Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
Remove node from a Document
Removes a JSON object in the path represented by nodes {n1} / {n2} / … of the document represented by {id} of {base}. Returns “DELETED” on success.
delete /{base}/doc/{id}/{n1}/{n2}/...
If the If-Not-Modified-Since field is present in the Request Header, the document will only be updated if it has not been changed since the date in the field.
Example:
If-Not-Modified-Since: 28/12/2016 15:54:00
FILES
Insert file
It is intended for uploading files.
post {base}/file
Notice
After the upload is generated the “json_file” of the file record (file). Note that for each base (doc) created in LightBase a file repository (file) is created and this is where the file is actually saved. In order to associate a file with a document (doc) record, it is necessary to record this information in the latter according to the procedure in Associate file with document.
- Parameters
file: Input/field that receives the binary from the file.
- Return
The value of json_file is returned by the server after uploading a file to the base defined in base as the template below …
{ // Mime type of the file. "mimetype": "application/pdf", // File size. "filesize": 1729896, // Id of the record that contains the file. "id_file": "24fb33c0-1ded-34a6-9d27-cd34a10cb956", // File Hash. "uuid": "5c248ce5-56e6-44d1-bc2f-e5332380a9d6", // File name. "filename": "file_name.pdf" }
Associate file with document
put {base}/doc/{id_doc}/{file_type_field}
Notice
The {file_type_field} field is a file-type field that recaps the “json_file” obtained in the Insert File operation.
- Parameters
value: Content of the “json_file”.
- Return
UPDATED
Retrieve metadata about the file
Returns metadata about the {base} file represented by {id_file}.
get /{base}/file/{id_file}
- Return
{ // Mime type file. "mimetype": "application/pdf", // Id of the record that contains the file. "id_file": "24fb33c0-1ded-34a6-9d27-cd34a10cb956", // Text extracted from the file by LBConverter. "filetext": "file text", // File size. "filesize": 1729896, // URI download. "download": "http://127.0.0.1/api/base/file/24fb33c0-1ded-34a6-9d27-cd34a10cb956/download", // Name of the file. "filename": "file_name.pdf", // Date of extraction of the contents of the file into text. "dt_ext_text": "dd/mm/yyyy HH:mm:ss", // Record (doc) to which the file is associated. "id_doc": 10 }
Insert Text
It is intended to store the extracted text from the file. This process is done automatically by the LBConverter.
put {base}/file/{id}/text
- Parameters
filetext: Input/field that receives the extracted text from the file.
- Return
Returns UPDATED on success.
Download file
Returns the {base} file represented by {id_file}
get /{base}/file/{id_file}/download
- Parameters
Disposition – Sets how the file will be downloaded.
Attachment – Use to download the file automatically.
Inline – Use to display file in browser / http client.
Ex:
http://127.0.0.1/api/{base}/file/{id_file}/download?disposition=attachment
Delete file
It is intended to delete files according to the models below:
Model I
delete {base}/file?$$={"<parameter_key>":"<parameter_value>"}
Model II
delete {base}/file/{id_file}
Notice
More specifically use model I follows the following example …
http://host_name/api/base_name/file?$$={"literal":"id_doc is null"}
That is, it is the same model that we use to make queries in the “doc-type” registers by associating the verbs (DELETE, GET …).
- Parameters
query:
?$$={"<parameter_key>":"<parameter_value>"}
Use as shown above and as we do in “doc type” records (“doc” route).
id_file: UUID of the “file type” record.
- Return
For model I
{ "success": <int_success_quantity>, "failure": <int_failure_quantity> }
For model II
DELETED
COLLECTIONS OF ARCHIVES
Recover Files
Returns a list of existing files, according to the search provided. For more details, see the neo.Brlight – REST – Select.odt file.
- $$: JSON Search.
get /{base}/file
INDEX ERROR
Deletes a collection of objects from the base. Returns the count of successes and failures.
delete / _index_error
CONFIGURE TEXTUAL SEARCH
Index Configuration
POST - Create
Creates an index setting.
POST http://<ip_or_name>/_txt_idx
Ex:
POST http://127.0.0.1/_txt_idx
- Parameters
Name: cfg_idx_txt
Required: YES
Model/Example Value:
{ "nm_idx": "bcocat", "cfg_idx": { "settings": { "analysis": { "analyzer": { "case_insensitive_sort": { "tokenizer": "keyword", "filter": [ "lowercase" ] }, "default": { "tokenizer": "standard", "filter": [ "lowercase", "asciifolding" ] }, "ngram_analyzer": { "tokenizer": "ngram_tokenizer", "filter": [ "lowercase", "asciifolding" ], "char_filter": [ "alfanumeric_pattern" ] }, "stemmer_analyzer": { "tokenizer": "standard", "filter": [ "lowercase", "asciifolding", "stemmer_pt_br" ] }, "alfanumeric_analyzer": { "char_filter": [ "alfanumeric_pattern" ], "filter": [ "lowercase", "asciifolding" ], "tokenizer": "standard" } }, "char_filter": { "alfanumeric_pattern": { "type": "pattern_replace", "pattern": "[^a-zA-Z0-9]", "replacement": "" } }, "tokenizer": { "ngram_tokenizer": { "type": "ngram", "min_gram": "2", "max_gram": "3", "token_chars": [ "digit", "letter" ] } }, "filter": { "stemmer_pt_br": { "type": "stemmer", "name": "brazilian" } } } } }, "dt_crt_idx": "01/01/2000 00:00:00", "dt_upt_idx": "01/01/2000 00:00:00", "url_idx": "http://172.16.13.172:9200/bcocat2", "actv_idx": true }
Notice
The dt_crt_idx, dt_upt_idx, and actv_idx fields are not mandatory and will be ignored in the process being handled by the server!
- Return (Model/Example)
12
Notice
id of the newly created record!
GET - Search
- By id
Returns the index set on that URI.
GET http:///_txt_idx/
Ex:
GET http://127.0.0.1/_txt_idx/bcocat
- Return (Model / Example)
{ "actv_idx": true, "url_idx": "http://172.16.13.172:9200/bcocat", "cfg_idx": { "settings": { "analysis": { "filter": { "stemmer_pt_br": { "type": "stemmer", "name": "brazilian" } }, "char_filter": { "alfanumeric_pattern": { "pattern": "[^a-zA-Z0-9]", "type": "pattern_replace", "replacement": "" } }, "analyzer": { "default": { "filter": [ "lowercase", "asciifolding" ], "tokenizer": "standard" }, "ngram_analyzer": { "filter": [ "lowercase", "asciifolding" ], "char_filter": [ "alfanumeric_pattern" ], "tokenizer": "ngram_tokenizer" }, "case_insensitive_sort": { "filter": [ "lowercase" ], "tokenizer": "keyword" }, "stemmer_analyzer": { "filter": [ "lowercase", "asciifolding", "stemmer_pt_br" ], "tokenizer": "standard" }, "alfanumeric_analyzer": { "filter": [ "lowercase", "asciifolding" ], "char_filter": [ "alfanumeric_pattern" ], "tokenizer": "standard" } }, "tokenizer": { "ngram_tokenizer": { "type": "ngram", "token_chars": [ "digit", "letter" ], "max_gram": "3", "min_gram": "2" } } } }, "dt_crt_idx": "01/01/2000 00:00:00", "nm_idx": "bcocat", "dt_upt_idx": "01/01/2000 00:00:00" }
PUT - Edit
Update an index setting.
PUT http://<ip_or_name>/_txt_idx/<nm_idx>
Ex:
PUT http://127.0.0.1/_txt_idx/bcocat
- Parameters
Name: cfg_idx_txt
Required: YES
Template/Value Example:
{ "actv_idx": true, "url_idx": "http://172.16.13.172:9200/bcocat", "cfg_idx": { "settings": { "analysis": { "filter": { "stemmer_pt_br": { "type": "stemmer", "name": "brazilian" } }, "char_filter": { "alfanumeric_pattern": { "pattern": "[^a-zA-Z0-9]", "type": "pattern_replace", "replacement": "" } }, "analyzer": { "default": { "filter": [ "lowercase", "asciifolding" ], "tokenizer": "standard" }, "ngram_analyzer": { "filter": [ "lowercase", "asciifolding" ], "char_filter": [ "alfanumeric_pattern" ], "tokenizer": "ngram_tokenizer" }, "case_insensitive_sort": { "filter": [ "lowercase" ], "tokenizer": "keyword" }, "stemmer_analyzer": { "filter": [ "lowercase", "asciifolding", "stemmer_pt_br" ], "tokenizer": "standard" }, "alfanumeric_analyzer": { "filter": [ "lowercase", "asciifolding" ], "char_filter": [ "alfanumeric_pattern" ], "tokenizer": "standard" } }, "tokenizer": { "ngram_tokenizer": { "type": "ngram", "token_chars": [ "digit", "letter" ], "max_gram": "3", "min_gram": "2" } } } } }, "dt_crt_idx": "01/01/2000 00:00:00", "nm_idx": "bcocat", "dt_upt_idx": "01/01/2000 00:00:00" }
Nota
The fields dt_crt_idx and dt_upt_idx will be ignored in the process being handled by the server!
- Return (Model/Example)
UPDATED
DELETE - Delete
Update an index setting.
DELETE http://<ip_or_name>/_txt_idx/<nm_idx>
Ex:
DELETE http://127.0.0.1/_txt_idx/bcocat
- Return (Model/Example)
DELETED
Mapping Configuration
The mapping configuration resides within the base configuration. For more details see the Bases section.
COMMANDS SQL
Send a SQL command directly to the PostgreSQL database.
Request:
POST /sql Content-Type: application/json Body: { "commands": [ (commands SQL) ] }
- commands (array): a list of strings each containing a SQL query to be executed. All the queries will be executed in a single transaction of the bank, that is, if one query returns error, all the others will be rolled back.
The answer comes in the form of a JSON array that may contain:
a) Commands that return records (SELECT):
{ "row_count": 2, "rows": [ { "col1": "valor_1", "col2": 1, "col3" true }, { "col1": "valor_2", "col2": 2, "col3" false } ] }
- row_count (integer): number of records
- rows (array): list of records in the form of JSON objects
b) Commands that do not return records (INSERT, DELETE, UPDATE…):
{ "success": (true | false) }
- success (boolean): If true, command executed successfully. If false , there was an error executing the command and all other operations were undone (rollback).
Example
Request:
POST /sql Content-Type: application/json { "commands": [ "SELECT id_base, name FROM lb_base WHERE name LIKE '%test%';", "UPDATE lb_doc_api_test_delete SET dt_idx = NOW();" ] }
Response:
[ { "row_count": 4, "rows": [ { "name": "api_test_delete", "id_base": 255 }, { "name": "client_lib_test", "id_base": 134 }, { "name": "dispatcher_test", "id_base": 125 }, { "name": "test_albums", "id_base": 145 } ] }, { "success": true } ]
SIMPLE TEXT SEARCH (via ElasticSearch)
Perform a textual search via ElasticSearch.
Option 1: Search for the same terms in various fields
Request:
POST /{base}/lbes Content-Type: application/json Body: { "query": "(TERM1 AND TERM2) OR TERM3", "search_fields": ["field_1", "field_2.field_2_1"], "return_fields": ["field_1", "field_3", "field_4.field_4_2"], "highlight": { "in_source": (true | false), "pre_tags": ["<b>"], "post_tags": ["</b>"], (and others accepted by ES...) }, "from": 0, "size": 10, "sort": [ {"field1": "asc"}, {"field2": {"order": "asc", "mode": "min"}} ], "raw_es_response": ( true | false ) }
- query (string): A string containing the terms to be fetched. Supports the Boolean operators AND and OR, as well as parentheses and ‘?’ as a wildcard of 1 (one) character.
- search_fields (array of strings, optional, default [“_all”]): an array containing the fields in which the terms are searched
- return_fields (array of strings, optional, default [“_all”]): an array containing the fields that will be returned in the response
- highlight (object, optional): Contains fields with options on how to “shine” the terms found. Any options accepted by ElasticSearch, including “pre-tags” and “post-tags”, can be used.
- in_source (boolean, optional, false ): if true and post-tags below) are placed within the search result; if false , the terms with the tags will come separately in the “highlight” field of the responsa (standard ES).
- pre-tags (string array, optional, default [“”]): strings sent in this array will be placed before each term found
(string array, optional, default [“”]): the strings sent in this array will be placed after each term found - from (integer, default, 0 ): offset value for result pagination
- size (integer, default 10 ): maximum number of results to return
- sort (array of objects, optional): array containing rules for sorting the results. See ES documentation for format details.
- raw_es_reponse (boolean, optional, false ): if true , the response will be returned in the standard ES format; if false , the response will be in the simplified LBG format
Response (simplified standard):
[ { "score": 0.34564, "id_doc": 11, "data": (fields of the 1st register: all or only those marked in "return_fields") }, { "score": 0.12312, "id_doc": 15, "data": (fields of the 2nd register: all or only those marked in "return_fields") }, (...) ]
- score (float): score tf-idf of the record, the more relevant is the search record
- data (object): object with record fields
Option 2: Search for different terms in different fields
Request:
POST /{base}/lbes Content-Type: application/json Body: { "query": { "field_1": "TERM1 OR TERM2", "field_4.field_4_1": "TERM3" }, "return_fields": ["field_1", "field_3", "field_4.field_4_2"], "highlight": { "in_source": (true | false), "pre_tags": ["<b>"], "post_tags": ["</b>"], (and others accepted by ES...) }, "from": 0, "size": 10, "sort": [ {"field1": "asc"}, {"field2": {"order": "asc", "mode": "min"}} ], "raw_es_response": ( true | false ) }
- query (object): an object representing the query to be executed, with the names of the fields as keys and the term to be searched in each field as values.
See option1 for details on other fields. The field “search_fields” should not be used in this type of search since the fields are already indicated inside the “query” object.
COMMAND
Build Version
post /_command/version
Memory Bases
post /_command/base_mem
Clear Memory Bases
post /_command/reset
Server Data
post /_command/rest_url
Bank Details
post /_command/db_url
Index fields
Index fields dd_doc, dt_idx, dt_last_up
POST http://<ip_or_name>/_command/index_base
Ex:
POST http://127.0.0.1/_command/index_base
- Parameters
- Name: base
- Template/Example Value: db_access
- Required: YES