Skip to content
Skills Library
Programming · Building & coding

spring-data-elasticsearch

/spring-data-elasticsearch

Spring Data Elasticsearch for full-text search and analytics. Covers ElasticsearchOperations, repositories, aggregations, and index management. USE WHEN: user mentions "spring data elasticsearch", "ElasticsearchRepository", "ElasticsearchOperations", "@Document elasticsearch", "Spring Boot Elasticsearch" DO NOT USE FOR: raw Elasticsearch queries - use `elasticsearch` instead, ELK stack setup - use `elasticsearch` instead

Licence
MIT
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
2
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Spring Data Elasticsearch for full-text search and analytics. Covers ElasticsearchOperations, repositories, aggregations, and index management. USE WHEN: user mentions "spring data elasticsearch", "ElasticsearchRepository", "ElasticsearchOperations", "@Document elasticsearch", "Spring Boot Elasticsearch" DO NOT USE FOR: raw Elasticsearch queries - use `elasticsearch` instead, ELK stack setup - use `elasticsearch` instead

Triggers from the description

spring data elasticsearchElasticsearchRepositoryElasticsearchOperations@Document elasticsearchSpring Boot Elasticsearch
Original author description

Spring Data Elasticsearch for full-text search and analytics. Covers ElasticsearchOperations, repositories, aggregations, and index management. USE WHEN: user mentions "spring data elasticsearch", "ElasticsearchRepository", "ElasticsearchOperations", "@Document elasticsearch", "Spring Boot Elasticsearch" DO NOT USE FOR: raw Elasticsearch queries - use `elasticsearch` instead, ELK stack setup - use `elasticsearch` instead

How it works

  1. Dependencies
  2. Configuration
  3. Document Mapping
  4. Repository Pattern
  5. ElasticsearchOperations
  6. Best Practices
  7. When NOT to Use This Skill
  8. Anti-Patterns
  9. Quick Troubleshooting
  10. Production Checklist
Original SKILL.md headings · 192 lines, 585 words
SKILL.md preview
---
name: spring-data-elasticsearch
description: |
  Spring Data Elasticsearch for full-text search and analytics.
  Covers ElasticsearchOperations, repositories, aggregations, and index management.

  USE WHEN: user mentions "spring data elasticsearch", "ElasticsearchRepository",
  "ElasticsearchOperations", "@Document elasticsearch", "Spring Boot Elasticsearch"

  DO NOT USE FOR: raw Elasticsearch queries - use `elasticsearch` instead,
  ELK stack setup - use `elasticsearch` instead
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Spring Data Elasticsearch - Quick Reference

> **Full Reference**: See [advanced.md](advanced.md) for aggregations, autocomplete/suggestions, bulk operations, index management, and Testcontainers integration.

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `spring-data-elasticsearch` for comprehensive documentation.

## Dependencies

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
```

## Configuration

```yaml
spring:
  elasticsearch:
    uris: http://localhost:9200
    username: ${ELASTICSEARCH_USERNAME:}
    password: ${ELASTICSEARCH_PASSWORD:}
    connection-timeout: 5s
    socket-timeout: 30s
```

## Document Mapping

```java
@Document(indexName = "products")
public class Product {

    @Id
    private String id;

    @Field(type = FieldType.Text, analyzer = "standard")
    private String name;

    @Field(type = FieldType.Text, analyzer = "standard")
    private String description;

    @Field(type = FieldType.Keyword)
    private String category;

    @Field(type = FieldType.Double)
    private BigDecimal price;

    @Field(type = FieldType.Integer)
    private Integer stock;

    @Field(type = FieldType.Boolean)
    private boolean active;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    private LocalDateTime createdAt;

    @Field(type = FieldType.Nested)
    private List<ProductAttribute> attributes;

    @Field(type = FieldType.Keyword)
    private List<String> tags;
}
```

## Repository Pattern

```java
public interface ProductRepository extends ElasticsearchRepository<Product, String> {

    List<Product> findByCategory(String category);
    List<Product> findByNameContaining(String name);
    List<Product> findByPriceBetween(BigDecimal min, BigDecimal max);
    List<Product> findByActiveTrue();

    // Pagination
    Page<Product> findByCategory(String category, Pageable pageable);

    // Sorting
    List<Product> findByCategoryOrderByPriceAsc(String category);

    // Count / Exists / Delete
    long countByCategory(String category);
    boolean existsByName(String name);
    void deleteByCategory(String category);
}
```

### Custom Queries
```java
public interface ProductRepository extends ElasticsearchRepository<Product, String> {

