ElastciSearch

[ElasticSearch] ElasticSearch ์ธ๋ฑ์Šค ์ƒ์„ฑ, ์กฐํšŒ, ์‚ญ์ œ ๋ช…๋ น์–ด ์‚ดํŽด๋ณด๊ธฐ

GaGah 2021. 6. 13. 15:34

TEST ํ™˜๊ฒฝ

  • ES ๋ฒ„์ „ : 7.11.2

 

๐Ÿ“Œ ElasticSearch์˜ ์ธ๋ฑ์Šค ์กฐํšŒ, ์ƒ์„ฑ, ์‚ญ์ œ ๋ช…๋ น์–ด

1) ElasticSearch Cluster ์ƒํƒœ ํ™•์ธ

  • ๋ช…๋ น์–ด
curl --location --request GET 'http://localhost:9200/_cat/health?v'
  • ๊ฒฐ๊ณผ  

 

2) ์ธ๋ฑ์Šค ์กฐํšŒ

  • ๋ช…๋ น์–ด
curl --location --request GET 'http://localhost:9200/_cat/indices?v'
  • ๊ฒฐ๊ณผ

 

3) ์ธ๋ฑ์Šค ์ƒ์„ฑ

  • ๋ช…๋ น์–ด
curl --location --request PUT 'http://localhost:9200/books(์ƒ์„ฑํ•  ์ธ๋ฑ์Šค ์ž‘์„ฑ)'
  • ๊ฒฐ๊ณผ
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "test"
}

 

4) ์ธ๋ฑ์Šค ์‚ญ์ œ

  • ๋ช…๋ น์–ด
curl --location --request DELETE 'http://localhost:9200/books(์‚ญ์ œํ•  ์ธ๋ฑ์Šค ์ž‘์„ฑ)'

 

  • ๊ฒฐ๊ณผ
{ "acknowledged": true }

 

๐Ÿ“Œ ์ธ๋ฑ์Šค ์ƒ์„ฑ ์‹œ, Setting/Mapping ์„ค์ •ํ•˜๊ธฐ

์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑํ•  ๋•Œ setting, mapping์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ฌผ๋ก , ์ดˆ๊ธฐ์—๋งŒ ์…‹ํŒ…ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์ƒ‰์ธ์ด ์ƒ์„ฑ๋œ ํ›„, mapping์„ ์ถ”๊ฐ€ํ•˜์—ฌ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜, ์–ธ์ œ๋‚˜ ํ™•์žฅ์ด ์ด๋ฃจ์–ด์ง€๋Š” ๊ฑด ์•„๋‹˜์„ ๋ช…์‹ฌํ•˜์ž.

 

์ƒ‰์ธ์ด ์ƒ์„ฑ๋œ ํ›„์— ๋ ˆํ”Œ๋ฆฌ์นด์˜ ์ˆ˜๋Š” ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์œผ๋‚˜, ์ƒค๋“œ ์ˆ˜๋Š” ๋ณ€๊ฒฝ์ด ๋ถˆ๊ฐ€ํ•˜๋‹ค. 

 

๐Ÿ“Œ Setting

ES ์ธ๋ฑ์Šค Setting ์กฐํšŒ 

  • ๋ช…๋ น์–ด
curl --location --request GET 'http://localhost:9200/nori_sample(์ธ๋ฑ์Šค ์ด๋ฆ„ ์ž‘์„ฑ)/_settings'
  • ๊ฒฐ๊ณผ(์‘๋‹ต
{
    "nori_test": {
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "number_of_shards": "1",
                "provided_name": "nori_test",
                "creation_date": "1622968144285",
                "analysis": {
                    "filter": {
                        "edge3Gram": {
                            "min_gram": "1",
                            "side": "front",
                            "type": "edgeNGram",
                            "max_gram": "3"
                        }
                    },
                    "analyzer": {
                        "nori_analyzer": {
                            "filter": [
                                "edge3Gram",
                                "lowercase"
                            ],
                            "type": "custom",
                            "tokenizer": "nori_user_dict"
                        }
                    },
                    "tokenizer": {
                        "nori_user_dict": {
                            "user_dictionary": "userdict_ko.txt",
                            "decompound_mode": "mixed",
                            "tokenize_on_chars": [
                                "whitespace",
                                "-",
                                "\n"
                            ],
                            "type": "nori_tokenizer",
                            "discard_punctuation": "false"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "jAlgkYzmSeesJU2u-8eysg",
                "version": {
                    "created": "7110299"
                }
            }
        }
    }
}

 

๐Ÿ“Œ Mapping

Mapping ์กฐํšŒ

  • ๋ช…๋ น์–ด
curl --location --request GET 'http://localhost:9200/nori_sample(์ธ๋ฑ์Šค ์ด๋ฆ„ ์ž‘์„ฑ)/_mapping'
  • ๊ฒฐ๊ณผ
{
    "nori_test": {
        "mappings": {
            "properties": {
                "base": {
                    "type": "text"
                },
                "word": {
                    "type": "text",
                    "fields": {
                        "one": {
                            "type": "text",
                            "analyzer": "nori_analyzer"
                        },
                        "two": {
                            "type": "text",
                            "analyzer": "nori_analyzer"
                        }
                    }
                }
            }
        }
    }
}

 

๐Ÿ“Œ ์ฐธ๊ณ ์ž๋ฃŒ

 

Explicit mapping | Elasticsearch Guide [7.13] | Elastic

You know more about your data than Elasticsearch can guess, so while dynamic mapping can be useful to get started, at some point you will want to specify your own explicit mappings. You can create field mappings when you create an index and add fields to a

www.elastic.co

 

fields | Elasticsearch Guide [7.13] | Elastic

Multi-fields do not change the original _source field.

www.elastic.co

 

LIST