Skip to content

zm-labo/elk-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ELK Demo

Practice

I. Ping & Health check

1. Ping Elasticsearch

$ curl -X GET "http://localhost:9200/"

2. Check Health Elasticsearch

$ curl -X GET "http://localhost:9200/_cat/health?v"

II. Setting

99. Setting Index Allow "read-only / allow delete"

$ curl -X PUT "http://localhost:9200/products/_settings?pretty" -H 'Content-Type: application/json' -d '
{
  "index.blocks.read_only_allow_delete": null
}'

III. CRUD index

1. Get Index Exists

$ curl -X GET "http://localhost:9200/_cat/indices?v"

2. Create Index

$ curl -X PUT "http://localhost:9200/products?pretty"
$ curl -X PUT "http://localhost:9200/soccers?pretty"

3. Detele Index

$ curl -X DELETE "http://localhost:9200/soccers?pretty"

IV. Manage data in index

1. Get data to Index

$ curl -X GET "http://localhost:9200/products/_doc/1"

2. Store data to Index

$ curl -X PUT "http://localhost:9200/products/_doc/2" -H 'Content-Type: application/json' -d'
{
    "fullname": "Duc Toan",
    "age": 30
}'

3. Update data to Index

$ curl -X PUT "http://localhost:9200/products/_doc/2" -H 'Content-Type: application/json' -d'
{
    "fullname": "Duc Toan",
    "age": 30,
    "subject": [
        "toan",
        "van",
        "anh"
    ]
}'

4. Delete data to Index

$ curl -X DELETE "http://localhost:9200/products/_doc/2"

5. Update or Create mutil data to Index

$ curl -X POST "http://localhost:9200/_bulk?pretty" -H 'Content-Type: application/json' --data-binary "@opt/vietnam-football.json"
$ curl -X POST "http://localhost:9200/accounts/_bulk?pretty" -H 'Content-Type: application/json' --data-binary "@opt/accounts.json"

V. Search data index

1. Get all data to index

$ curl -X GET "http://localhost:9200/accounts/_search?pretty"
$ curl -X GET "http://localhost:9200/accounts/_search?pretty=true&q=*:*"

2. Search data

# Seach match_all (_source, sort, size, from)
$ curl -X GET "http://localhost:9200/accounts/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {"match_all": {}},
    "_source": ["account_number", "balance"],
    "sort": [
        {
            "balance": {
                "order": "desc"
            }
        }
    ],
    "size": 2,
    "from": 10
}'
# Seach match (age)
$ curl -X GET "http://localhost:9200/accounts/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {"match": {
        "age": 34
    }},
    "_source": ["account_number", "balance", "age"],
    "sort": [
        {
            "balance": {
                "order": "desc"
            }
        }
    ],
    "size": 2,
    "from": 10
}'
# Search logic (must, should, must_not)
$ curl -X GET "http://localhost:9200/accounts/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "bool": {
            "should": [
                {"match": {"address": "mill"}},
                {"match": {"address": "lane"}}
            ],
            "must_not": [
                {"match": {"state": "IL"}}
            ]
        }
    },
    "_source": ["account_number", "balance", "address", "state"],
    "sort": [
        {
            "balance": {
                "order": "desc"
            }
        }
    ]
}'

Reference

  1. Giới thiệu và cài đặt Elasticsearch và Kibana bằng Docker
  2. Cài đặt Elasticsearch trên CentOS
  3. Tìm hiểu và cài đặt ELK Elasticsearch Logstash Kibana
  4. Laravel tìm kiếm dữ liệu với Elasticsearch

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages