Skip to content

Instantly share code, notes, and snippets.

@brunocarvalhodearaujo
Last active August 29, 2019 14:42
Show Gist options
  • Save brunocarvalhodearaujo/3f901e33fcd359bd1aa0c5f9d2b2bdb5 to your computer and use it in GitHub Desktop.
Save brunocarvalhodearaujo/3f901e33fcd359bd1aa0c5f9d2b2bdb5 to your computer and use it in GitHub Desktop.

Elasticsearch Node.js client common operations

Index (insert)

client.index({
  index: 'example_index',
  type: 'posts',
  id: '1',
  body: {
    user: 'me',
    post_date: new Date(),
    message: 'Hello World!'
  },
  refresh: true
})

Search (DSL)

client.search({
  index: 'example_index',
  type: 'posts',
  body: {
    query: {
      match: {
        body: 'Hello World'
      }
    }
  }
})

Delete

client.delete({
  index: 'example_index',
  type: 'posts',
  id: '1'
})

Update

client.update({
  index: 'game-of-thrones',
  id: 2,
  body: {
    doc: {
      character: 'Maria da silva'
    }
  }
})

delete index

client.indices.delete({ index: 'game-*' })

create index

client.indices.create({ index: 'game-of-thrones' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment