0Pricing
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · Aula

Elasticsearch: indexação e pesquisa

Aprenda os fundamentos do Elasticsearch, um mecanismo distribuído de pesquisa e análise. Compreenda como indexar documentos e executar consultas básicas.

Elasticsearch: indexação e pesquisa é uma aula grátis de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Welcome to Elasticsearch!

Welcome to the first lesson on the ELK Stack! We'll start with Elasticsearch, the 'E' in ELK.

Elasticsearch is a powerful, open-source distributed search and analytics engine. It's designed to store, search, and analyze large volumes of data quickly.

  • Distributed: Runs across multiple servers.
  • Real-time: Data is available for search almost instantly.
  • Scalable: Easily handles growing data needs.

Data as JSON Documents

Elasticsearch stores data as JSON documents. Think of a document as a single record, like a row in a database, but more flexible.

Each document is a collection of fields (key-value pairs) and can contain various data types, including text, numbers, dates, and even other JSON objects.

Here's a simple example of a document:

{"user": "alice", "message": "Hello CoddyKit!"}

Understanding Indices

In Elasticsearch, documents are organized into indices. An index is like a database in a relational database system, or a collection in a NoSQL database.

You can have multiple indices, and each index can store documents that are somewhat related. For example, you might have one index for 'logs' and another for 'products'.

  • An index is a logical namespace.
  • It groups similar documents.
  • You search within specific indices.

Indexing Your First Document

Indexing is the process of adding or updating documents in an Elasticsearch index. When you index a document, Elasticsearch stores it and makes it searchable.

Each document needs a unique ID within its index. If you don't provide one, Elasticsearch will generate it for you.

We use HTTP API calls, typically with PUT or POST requests, to interact with Elasticsearch.

Indexing a Document Example

Let's index a simple log document into an index called my_logs. We'll specify an ID of 1.

Try running this command (assuming Elasticsearch is running on localhost:9200):

curl -X PUT "localhost:9200/my_logs/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "timestamp": "2023-10-27T10:00:00Z",
  "level": "info",
  "message": "Application started successfully"
}'

Retrieving Documents by ID

Once a document is indexed, you can retrieve it using its unique ID. This is useful when you know exactly which document you want.

To retrieve a document, you send an HTTP GET request to the specific index and document ID endpoint.

This operation is very fast as Elasticsearch can directly fetch the document.

Retrieving a Document Example

Let's retrieve the document we just indexed with ID 1 from the my_logs index.

Run this command to see the stored document:

curl -X GET "localhost:9200/my_logs/_doc/1?pretty"

Introduction to Searching

The real power of Elasticsearch comes from its searching capabilities. Instead of knowing an ID, you often want to find documents based on their content.

You can search across all documents in an index (or multiple indices) using various query types. Elasticsearch uses a query language based on JSON.

  • Find documents by keywords.
  • Filter by date ranges or specific values.
  • Combine multiple search criteria.

Basic Search: Match All

The simplest search query is the match_all query. It returns all documents in the specified index.

This is often used to verify that documents are indexed correctly or as a starting point for more complex queries.

You send an HTTP GET request to the _search endpoint of your index.

Match All Query Example

Let's search for all documents in our my_logs index. You'll see the document we indexed earlier.

Run this command:

curl -X GET "localhost:9200/my_logs/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match_all": {}
  }
}'

Quick Check on Indexing

You've learned about documents, indices, and how to index and retrieve data. Let's test your understanding of indexing.

Recap: Indexing and Basic Search

Great job! In this lesson, you've learned the fundamentals of Elasticsearch:

  • Elasticsearch is a distributed search and analytics engine.
  • Data is stored as JSON documents.
  • Documents are organized into indices.
  • Indexing adds or updates documents using PUT/POST requests.
  • Documents can be retrieved by ID using GET requests.
  • Basic searching can be done with queries like match_all.

Next, we'll dive deeper into Logstash, the 'L' in ELK, to ingest and process data!

Perguntas Frequentes

A aula “Elasticsearch: indexação e pesquisa” é grátis?

Sim — o texto completo de “Elasticsearch: indexação e pesquisa” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry), atualize para CoddyKit PRO. O curso de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) inclui 4 aulas no total.

O que vou aprender em “Elasticsearch: indexação e pesquisa”?

Aprenda os fundamentos do Elasticsearch, um mecanismo distribuído de pesquisa e análise. Compreenda como indexar documentos e executar consultas básicas. Você pratica System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?

Nenhuma experiência prévia é necessária. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Elasticsearch: indexação e pesquisa”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)?

Sim. Cada aula de System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Elasticsearch: indexação e pesquisa
  2. Logstash: ingestão e processamento de dados
  3. Kibana: visualização e painéis
  4. Beats: coletores leves de dados
← Voltar para System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)