    @Query("""
        {
          "multi_match": {
            "query": "?0",
            "fields": ["name^3", "description", "tags"],
            "type": "best_fields",
            "fuzziness": "AUTO"
          }
        }
        """)
    Page<Product> fullTextSearch(String query, Pageable pageable);
}
```

## ElasticsearchOperations

```java
@Service
@RequiredArgsConstructor
public class ProductSearchService {

    private final ElasticsearchOperations elasticsearchOperations;

    public SearchHits<Product> search(ProductSearchCriteria criteria) {
        BoolQuery.Builder boolQuery = new BoolQuery.Builder();

        if (StringUtils.hasText(criteria.getQuery())) {
            boolQuery.must(MultiMatchQuery.of(m -> m
                .query(criteria.getQuery())
                .fields("name^3", "description", "tags")
                .fuzziness("AUTO")
            )._toQuery());
        }

        if (StringUtils.hasText(criteria.getCategory())) {
            boolQuery.filter(TermQuery.of(t -> t
                .field("category")
                .value(criteria.getCategory())
            )._toQuery());
        }

        NativeQuery query = NativeQuery.builder()
            .withQuery(boolQuery.build()._toQuery())
            .withPageable(PageRequest.of(criteria.getPage(), criteria.getSize()))
            .build();

        return elasticsearchOperations.search(query, Product.class);
    }
}
```

## Best Practices

| Do | Don't |
|----|-------|
| Use appropriate field types | Map everything as text |
| Define proper analyzers | Use default for all |
| Use filters for exact matches | Use match for keywords |
| Paginate large result sets | Fetch all documents at once |

## When NOT to Use This Skill

- **Raw Elasticsearch API** - Use `elasticsearch` skill for REST API
- **ELK stack setup** - Use `elasticsearch` skill
- **Primary database** - Elasticsearch is for search, not ACID transactions

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| Refresh after each write | Performance degradation | Use refresh_interval, batch |
| Deep pagination with from/size | Memory issues | Use search_after |
| Mapping all as text | Poor search, high disk | Use appropriate field types |
| No index lifecycle | Disk exhaustion | Configure ILM policies |
| Fetching all fields | Wasted bandwidth | Use source filtering |

## Quick Troubleshooting

| Problem | Diagnostic | Fix |
|---------|------------|-----|
| Connection failed | Check Elasticsearch running | Start ES, check URI, SSL |
| Index not found | Check index name | Create index, check @Document |
| Mapping conflict | Check field types | Reindex with correct mapping |
| Search returns nothing | Check analyzer | Test with _analyze API |
| Version conflict | Check @Version | Handle OptimisticLockingFailureException |

## Production Checklist

- [ ] Cluster configured (3+ nodes)
- [ ] Shards and replicas set
- [ ] Index lifecycle management
- [ ] Proper mapping defined
- [ ] Analyzers configured
- [ ] Bulk operations for indexing
- [ ] Monitoring enabled
- [ ] Security enabled

## Reference Documentation
- [Spring Data Elasticsearch Reference](https://docs.spring.io/spring-data/elasticsearch/reference/)
Files in this package (2)
  • SKILL.md 6 KB
  • advanced.md 9 KB

Versions

The database has no other skills named spring-data-elasticsearch.

Database snapshot: 13.11.2026 · package version 2a0e4718d0d8 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100elasticsearch
    Elasticsearch search and analytics engine. Full-text search, aggregations, document store. Use when implementing search functionality or log analytics. USE WHEN: user mentions "elasticsearch", "full-text search", "search indexing", "log analytics", "ELK stack", "aggregations",…
  • 100spring-data-mongodb
    Spring Data MongoDB for Java/Spring Boot applications. Covers repositories, MongoTemplate, aggregations, and document mapping. USE WHEN: user mentions "spring data mongodb", "MongoTemplate", "MongoRepository", "@Document", "Spring Boot MongoDB", "aggregation pipeline Java" DO…
  • 100elasticsearch
    Read-only access to an Elasticsearch cluster from the shell: list indices, read field mappings, run Query DSL searches, aggregations and ES|QL queries, and check cluster health and shards. Use it whenever the user asks about data, logs, metrics or documents stored in…
  • 100elasticsearch-search
    Configure and use Elasticsearch for full-text search, custom analyzers, aggregations, and index management. Use when a user needs to design search mappings, write complex queries, build aggregation pipelines, tune relevance scoring, or optimize index performance for search workloads.
  • 100elasticsearch
    Expert Elasticsearch assistance covering full-text search, inverted indexes, mappings, aggregations, and cluster lifecycle. Use when building search engines, analyzing logs (ELK), or implementing autocomplete search.
  • 100elasticsearch-expert
    Expert-level Elasticsearch, search, ELK stack, and full-text search. Use when the user mentions search, ELK, Logstash, Kibana, or full text search.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.