jyasuu

elasticsearch

Elasticsearch search and analytics engine operations including CRUD, aggregations, mappings, and reindexing.

jyasuu 0 Updated 4mo ago
GitHub

Install

npx skillscat add jyasuu/cheat-sheet/elasticsearch

Install via the SkillsCat registry.

SKILL.md

Elasticsearch — CRUD Operations

Create Index

curl -X PUT "localhost:9200/index_name"

Add Document

curl -X POST "localhost:9200/index_name/_doc" -H 'Content-Type: application/json' -d'
{
  "field": "value"
}'

Search

curl -X GET "localhost:9200/index_name/_search?q=field:value"

Delete Index

curl -X DELETE "localhost:9200/index_name"

Elasticsearch — Advanced Usage

Aggregations

curl -X GET "localhost:9200/sales/_search" -H 'Content-Type: application/json' -d'
{
  "aggs": {
    "avg_price": { "avg": { "field": "price" } }
  }
}'

Mappings

curl -X PUT "localhost:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "date": { "type": "date" },
      "text": { "type": "text", "analyzer": "english" }
    }
  }
}'

Reindex API

curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
{
  "source": { "index": "old_index" },
  "dest": { "index": "new_index" }
}'