技術めも

Elastichsearch

検索(完全一致)
https://qiita.com/mctk/items/0a072e758811d90d4642

全文検索エンジン「Elasticsearch」を調べて使ってみた色々まとめ
https://vitalify.jp/blog/2017/02/elasticsearch_matome.html

Hello Elasticsearch
https://medium.com/hello-elasticsearch

第6回 Elasticsearch 入門 基本コンセプトを理解する
https://dev.classmethod.jp/articles/elasticsearch-getting-started-06/

RDB Elasticsearch
Databases Indices, Types(_doc)
Rows Documents
Columns Fields

Index は、物理的な要素である複数の Shards から構成
Shards を複数のノードに分散することで1つの Index に対するデータ量や書き込み速度を分散

# ローカル起動
/usr/local/Cellar/elasticsearch@6/6.8.13/bin
./elasticsearch
#バージョンの概要
curl 127.0.0.1:9200

#sheardsのreplicaが不要なので削除する
curl -H 'Content-Type: application/json' -X PUT -d '{"index":{"number_of_replicas": 0}}' 127.0.0.1:9200/【INDEX】/_settings

#クラスターの状態を確認
curl 127.0.0.1:9200/_cat/health

#インデックスの状態を確認
curl 127.0.0.1:9200/_cat/indices

index 削除

# 存在確認
curl -XGET "localhost:9200/my_index/_mapping?pretty=true"

# 削除
curl -XDELETE "localhost:9200/my_index?pretty=true"

index名の付け方

(データ名)-yyyy.mm.dd" の形式

logstash形式でデータを保存すると、indexが"logstash-yyyy.mm.dd"となる。kibanaもこの形式を標準にしている。
この形式だと日付パーテーションの役割も兼ねるので、n日以前のデータ削除としても使える。

Nested データ型

PUT my_index/my_type/1
{
  "group": "fans",
  "nested_users": [
    {
      "first_name": "John",
      "last_name": "Smith"
    },
    {
      "first_name": "Alice",
      "last_name": "White"
    }
  ]
}
Parent-Child は、1対多の関連性を持ったデータを同じインデックス内に親子それぞれドキュメントタイプを分けて別々にインデックスすることができます(正しくは同じ Shard 内にインデックスする制限がある)。この場合、データスキーマ設計は親と子それぞれ別に JSON 構造に落とし込む設計イメージになります。(RDB 的なリレーションはこちらに近い)

Google Chrome
https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm?spm=a21mg.p38356.a3.1.683e6702ma9hCo