Create Elasticsearch indices, mappings and documents -- without any code!
π velcro strap
currently deletes and re-creates indices and is not meant for production data management.
There is one subcommand: velcro strap
, which will read index mappings from velcro.yaml
and populate indices with data.
Install globally
npm i -g @eighty4/velcro
velcro strap
Or npx it
npx @eighty4/velcro strap
Or add an npm script and npm run velcro
it
{
"scripts": {
"velcro": "velcro strap"
},
"devDependencies": {
"@eighty4/velcro": "0.0.6"
}
}
The velcro
cli uses the following args to configure its connection to Elasticsearch:
velcro strap --config-file path/to/velcro.yaml
velcro strap --node-address https://us-central-1.big-searchable-startup.com
velcro strap --use-basic-auth
and set VELCRO_ES_USER
and VELCRO_ES_PASSWORD
environment variables
velcro strap --use-token-auth
and set VELCRO_ES_TOKEN
environment variable
velcro strap --use-api-key-auth
and set VELCRO_ES_API_KEY
environment variable
velcro strap --skip-tls-verify
velcro strap
will create all index mappings and documents configured in velcro.yaml
---
indices:
my-index-name:
properties:
a_field_name: keyword
another_field: text
my-other-index:
properties:
created_when: date
Documents to be bootstrapped are configured with the documents
key.
---
indices:
my-index-name:
properties:
a_field_name: keyword
another_field: text
documents:
all:
my-index-name:
- _id: foobar
doc:
a_field_name: MY_VERY_OWN_ID
another_field: this doc is created with a specified id
- a_field_name: GENERATED_DOC_ID
another_field: this doc's id will be generated by elasticsearch
- a_field_name: GENERATED_DOC_ID
another_field: this structure will also create a doc with an elasticsearch generated id
Documents under documents.all
will be created any time velcro strap
is run.
Creating documents for a specific environment, such as test
, can be done by running velcro strap --env test
and nesting documents under documents.test
in velcro.yaml
:
documents:
test:
my-index-name:
- a_field_name: CREATED
another_field: velcro strap --env test will create this doc
prod:
my-index-name:
- a_field_name: SKIPPED
another_field: velcro strap --env test will omit this doc
all:
my-index-name:
- a_field_name: CREATED
another_field: velcro strap will always create docs nested under all
A document may include an id by specifying it with the _id
key and nesting the document's fields under the doc
key. The field id_source
comments on the document's id origin.
---
indices:
my-index-name:
properties:
id_source: keyword
documents:
all:
my-index-name:
- _id: foobar
doc:
id_source: MY_VERY_OWN_ID
- id_source: GENERATED_DOC_ID
A test strap manages indices and mappings for execution of a test and can be created with createVelcroTestStrap.
createVelcroTestStrap
will generate unique names for each test's indices that can be removed from Elasticsearch at the end of a test with cleanup()
.
createVelcroTestStrap
uses a config object to specify indices and docs, and it also reads velcro.yaml
so indices can be referenced by name (this will error without my-index-name
declared in a velcro.yaml
):
import {createVelcroTestStrap} from 'velcro'
const velcro = await createVelcroTestStrap({
indices: ['my-index-name'],
documents: [
{
a_field_name: "value",
another_field: "text",
}
]
})
// do some testing
await velcro.cleanup()
Indices can also be configured from test code:
const velcro = await createVelcroTestStrap({
indices: [{
name: 'my-index-name',
mappings: {
a_field_name: 'text',
another_field: 'text',
}
}],
documents: [
{
a_field_name: "value",
another_field: "text",
}
]
})
π createVelcroTestStrap({configPath})
can be used to read a velcro.yaml
from a relative path.
π Documents will not be created from velcro.yaml
for tests.
createVelcroTestStrap
returns VelcroTestStrap which includes APIs to assist with Elasticsearch application testing.
Returns the generated index name for the given index mapping.
Returns the index's created documents' ids.
Returns the doc id of a given index at the specified array index from the createVelcroTestStrap({documents})
array.
Delete all managed documents.
Delete all managed indices.
Delete all managed indices and close Elasticsearch client.