Elasticsearch Quick Start: Making Search Simple and Fun

10 months ago

What Exactly is Elasticsearch?

In simple terms, Elasticsearch (ES for short) is a super powerful search engine. Imagine you have millions of data records; searching through them one by one in a traditional database could take forever. But with ES, it's done in milliseconds!

It's like giving your data its own Google search engine. Whether it's products, logs, articles, or user information, ES can find it in an instant.

Who Uses It?

  • Wikipedia: The world's largest encyclopedia relies on it for search functionality.
  • GitHub: Its code search is powered by ES.
  • Stack Overflow: The programmer's lifeline uses it for question search.
  • JD.com, Taobao: It's the technology behind their product search.
  • Didi, Meituan: Used for location search and merchant search.

https://appstore.lazycat.cloud/#/shop/detail/xu.deploy.elasticsearch

How to Use It?

As of now (September 11, 2025, 08:51:18), the version available in the store is a single-node service and does not include the dashboard feature. Therefore, after opening the application, you will see this page:

image.png

The image above shows the welcome page after the Elasticsearch service starts. It displays the status of the current node and cluster, version number (e.g., 9.0.0), cluster name (e.g., docker-cluster), etc. This indicates that your Elasticsearch instance is running and ready for data operations and retrieval via its API.

Through the Lazycat App Viewer, it was discovered that authentication is currently disabled, allowing access to the service without a password.

image.png

Check Cluster Health

Open a terminal and enter the command:

curl -X GET "https://elasticsearch.your-lanmao.heiyu.space/_cat/health?v"

If successful, you will see a response similar to the following, showing the cluster status, number of nodes, and other information:

image.png

List All Indices

To view all indices in the current cluster: curl -X GET "https://elasticsearch.lanmao168.heiyu.space/_cat/indices?v"

image.png

This will list all indices, including their names, status, and other information. I currently have no data, so the list is empty.

Using the command line can be a bit cumbersome. Next, I'll demonstrate the functionality using Postman. Note that lanmao168 is my microservice identifier; you need to replace it with your own.

1. Create an Index

Request Method:

  • PUT

Request URL:

https://elasticsearch.lanmao168.heiyu.space/products

Request Body:

{}

Explanation:

  • Here, we use a PUT request to create an index named products.
  • The request body can be empty {} to create the index.

Steps:

  1. Open Postman and select the PUT method.
  2. Enter https://elasticsearch.lanmao168.heiyu.space/products in the URL bar.
  3. Go to the Body tab and select the raw format.
  4. Choose JSON format in the raw dropdown and enter {} as the content.
  5. Click the Send button to send the request.

image.png If the index is created successfully, you will see a response similar to:

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "products"
}

2. Add a Document

Request Method:

  • POST

Request URL:

https://elasticsearch.lanmao168.heiyu.space/products/_doc/1

Request Body:

{
  "name": "Smartphone",
  "brand": "BrandX",
  "price": 699.99,
  "category": "Electronics"
}

Explanation:

  • Here, we use a POST request to add a document to the products index.
  • The document ID is 1, and the content is about a product named Smartphone.

Steps:

  1. In Postman, select the POST method.
  2. Enter https://elasticsearch.lanmao168.heiyu.space/products/_doc/1 in the URL bar.
  3. Go to the Body tab and select the raw format.
  4. Choose JSON format in the raw dropdown and enter the document content above.
  5. Click the Send button to send the request.

image.png If the document is added successfully, you will see a response similar to:

{
    "_index": "products",
    "_id": "1\n",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 0,
    "_primary_term": 1
}

3. Search for Documents

Request Method:

  • GET

Request URL:

https://elasticsearch.lanmao168.heiyu.space/products/_search

Request Parameters:

q=name:Smartphone

Explanation:

  • Here, we use a GET request to query all documents in the products index where the name field is Smartphone.

Steps:

  1. In Postman, select the GET method.

  2. Enter https://elasticsearch.lanmao168.heiyu.space/products/_search in the URL bar.

  3. In the Params tab, add a parameter:

    • Key: q
    • Value: name:Smartphone
  4. Click the Send button to send the request.

image.png The returned result will be similar to:

{
    "took": 283,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.2876821,
        "hits": [
            {
                "_index": "products",
                "_id": "1\n",
                "_score": 0.2876821,
                "_source": {
                    "name": "Smartphone",
                    "brand": "BrandX",
                    "price": 699.99,
                    "category": "Electronics"
                }
            }
        ]
    }
}

4. Update a Document

Request Method:

  • PUT

Request URL:

https://elasticsearch.lanmao168.heiyu.space/products/_doc/1

Request Body:

{
  "doc": {
    "price": 799.99
  }
}

Explanation:

  • Here, we use a PUT request to update the price field of the document with ID 1.

Steps:

  1. In Postman, select the PUT method.
  2. Enter https://elasticsearch.lanmao168.heiyu.space/products/_doc/1/_update in the URL bar.
  3. Go to the Body tab and select the raw format.
  4. Choose JSON format in the raw dropdown and enter the data to be updated.
  5. Click the Send button to send the request.

image.png If the update is successful, you will see the returned JSON:

{
    "_index": "products",
    "_id": "1",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 1,
    "_primary_term": 1
}

5. Delete a Document

Request Method:

  • DELETE

Request URL:

https://elasticsearch.lanmao168.heiyu.space/products/_doc/1

Explanation:

  • Use the DELETE method to remove the document with ID 1 from the products index.

Steps:

  1. In Postman, select the DELETE method.
  2. Enter https://elasticsearch.lanmao168.heiyu.space/products/_doc/1 in the URL bar.
  3. Click the Send button to send the request.

image.png After successful deletion, the response will be:

{
    "_index": "products",
    "_id": "1",
    "_version": 3,
    "result": "deleted",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 3,
    "_primary_term": 1
}

Summary

Elasticsearch is not a silver bullet, but it is indeed a powerful tool for search and log analysis scenarios. Whether you need product search, log analysis, or real-time monitoring, ES can handle it with ease.

Start with a single-node version to familiarize yourself with its features, and scale to a cluster when needed. By mastering ES's core concepts and usage skills, you'll be able to navigate the sea of data with ease.

Author
天天