ElasticSearch-Kibanaの一般的な操作
84490 ワード
開始
ElasticSearch
1、目次elasticsearch-5.6に入る.16 2、Terminalを開いて、./Elasticsearch 3、起動に成功したかどうかを確認する
Kibana
1、目次kibana-5.6に入る.16-darwin-x86_64 2、Terminalを開いて、./kibana 3、起動に成功したかどうかを確認する 4、開くhttp://localhost:5601
Kibanaの一般的な操作
1、迅速に集団の健康状態を検査する
GET/_cat/health?v注意:後ろがついたら?vヘッダーが表示されます.そうしないとヘッダーは表示されません. green:各インデックスのprimary shardおよびreplica shardはactive状態の である. yellow:各インデックスのprimary shardはactive状態ですが、一部のreplica shardはactive状態ではなく、使用できない状態です red:すべてのインデックスのprimary shardがactive状態ではなく、一部のインデックスでは のデータが失われています.
Q&Aはなぜ今yellow状態にあるのですか?
2.クラスタ内のインデックスをすばやく表示
GET/_cat/indices?v
3、簡単な索引操作
索引の作成:PUT/test_index?pretty
索引の削除:DELETE/test_index?pretty
4、商品のCRUD操作
PUT/Index/Type/id:GET/Index/Type/idの新規/置換:POST/Index/Type/id/_の問合せupdate:DELETE/Index/Type/idの変更:削除
4.1新規商品:新規ドキュメント、インデックス作成
次のように入力します.
操作結果を返す
Esはindexとtypeを自動的に確立し、事前に作成する必要はありません.また、esのデフォルトではdocumentのfieldごとに逆インデックスが確立され、検索可能になります.
4.2商品検索:ドキュメント検索
GET/Index/Type/id入力:
戻り値:
4.3商品の修正:文書の置換
置換方法には、すべてのfieldを持っていなくても、情報の修正を行うことができません.例えば、
調べてみると、idが1の商品はそれだけのフィールドしかないことがわかりました
4.4商品の修正:文書の更新
結果を返す
nameフィールドのみ更新
4.5商品の削除:ドキュメントの削除
結果を返します.
削除したdocumentが元のtypeに存在しない場合
5、商品の照会操作
6つのクエリー方式 1、query string search GET/Index/Type/_search:全 を検索 2、query DSL 3、query filter 4、full-text search 5、phrase search 6、highlight search
5.1、query string search(非常用)
結果は次のとおりです.
took:数ミリ秒のtimed_out:タイムアウトするかどうか、ここにはありません_shards:データは5つのスライスに分割されているので、検索要求に対して、すべてのprimary shardに電話します(またはそのreplica shardのいずれか)hits.total:クエリー結果の数、3つのdocument hits.max_score:scoreの意味は、documentが1つのsearchの相関に対する整合スコアであるほど、相関があるほど整合し、スコアも高いhits.hits:整合検索を含むdocumentの詳細データは、コマンドラインで一時的にいくつかのツールを使用するのに適していることを意味します.例えばcurlは、要求を迅速に出して、欲しい情報を検索します.しかし、クエリーリクエストが複雑であれば、構築するのは難しいです.生産環境ではquery string searchはほとんど使用されません.例えば、商品名にyagaoが含まれている商品を検索し、価格の降順にソートする必要があります.
5.2、query DSL
DSL:Domain Specified Language,特定の分野の言語http request body:要求体、jsonのフォーマットで検索文法を構築することができて、比較的に便利で、各種の複雑な文法を構築することができて、query string searchよりきっととても強いです
5.2.1すべてのクエリー
5.2.2照会名称yagaoを含む商品を価格降順で並べ替える
5.2.3ページごとに商品を検索し、合計3つの商品につき、1ページにつき1つの商品が表示されたと仮定し、2ページ目が表示されたので、2つ目の商品が検出されます
5.2.4クエリーが返すフィールドのリストを指定する
結果は次のように返されます.
5.3、query filter
検索商品名にはyagaoが含まれており、価格が20元以上の商品
5.4、full-text search(全文検索)
Producerにyagaoとproducerが含まれている商品を検索します.すなわち、matchのクエリー条件をスペースで区切ることです.
クエリの結果は
複雑なクエリー
5.5、phrase search(フレーズ検索)
全文検索に対応して、逆に全文検索は入力した検索列を分解して、インデックスの中に並べ替えて一つ一つマッチングして、上のいずれかの分解後の単語にマッチングできれば、結果としてphrase searchを返すことができて、入力した検索列を要求して、指定したフィールドのテキストの中で、完全にそっくりを含んでこそ、マッチングを計算することができます.結果として返される
6、データ分析
6.1 tagあたりの商品数を計算する
初めてtagを使用してパケットをグループ化するとエラーが表示されます.この場合、tagフィールドfielddataをtrueに設定する必要があります.以下に示します.
結果は以下の通りです.
6.2名前にyagaoが含まれている商品について、tagあたりの商品数を計算する
上のaggsと比較してqueryの条件が多くなりました
6.3グループに分けてから、グループごとの平均値を計算し、tagごとの商品の平均価格を計算する
次の結果が返されます.
6.4
各tagの商品の平均価格を計算し、平均価格の降順にソートする
結果は
6.5指定された価格範囲区間でグループ化し、各グループ内でtagでグループ化し、最後に各グループの平均価格を計算する
結果は次のとおりです.
ElasticSearch
1、目次elasticsearch-5.6に入る.16 2、Terminalを開いて、./Elasticsearch 3、起動に成功したかどうかを確認する
Kibana
1、目次kibana-5.6に入る.16-darwin-x86_64 2、Terminalを開いて、./kibana 3、起動に成功したかどうかを確認する 4、開くhttp://localhost:5601
Kibanaの一般的な操作
1、迅速に集団の健康状態を検査する
GET/_cat/health?v注意:後ろがついたら?vヘッダーが表示されます.そうしないとヘッダーは表示されません.
Q&Aはなぜ今yellow状態にあるのですか?
/**
, es , node。 es index, kibana index。
index 5 primary shard 5 replica shard, primary shard replica shard ( )。
kibana index 1 primary shard 1 replica shard。 node,
1 primary shard , replica shard 。
*/
2.クラスタ内のインデックスをすばやく表示
GET/_cat/indices?v
3、簡単な索引操作
索引の作成:PUT/test_index?pretty
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open test_index XmS9DTAtSkSZSwWhhGEKkQ 5 1 0 0 650b 650b
yellow open .kibana rUm9n9wMRQCCrRDEhqneBg 1 1 1 0 3.1kb 3.1kb
索引の削除:DELETE/test_index?pretty
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open .kibana rUm9n9wMRQCCrRDEhqneBg 1 1 1 0 3.1kb 3.1kb
4、商品のCRUD操作
PUT/Index/Type/id:GET/Index/Type/idの新規/置換:POST/Index/Type/id/_の問合せupdate:DELETE/Index/Type/idの変更:削除
4.1新規商品:新規ドキュメント、インデックス作成
PUT /Index/Type/Id
{
"json "
}
次のように入力します.
PUT /ecommerce/product/1
{
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"producer" :"gaolujie producer",
"tags": [ "meibai", "fangzhu" ]
}
操作結果を返す
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
Esはindexとtypeを自動的に確立し、事前に作成する必要はありません.また、esのデフォルトではdocumentのfieldごとに逆インデックスが確立され、検索可能になります.
4.2商品検索:ドキュメント検索
GET/Index/Type/id入力:
GET /ecommerce/product/1
戻り値:
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "gaolujie yagao",
"desc": "gaoxiao meibai",
"price": 30,
"producer": "gaolujie producer",
"tags": [
"meibai",
"fangzhu"
]
}
}
4.3商品の修正:文書の置換
PUT /ecommerce/product/1
{
"name" : "jiaqiangban gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"producer" : "gaolujie producer",
"tags": [ "meibai", "fangzhu" ]
}
置換方法には、すべてのfieldを持っていなくても、情報の修正を行うことができません.例えば、
PUT /ecommerce/product/1
{
"name" : "jiaqiangban gaolujie yagao"
}
調べてみると、idが1の商品はそれだけのフィールドしかないことがわかりました
4.4商品の修正:文書の更新
POST /ecommerce/product/1/_update
{
"doc": {
"name": "jiaqiangban gaolujie yagao"
}
}
結果を返す
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 8,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
nameフィールドのみ更新
4.5商品の削除:ドキュメントの削除
DELETE /ecommerce/product/1
結果を返します.
{
"found": true,
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 9,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
削除したdocumentが元のtypeに存在しない場合
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"found": false
}
5、商品の照会操作
6つのクエリー方式
5.1、query string search(非常用)
GET /taobao/goods/_search
結果は次のとおりです.
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "taobao",
"_type": "goods",
"_id": "4",
"_score": 1,
"_source": {
"name": "heiren",
"desc": "youxiao qingjie",
"price": 70,
"producer": "yagao producer"
}
},
......
]
}
}
took:数ミリ秒のtimed_out:タイムアウトするかどうか、ここにはありません_shards:データは5つのスライスに分割されているので、検索要求に対して、すべてのprimary shardに電話します(またはそのreplica shardのいずれか)hits.total:クエリー結果の数、3つのdocument hits.max_score:scoreの意味は、documentが1つのsearchの相関に対する整合スコアであるほど、相関があるほど整合し、スコアも高いhits.hits:整合検索を含むdocumentの詳細データは、コマンドラインで一時的にいくつかのツールを使用するのに適していることを意味します.例えばcurlは、要求を迅速に出して、欲しい情報を検索します.しかし、クエリーリクエストが複雑であれば、構築するのは難しいです.生産環境ではquery string searchはほとんど使用されません.例えば、商品名にyagaoが含まれている商品を検索し、価格の降順にソートする必要があります.
GET /taobao/goods/_search?q=name:yagao&sort=price:desc
5.2、query DSL
DSL:Domain Specified Language,特定の分野の言語http request body:要求体、jsonのフォーマットで検索文法を構築することができて、比較的に便利で、各種の複雑な文法を構築することができて、query string searchよりきっととても強いです
5.2.1すべてのクエリー
GET /taobao/goods/_search
{
"query": {
"match_all": {}
}
}
5.2.2照会名称yagaoを含む商品を価格降順で並べ替える
GET /taobao/goods/_search
{
"query": {
"match":{
"name":"yagao"
}
},
"sort": [
{
"price": "desc"
}
]
}
5.2.3ページごとに商品を検索し、合計3つの商品につき、1ページにつき1つの商品が表示されたと仮定し、2ページ目が表示されたので、2つ目の商品が検出されます
GET /taobao/goods/_search
{
"query": {
"match_all": {}
},
"from": 1,
"size": 1
}
5.2.4クエリーが返すフィールドのリストを指定する
GET /taobao/goods/_search
{
"query": {"match_all": {}},
"_source":["name","producer"]
}
結果は次のように返されます.
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "taobao",
"_type": "goods",
"_id": "4",
"_score": 1,
"_source": {
"name": "heiren",
"producer": "yagao producer"
}
},
......
]
}
}
5.3、query filter
検索商品名にはyagaoが含まれており、価格が20元以上の商品
GET /taobao/goods/_search
{
"query": {
"bool": {
"must":{
"match":{
"name":"yagao"
}
},
"filter": {
"range":{
"price":{
"gt":20
}
}
}
}
}
}
5.4、full-text search(全文検索)
Producerにyagaoとproducerが含まれている商品を検索します.すなわち、matchのクエリー条件をスペースで区切ることです.
GET /taobao/goods/_search
{
"query":{
"match":{
"producer": "yagao producer"
}
}
}
クエリの結果は
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0.78549397,
"hits": [
{
"_index": "taobao",
"_type": "goods",
"_id": "4",
"_score": 0.78549397,
"_source": {
"name": "heiren",
"desc": "youxiao qingjie",
"price": 70,
"producer": "yagao producer"
}
},
{
"_index": "taobao",
"_type": "goods",
"_id": "1",
"_score": 0.25811607,
"_source": {
"name": "gaolujie yagao",
"desc": "youxiao fangzhu",
"price": 25,
"producer": "gaolujie producer"
}
},
{
"_index": "taobao",
"_type": "goods",
"_id": "3",
"_score": 0.25811607,
"_source": {
"name": "zhonghua",
"desc": "youxiao zhonghua",
"price": 55,
"producer": "zhonghua producer"
}
},
{
"_index": "taobao",
"_type": "goods",
"_id": "2",
"_score": 0.16358379,
"_source": {
"name": "jiajieshi yagao",
"desc": "youxiao fangzhu",
"price": 30,
"producer": "jiajieshi producer"
}
}
]
}
}
複雑なクエリー
GET /taobao/goods/_search
{
"query":{
"bool":{
"must":{
"match":{
"producer":"yagao producer"
}
},
"filter": {
"range":{
"price":{
"gt":30
}
}
}
}
},
"sort":{
"price":"asc"
}
}
5.5、phrase search(フレーズ検索)
全文検索に対応して、逆に全文検索は入力した検索列を分解して、インデックスの中に並べ替えて一つ一つマッチングして、上のいずれかの分解後の単語にマッチングできれば、結果としてphrase searchを返すことができて、入力した検索列を要求して、指定したフィールドのテキストの中で、完全にそっくりを含んでこそ、マッチングを計算することができます.結果として返される
GET /taobao/goods/_search
{
"query":{
"match_phrase":{
"producer":"yagao producer"
}
}
}
6、データ分析
6.1 tagあたりの商品数を計算する
GET /taobao/goods/_search
{
"size":0,// hits/hits
"aggs": { //aggs ,
"group_by_tag": {//
"terms": {// terms,
"field": "tag"// tag ,tag jsonarray
}
}
}
}
初めてtagを使用してパケットをグループ化するとエラーが表示されます.この場合、tagフィールドfielddataをtrueに設定する必要があります.以下に示します.
PUT /taobao/_mapping/goods
{
"properties": {
"tag":{
"type":"text",
"fielddata": true
}
}
}
結果は以下の通りです.
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fangzhu",
"doc_count": 2
},
{
"key": "meibai",
"doc_count": 2
},
{
"key": "qingxin",
"doc_count": 2
}
]
}
}
}
6.2名前にyagaoが含まれている商品について、tagあたりの商品数を計算する
上のaggsと比較してqueryの条件が多くなりました
GET /taobao/goods/_search
{
"size":0,
"query": {
"match": {
"name": "yagao"
}
},
"aggs":{
"group_by_tag":{
"terms": {
"field": "tag"
}
}
}
}
6.3グループに分けてから、グループごとの平均値を計算し、tagごとの商品の平均価格を計算する
GET /taobao/goods/_search
{
"size":0,
"aggs": {
"group_by_tag": {
"terms": {
"field": "tag"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
次の結果が返されます.
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fangzhu",
"doc_count": 2,
"avg_price": {
"value": 55.5
}
},
{
"key": "meibai",
"doc_count": 2,
"avg_price": {
"value": 35.5
}
},
{
"key": "qingxin",
"doc_count": 2,
"avg_price": {
"value": 40
}
}
]
}
}
}
6.4
各tagの商品の平均価格を計算し、平均価格の降順にソートする
GET /taobao/goods/_search
{
"size":0,
"aggs":{
"group_by_tag":{
"terms":{
"field": "tag",
"order": {
"avg_price": "desc"
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
結果は
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fangzhu",
"doc_count": 2,
"avg_price": {
"value": 55.5
}
},
{
"key": "qingxin",
"doc_count": 2,
"avg_price": {
"value": 40
}
},
{
"key": "meibai",
"doc_count": 2,
"avg_price": {
"value": 35.5
}
}
]
}
}
}
6.5指定された価格範囲区間でグループ化し、各グループ内でtagでグループ化し、最後に各グループの平均価格を計算する
GET /taobao/goods/_search
{
"size":0,
"aggs": {
"group_by_price": {
"range": {
"field": "price",
"ranges":[
{
"from":0,
"to":20
},
{
"from":20,
"to":40
},
{
"from":40,
"to":60
}
]
},
"aggs": {
"group_by_tag":{
"terms": {
"field": "tag"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
結果は次のとおりです.
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_price": {
"buckets": [
{
"key": "0.0-20.0",
"from": 0,
"to": 20,
"doc_count": 0,
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
},
{
"key": "20.0-40.0",
"from": 20,
"to": 40,
"doc_count": 1,
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "meibai",
"doc_count": 1,
"avg_price": {
"value": 30
}
},
{
"key": "qingxin",
"doc_count": 1,
"avg_price": {
"value": 30
}
}
]
}
},
{
"key": "40.0-60.0",
"from": 40,
"to": 60,
"doc_count": 2,
"group_by_tag": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "fangzhu",
"doc_count": 1,
"avg_price": {
"value": 41
}
},
{
"key": "meibai",
"doc_count": 1,
"avg_price": {
"value": 41
}
},
{
"key": "qingxin",
"doc_count": 1,
"avg_price": {
"value": 50
}
}
]
}
}
]
}
}
}