๊ด€๋ฆฌ ๋ฉ”๋‰ด

โœ๐Ÿป๊ธฐ๋กํ•˜๋Š” ๋ธ”๋กœ๊ทธ

ElasticSearch ๊ฐ„๋‹จ ์ •๋ฆฌ ๋ณธ๋ฌธ

ELK Stack

ElasticSearch ๊ฐ„๋‹จ ์ •๋ฆฌ

์ฉ์‹œํ‚ด 2022. 6. 29. 00:34
728x90

ํŠน์ง•

  • ๋„ํ๋จผํŠธ

๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ๊ธฐ๋ณธ ๋‹จ์œ„์ด๋ฉฐ JSONํ˜•ํƒœ

7.x ๋ฒ„์ „์ดํ›„์—๋Š” ํƒ€์ž…์ด ์‚ญ์ œ๋˜๋ฉด์„œ RDMS์™€ ๋น„๊ตํ•  ์‹œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ดํ•ดํ•˜๋ฉด ์ข‹๋‹ค.

table index

rdbms es
table index
record document
column field
schema mapping
  • ๋ถ„์„๊ธฐ(Analyzer)์— ์˜ํ•ด ๋ถ„์„ ํ›„ ํ† ํฐ์œผ๋กœ ๋ถ„๋ฆฌ
  • ๊ฒ€์ƒ‰์–ด ์š”์ฒญ์ด ์˜ค๋ฉด ๋ถ„์„๊ธฐ๋ฅผ ํ†ตํ•ด ๋ถ„์„๋œ ํ† ํฐ๊ณผ ์ผ์น˜์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ๊ฒฐ๊ณผ์— score์„ ๋งค๊น€
    • ๋‹ค์–‘ํ•œ ๊ฒ€์ƒ‰๊ธฐ๋Šฅ์„ ์œ„ํ•ด Query DSL์ด๋ž€ ์ฟผ๋ฆฌ ๋ฌธ๋ฒ• ์กด์žฌ

์ธ๋ฑ์Šค

๋„ํ๋จผํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ๋…ผ๋ฆฌ์  ๋‹จ์œ„

๋‹ค์ด๋‚˜ ๋งฅ ๋งคํ•‘

์ธ๋ฑ์Šค ์ƒ์„ฑ ํ›„ ๋งคํ•‘์„ ์„ค์ •ํ•˜์ง€ ์•Š๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์ž๋งˆ์ž ์—˜๋ผ์Šคํ‹ฑ์„œ์น˜๊ฐ€ ์ž๋™์œผ๋กœ ์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ์ž๋™์œผ๋กœ ๊ฒฐ์ • ๊ทธ์˜ ๋ฐ˜๋Œ€๋Š” ๋ช…์‹œ์  ๋งคํ•‘

 

index ๊ด€๋ จ ์š”์ฒญ

๋ชจ๋“  index์กฐํšŒ

# curl -XGET 'localhost:9200/_cat/indices?v'

alias ๊ด€๋ จ ์š”์ฒญ

alias ์กฐํšŒ

curl -X GET 'localhost:9200/_cat/aliases?v'

alias ์ƒ์„ฑ

POST /_aliases?pretty
{
  "actions": [
    {
      "add": {
        "index": "company_index",
        "alias": "company_tmp"
      }
    }
  ]
}

๊ฒ€์ƒ‰

  • ๊ฒ€์ƒ‰์€ ์ธ๋ฑ์Šค ๋‹จ์œ„๋กœ ๊ฒ€์ƒ‰
  • GET <์ธ๋ฑ์Šค๋ช…>/_search ํ˜•์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ ์ฟผ๋ฆฌ๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š์œผ๋ฉด ์ „์ฒด ๋„ํ๋จผํŠธ ๊ฒ€์ƒ‰

๊ธฐ๋ณธ ๊ฒ€์ƒ‰

docment ๋‚ด์šฉ ์ค‘ java๋ผ๋Š” ๋‚ด์šฉ์ด ๋“ค์–ด์žˆ๋Š” document๊ฒ€์ƒ‰

GET index1/_search?q=java

