LoginSignup
0
0

More than 1 year has passed since last update.

Elasticsearch 7.14で『📘 データ分析基盤構築入門』を写経してみた (11章)

Last updated at Posted at 2021-08-10
本シリーズのトップページ
https://qiita.com/robozushi10/items/09a088b183127cefa51a

はじめに

Kibana (Elasticsearch, Fluentd) の学習のために、
Elasticsearch 7.14.0 環境で次の御著書を写経してみた.

📘 データ分析基盤構築入門[Fluentd,Elasticsearch,Kibanaによるログ収集と可視化]

ただし、御著書は前提とする Elasticsearch バージョンが v5.4.3 であり、
v7.14.0 では動作しない(と思われる)部分があったので、動いたときの記録を書き出しておく.
(当然ながら、本文を転載するようなことはしない)

本項では、御著書の 11章について書き出す.

なお、私は Elasticsearch, Kibana, Fluentd 初学者のため認識誤りの部分もあるかと思う.

検証環境

次のコマンドで構築した. (詳細は こちら を参照)

$ git clone -b Qiita-02 git@github.com:robozushi10/qiita-efk.git
$ cd qiita-efk
$ docker-compose build --no-cache
$ docker-compose up -d

なお、当方はポートを次のように割り当てている.
・Elasticsearch ... 29200
・Kibana .......... 29601

また、X-Pack による認証は使用していない.

第11章 Elasticsearchのはじめ方

11-4 インデックスとデータの操作

データの取り込み (P210)

Elasticsearch への登録コマンドについても次の変化点があった.

・curl コマンドに「-H "Content-Type: application/json"」を付与する.

ここでは次のように a.sh というシェルスクリプトを作成して PUT を実施した.

a.sh

#!/bin/bash

H="Content-Type: application/json"

B=$(< <(cat <<EOF
{
"host": "localhost",
"timestamp": "06/May/2014:06:11:48 +0000",
"verb": "GET",
"request": "/category/finance",
"httpversion": "1.1",
"response": "200",
"bytes": "51"
}
EOF
))

curl -i -X PUT -H "$H" -d "$B" http://localhost:29200/test_index/apache_log/1

11-6 マッピング定義

Index Template (P220)

御著書のテンプレート登録を実行したところ、次のエラーが発生してしまった.

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [apache_log : {properties={request={type=text, fields={keyword={ignore_above=1000, type=keyword}}}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [apache_log : {properties={request={type=text, fields={keyword={ignore_above=1000, type=keyword}}}}}]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters:  [apache_log : {properties={request={type=text, fields={keyword={ignore_above=1000, type=keyword}}}}}]"
    }
  },
  "status": 400
}

どうやら下記「関連サイト」を見たところ、マッピングの「タイプ」の指定が廃止された影響の模様.

そこで次のように「apache_log」を削除して PUT すれば成功した.

#!/bin/bash

H="Content-Type: application/json"

B=$(< <(cat <<EOF
{
  "template": "test_*",
  "mappings": {
    "properties": {
      "request": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 1000
          }
        }
      }
    }
  }
}
EOF
))

curl -s -X PUT -H "$H" -d "$B" http://localhost:29200/_template/apache_log_template

関連サイト

https://teratail.com/questions/309509
https://www.elastic.co/jp/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0