Skip to content
Back to skills

Elastic

ASecurity

R elastic package for Elasticsearch. Use for connecting to Elasticsearch and performing search operations.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 4, 2026
datago

Works with

  • cli

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill elastic --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Elastic?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Elastic
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-elastic/badge)](https://www.skillsdirectory.com/skills/leolin990405-elastic)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: elastic
description: R elastic package for Elasticsearch. Use for connecting to Elasticsearch and performing search operations.
---

# elastic

Elasticsearch client for R.

## Connection

```r
library(elastic)

# Connect to local Elasticsearch
connect()

# Connect with options
connect(
  host = "localhost",
  port = 9200,
  user = "elastic",
  pwd = "password"
)

# Check connection
ping()
```

## Index Operations

```r
# Create index
index_create("myindex")

# Create with settings
index_create("myindex", body = '{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "title": {"type": "text"},
      "date": {"type": "date"},
      "count": {"type": "integer"}
    }
  }
}')

# Check if exists
index_exists("myindex")

# Delete index
index_delete("myindex")

# List indices
cat_indices()
```

## Indexing Documents

```r
# Index single document
docs_create(index = "myindex", id = 1, body = list(
  title = "Hello",
  content = "World",
  date = Sys.Date()
))

# Bulk index
docs_bulk(df, index = "myindex")

# Bulk from file
docs_bulk("data.json", index = "myindex")
```

## Search

```r
# Simple search
Search(index = "myindex", q = "hello")

# Query DSL
Search(index = "myindex", body = '{
  "query": {
    "match": {
      "title": "hello"
    }
  }
}')

# Bool query
Search(index = "myindex", body = '{
  "query": {
    "bool": {
      "must": [
        {"match": {"title": "hello"}},
        {"range": {"date": {"gte": "2024-01-01"}}}
      ]
    }
  }
}')

# With pagination
Search(index = "myindex", size = 10, from = 0)

# With sorting
Search(index = "myindex", body = '{
  "query": {"match_all": {}},
  "sort": [{"date": "desc"}]
}')
```

## Aggregations

```r
# Terms aggregation
Search(index = "myindex", body = '{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {"field": "category.keyword"}
    }
  }
}')

# Date histogram
Search(index = "myindex", body = '{
  "size": 0,
  "aggs": {
    "by_month": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "month"
      }
    }
  }
}')

# Nested aggregations
Search(index = "myindex", body = '{
  "size": 0,
  "aggs": {
    "by_category": {
      "terms": {"field": "category.keyword"},
      "aggs": {
        "avg_price": {"avg": {"field": "price"}}
      }
    }
  }
}')
```

## Get and Delete

```r
# Get document by ID
docs_get(index = "myindex", id = 1)

# Delete document
docs_delete(index = "myindex", id = 1)

# Delete by query
docs_delete_by_query(index = "myindex", body = '{
  "query": {"match": {"status": "deleted"}}
}')
```

## Update

```r
# Update document
docs_update(index = "myindex", id = 1, body = '{
  "doc": {"status": "updated"}
}')

# Update by query
docs_update_by_query(index = "myindex", body = '{
  "query": {"match": {"status": "pending"}},
  "script": {"source": "ctx._source.status = \"processed\""}
}')
```

## Scroll (Large Results)

```r
# Initialize scroll
res <- Search(index = "myindex", scroll = "1m", size = 1000)

# Get scroll ID
scroll_id <- res$`_scroll_id`

# Continue scrolling
while (length(res$hits$hits) > 0) {
  res <- scroll(scroll_id = scroll_id, scroll = "1m")
  # Process results
}

# Clear scroll
scroll_clear(scroll_id)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…