์ฟผ๋ฆฌ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,//๊ฒ€์ƒ‰๊ฒฐ๊ณผ count
      "relation" : "eq"
    },
    "max_score" : 5.2783985,
    "hits" : [//์ •ํ™•๋„๊ฐ€ ๋†’์€ ์ˆœ์œผ๋กœ ์ถœ๋ ฅ
      {
        "_index" : "index1",
        "_type" : "_doc",
        "_id" : "QEdBHYEBA0g9hlFCkg_S",
        "_score" : 5.2783985,
        "_source" : {
          "company_id" : 1,
          "post_id" : "post-20326-1",
          "title" : "์ผ€๋„ค์Šค ๋ผ์šฐ",
          "full_content" : "",
          "tag" : [
            "#Technical Writing"
          ]
        }
      },
      {
        "_index" : "index1",
        "_type" : "_doc",
        "_id" : "Rkc-HYEBA0g9hlFCGw5w",
        "_score" : 3.2347195,
        "_source" : {
          "company_id" : 1,
          "post_id" : "post-121447-1",
          "title" : "Alan Davalos",
          "full_content" : "",
          "tag" : [
            "#Web Development",
            "#Web Development"
          ]
        }
      }
    ]
  }
}

๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž๋ฅผ ํ†ตํ•œ ๊ฒ€์ƒ‰

์˜ˆ) ์ž‘์„ฑ์ž์™€ ๊ธ€ ์ œ๋ชฉ์œผ๋กœ ์ƒ์„ธ๊ฒ€์ƒ‰

GET test/_search?q=value AND three

ํŠน์ • ํ•„๋“œ ๊ฒ€์ƒ‰

GET test/_search?q=value AND three

 


๋งŒ๋‚ฌ๋˜ ์ด์Šˆ

1. ๋…ธ๋ฆฌ ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ฏธ์„ค์น˜ ์ด์Šˆ

Unknown tokenizer type [nori_tokenizer] for [korean_nori_tokenizer]

๋…ธ๋ฆฌ ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์„ค์น˜ ๋˜์ง€์•Š์•„์„œ ๋‚˜๋Š” ์˜ค๋ฅ˜

elastic search.yml ์žฌ์„ค์ • ํ›„ ๋„์ปค ์žฌ์‹œ์ž‘ํ–ˆ๋”๋‹ˆ nori ์ดˆ๊ธฐํ™”

docker exec -it es01 /bin/bash
cd /usr/share/elasticsearch/bin/
./elasticsearch-plugin install analysis-nori

์ปจํ…Œ์ด๋„ˆ ์ ‘์† ํ›„ ๋…ธ๋ฆฌ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ ํ›„ ์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘ ํ•ด์•ผํ•œ๋‹ค.

 

2. logstash์—์„œ elasticsearch๋กœ bulk insert์‹œ ์ปจํ…์ธ  ๊ธธ์ด ๋ฌธ์ œ

/config/elasticsearch.yml์— http:.max_content_length ์„ค์ •์ด ์žˆ๋Š”๋ฐ ์„ค์ •๋œ ์šฉ๋Ÿ‰๋ณด๋‹ค ์ดˆ๊ณผ๋œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋ฉด ์•„๋ž˜ ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค.

 

[2022-06-25T14:32:08,741][ERROR][logstash.outputs.elasticsearch][main]
[354953e725df2fa2db15038a6b15d07cfbe8af411ec4e89ee6f5dfbbc81d5364]
 Encountered a retryable error (will retry with exponential backoff)
 {:code=>400, :url=>"http://[IP:port]/_bulk", :content_length=>37171}

์—˜๋ผ์Šคํ‹ฑ์„œ์น˜๋ฅผ ๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„์— docker compose๋กœ ๋„์šฐ๊ณ   elasticsearch.yml์€ ๋”ฐ๋กœ ์„ค์ •ํ•˜์ง€ ์•Š์•˜๋˜ ์ƒํƒœ์—ฌ์„œ

volume์— ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ • ํŒŒ์ผ์„ ๋งคํ•‘ํ•ด์คฌ๋‹ค.

volumes:
      - es-data01:/usr/share/elasticsearch/data
      - /usr/workspace/elastic-dockercompose/config/elasticsearch.yml:/etc/elasticsearch/config/elasticsearch.yml

elasticsearch.yml์—๋Š” ๋ฉ”์„ธ์ง€ ์šฉ๋Ÿ‰์˜ ์‚ฌ์ด์ฆˆ ์„ค์ •์„ ๋Š˜๋ ค์„œ ์„ธํŒ…ํ–ˆ๋‹ค.

http:.max_content_length: 1024mb

์ฐธ๊ณ ์‚ฌ์ดํŠธ

Elasticsearch - 2.๊ฒ€์ƒ‰ API(Elasticsearch Query DSL)

4.4 ๊ฒ€์ƒ‰ API - _search API

https://honeyinfo7.tistory.com/87

728x90
๋ฐ˜์‘ํ˜•