# Error Handling Note

Elasticsearch 7.9 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋ฐœ์ƒํ•œ Error๋ฅผ ์ •๋ฆฌํ•˜์˜€๋‹ค.


# ์‹ค์Šต ํ™˜๊ฒฝ

  • ๐Ÿ’ก Elasticsearch 7.9.0
  • ๐Ÿ’ก Windows 10
  • ๐Ÿ’ก Git Bash

# header not supported Error

# ๋ฌธ์ œ์ 

2020.08.21
ES์—์„œ index๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ™•์ธํ•˜๊ณ  ์‚ญ์ œํ•  ๋•Œ๋Š” ์•„๋ฌด Error๊ฐ€ ๋‚˜์ง€ ์•Š์•˜๋Š”๋ฐ

Document๋ฅผ ๋งŒ๋“ค ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ Error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}

# ์›์ธ

Elasticsearch 6.0 ์ดํ›„ ๋ฒ„์ „์— ๋„์ž…๋œ ์—…๊ฒฉํ•œ content-type ํ™•์ธ (opens new window)์œผ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•˜๋Š” Error์ด๋‹ค.

# ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

curl ๋ช…๋ น์–ด์— ์˜ต์…˜์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ด์„œ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค.

-H 'Content-Type: application/json'

# Example

Error ์ƒํ™ฉ

$ curl -XPOST http://localhost:9200/classes/class/1/?pretty -d @oneclass.json

{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}

ํ•ด๊ฒฐ

$ curl -XPOST http://localhost:9200/classes/class/1/?pretty -H 'Content-Type: application/json' -d @oneclass.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   394  100   222  100   172   1734   1343 --:--:-- --:--:-- --:--:--  3078{
  "_index" : "classes",
  "_type" : "class",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}


# Could not resolve host: application

# ๋ฌธ์ œ์ 

2020.08.21
Windows10 ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ Elasticsearch๋ฅผ ํ…Œ์ŠคํŠธ ์ค‘์— ์œ„ header ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ ๋“ฏ ํ•˜์˜€๋Š”๋ฐ ์•„๋ž˜์— ์ด๋Ÿฐ Error๊ฐ€ ๋” ์žˆ์—ˆ๋‹ค.

curl: (6) Could not resolve host: application

# ์›์ธ

Cmder (opens new window)์ด๋ผ๋Š” Windows ์ฝ˜์†” ์—๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ls์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ดœ์ฐฎ์„ ์ค„ ์•Œ์•˜์ง€๋งŒ Unix ๋ช…๋ น์–ด๋ฅผ ์˜ค๋ฅ˜์—†์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์•„์ง ์•ˆ๋˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

# ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

Git Bash (opens new window)๋ฅผ ์‚ฌ์šฉํ•ด ๋˜‘๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑํ–ˆ๋Š”๋ฐ ์ž˜ ๋œ๋‹ค.

Cmder์„ ์‚ญ์ œํ•ด์•ผ๊ฒ ๋‹ค.


# The Bulk request must be terminated by a newline [\n]

# ๋ฌธ์ œ์ 

JSON file์„ Bulk ํ•˜๋Š” ๊ณผ์ •์—์„œ Error ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.
2020.08.21

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "The bulk request must be terminated by a newline [\\n]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "The bulk request must be terminated by a newline [\\n]"
  },
  "status" : 400
}

# ์›์ธ

Error ์„ค๋ช…๋Œ€๋กœ New Line์œผ๋กœ ๋๋‚˜์•ผ๋˜๋Š”๋ฐ New Line์ด ์—†์–ด์„œ ๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™๋‹ค.

# ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

JSON file์— ์—”ํ„ฐ๋ฅผ ๋‘ ๋ฒˆ ์ณค๋‹ค.

์ด๋ ‡๊ฒŒ ๋‹จ์ˆœํ•œ Error๋Š” ์ ์ง€๋„ ๋ง์•„์•ผ๊ฒ ๋‹ค. Error ์žก๋Š” ์‹œ๊ฐ„๋ณด๋‹ค ์ •๋ฆฌํ•˜๋Š”๊ฒŒ ๋” ์˜ค๋ž˜๊ฑธ๋ ธ์Œ


# Mapping ์„ค์ •์—์„œ ๋ฌธ์ œ์ (Elasticsearch 7.x ๋ฒ„์ „)

2020.08.24

# โœ” ๋ฌธ์ œ์ 

Elasticsearch 7.x ๋ฒ„์ „์—์„œ Mapping์„ ์ƒ์„ฑํ•˜๋Š” ์‹ค์Šต ๋„์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

์—๋Ÿฌ๋ฌธ๊ตฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
  },
  "status" : 400
}

# ์›์ธ

  • Elasticsearch 7.x ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” curl ๋ฆฌํ€˜์ŠคํŠธ์—์„œ ํ—ค๋”๋ฅผ ๋ช…ํ™•ํžˆ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  • mapping์„ ์ƒ์„ฑํ•  ๋•Œ์—๋Š” include_type_name์„ true๋กœ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

# ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

# 1๏ธโƒฃ mapping์„ ์ƒ์„ฑํ•  ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์ด Content-Type ์ถ”๊ฐ€

-H 'Content-Type: application/json'

์ „์ฒด ์ปค๋ฉ˜๋“œ ๋ผ์ธ

$ curl -XPUT http://localhost:9200/classes/class/_mapping -d @classesRating_mapping.json -H 'Content-Type: application/json'

๋‹ค๋ฅธ ์—๋Ÿฌ ๋ฐœ์ƒ

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
  },
  "status" : 400
}

์ด ์—๋Ÿฌ์— ๋Œ€ํ•ด Elasticsearch ๊ณต์‹ ๋ฌธ์„œ (opens new window)๋ฅผ ์ฐพ์•„๋ณด๋ฉด 7.0 ๋ฒ„์ „ ๋ถ€ํ„ฐ๋Š” ๋ฌดํ˜•์‹ API๋ฅผ ๋„์ž…ํ•จ์— ๋”ฐ๋ผ

include_type_name=true๋ฅผ ์ธ๋ฑ์Šค ์ƒ์„ฑ, ํ…œํ”Œ๋ฆฟ, ๋งคํ•‘ API๋กœ ์ „๋‹ฌ ํ•˜๋ผ๋Š” ๋‚ด์šฉ์ด ์žˆ๋‹ค.

์ถ”๊ฐ€ํ•ด๋ณด์•˜๋‹ค.

# 2๏ธโƒฃ include_type_name=true ์ถ”๊ฐ€

$ curl -XPUT 'http://localhost:9200/classes/class/_mapping?include_type_name=true&pretty' -d @classesRating_mapping.json -H 'Content-Type: application/json'

๋˜ ๋‹ค๋ฅธ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "No handler for type [string] declared on field [professor]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "No handler for type [string] declared on field [professor]"
  },
  "status" : 400
}

์ด ์›์ธ์„ stackoverflow (opens new window)์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š”๋ฐ 6.0 ๋ฒ„์ „ ์ด์ƒ๋ถ€ํ„ฐ Mapping Type ์ค‘ String์„ ์‚ญ์ œํ•˜๊ณ  text๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

๋”ฐ๋ผ์„œ ๊ธฐ์กด์˜ mapping ํƒ€์ž… ์ค‘ string์„ ์‚ญ์ œํ•˜๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค.

์ฐธ๊ณ ํ•œ ๊ธ€ (opens new window)


Last Updated: 6/18/2023, 2:13:15 PM