0.1.2 • Published 1 year ago

@team_seki/elastic-plugin v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

elastic-plugin

This library was generated with Nx.

Building

Run nx build elastic-plugin to build the library.

Running unit tests

Run nx test elastic-plugin to execute the unit tests via Jest.

How to use it

Use this docker-compose.yml file to run Elastic Search in your local environment.

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.6.0
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      discovery.type: single-node
      xpack.security.enabled: false

Install the plugin.

npm install @team_seki/elastic-plugin

Use the plugin in your code.

const plugin = new ElasticPlugin()
const client = plugin.getClient()

// Let's start by indexing some data
await client.index({
  index: 'game-of-thrones',
  document: {
    character: 'Ned Stark',
    quote: 'Winter is coming.'
  }
})

await client.index({
  index: 'game-of-thrones',
  document: {
    character: 'Daenerys Targaryen',
    quote: 'I am the blood of the dragon.'
  }
})

await client.index({
  index: 'game-of-thrones',
  document: {
    character: 'Tyrion Lannister',
    quote: 'A mind needs books like a sword needs a whetstone.'
  }
})

// here we are forcing an index refresh, otherwise we will not
// get any result in the consequent search
await client.indices.refresh({ index: 'game-of-thrones' })

// Let's search!
const result= await client.search({
  index: 'game-of-thrones',
  query: {
    match: { quote: 'winter' }
  }
})

console.log(result.hits.hits)