Lesson 1 of 1 Amazon OpenSearch Service

Adding Full-Text Search and Log Analytics with Amazon OpenSearch Service

This lesson explains how Amazon OpenSearch Service provides full-text search, log analytics and observability, which general-purpose databases handle poorly. It runs OpenSearch clusters and serverless collections that usually hold a searchable copy of data whose primary copy lives elsewhere.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how OpenSearch indexes documents so that text can be searched by relevance.
  • Describe the common pattern of keeping a searchable copy of DynamoDB or Amazon S3 data in OpenSearch.
  • Describe how an OpenSearch Service domain is secured at the network, identity and data levels.

How OpenSearch works

OpenSearch stores data as JSON documents grouped into indexes. When a document is added, OpenSearch analyses its text fields: it splits them into terms, normalises them, for example to lower case, and records which documents contain each term in a structure called an inverted index. A search then looks up the terms instead of scanning every document, which is why OpenSearch can search millions of documents in milliseconds and rank the results by relevance.

Each index is divided into shards, which are spread across the nodes of a cluster so that storage and query work scale out, and each shard can have replicas on other nodes for availability and read throughput. With a provisioned domain, the developer chooses the instance types and number of nodes. OpenSearch Serverless removes that work: data is stored in collections whose capacity scales automatically.

This design gives OpenSearch capabilities that general-purpose databases handle poorly. The following list describes the main ones.

  • Full-text search with relevance ranking, fuzzy matching for typing errors, highlighting and filters.
  • Aggregations, such as counts per category or averages over time, which power faceted navigation and dashboards.
  • Vector (k-NN) search, which finds documents with similar meaning rather than matching words, for semantic search and retrieval-augmented generation (RAG).

Applications query OpenSearch with its JSON query domain-specific language (DSL), with SQL or with the Piped Processing Language (PPL), and OpenSearch Dashboards visualises the results.

Common patterns

OpenSearch is rarely an application's only data store. It usually holds a searchable copy of data whose primary copy lives elsewhere, or it receives logs and events for analysis.

The most common developer pattern is search over DynamoDB data. DynamoDB is efficient for retrieving items by key but cannot perform full-text search, so the application keeps DynamoDB as the source of truth and streams each change into OpenSearch. This is done either with DynamoDB Streams and a Lambda function that indexes each changed item, or with the zero-ETL integration, which performs the synchronisation without custom code. The application then writes to DynamoDB and sends search queries to OpenSearch. Because the copy is updated asynchronously, a newly written item appears in search results after a short delay, which the user interface should allow for.

The second pattern is log analytics. Logs from CloudWatch Logs, applications or Amazon Data Firehose are streamed into OpenSearch, where they can be searched and visualised in near real time. For occasional queries over large volumes of older logs, querying the data in Amazon S3 with Amazon Athena is usually cheaper.

Security

OpenSearch Service domains are secured at three levels: the network, the identity of the caller and the data itself. The following list describes the recommended measure at each level.

  • Network: place the domain in a VPC, so that it has no public endpoint and only resources whose security groups are allowed can reach it.
  • Identity: require requests signed with IAM credentials (Signature Version 4), so that a Lambda function's execution role, for example, determines what it may do. A domain access policy grants access to the domain as a whole.
  • Data: turn on fine-grained access control to define roles with index-level, document-level and field-level permissions, for example allowing a support team to search tickets but not to see payment fields. Encrypt data at rest with AWS KMS and between nodes with node-to-node encryption, and require HTTPS.
Worked example

Product search that understands typing errors

An online shop's product search uses a DynamoDB scan with contains(). It is slow, expensive, and finds nothing when a customer types "wireles hedphones". The developer adds OpenSearch:

ComponentRole
DynamoDBRemains the source of truth for products
Zero-ETL integration (or Streams with Lambda)Keeps the OpenSearch index in sync with the table
OpenSearch indexFull-text search with fuzzy matching, relevance ranking and facets (brand, price range)
Search APIQueries OpenSearch; fetches details from DynamoDB if needed

Fuzzy matching finds "wireless headphones" despite the typing errors. The pattern, a database for writes plus a search index for queries, is the standard answer whenever full-text search is needed.

Check yourself

Products are stored in DynamoDB, and users need full-text search. How is the search index usually kept up to date?

Show answer

DynamoDB Streams capture each change, and a Lambda function, or the managed zero-ETL integration, writes the change to OpenSearch. DynamoDB remains the source of truth, and OpenSearch serves the searches.

Exam Tips

Remember for the exam

  • Full-text search over application data points to OpenSearch Service.
  • To search DynamoDB data, stream its changes into OpenSearch.
  • Semantic or vector search points to OpenSearch k-NN vector search.
  • To restrict access to particular indexes or documents, use fine-grained access control.