{"id":5400,"date":"2024-09-16T16:01:04","date_gmt":"2024-09-16T08:01:04","guid":{"rendered":""},"modified":"2024-09-16T16:01:04","modified_gmt":"2024-09-16T08:01:04","slug":"elasticsearch \u5ba2\u6237\u7aef\u5de5\u5177_\u5982\u4f55\u7528ElasticSearch\u8fdb\u884c\u673a\u5668\u5b66\u4e60","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5400.html","title":{"rendered":"elasticsearch \u5ba2\u6237\u7aef\u5de5\u5177_\u5982\u4f55\u7528ElasticSearch\u8fdb\u884c\u673a\u5668\u5b66\u4e60"},"content":{"rendered":"
\n

\u524d\u8a00<\/h2>\n

\u673a\u5668\u5b66\u4e60\u5df2\u7ecf\u5728\u73b0\u5728\u7684\u5de5\u4e1a\u5b9e\u8df5\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f5c\u4e3a\u5f3a\u5927\u641c\u7d22\u5f15\u64ce\u7684ElasticSearch\u4e5f\u57286.3\u5f00\u59cb\u5185\u7f6e\u4e86\u5bf9\u673a\u5668\u5b66\u4e60\u7684\u652f\u6301\u3002<\/p>\n

\n \"elasticsearch <\/p>\n

ElasticSearch\u4e5f\u57286.3\u5f00\u59cb\u5185\u7f6e\u4e86\u5bf9\u673a\u5668\u5b66\u4e60\u7684\u652f\u6301<\/p>\n<\/p><\/div>\n

\u6982\u8ff0<\/h2>\n

\u4ece\u5e94\u7528\u89d2\u5ea6\u6765\u770b\uff0c\u5982\u679c\u4f60\u6709\u5f02\u5e38\u4fa6\u6d4b\u548c\u6570\u636e\u56de\u5f52\u65b9\u9762\u7684\u9700\u6c42\uff0c\u5e76\u4e14\u6570\u636e\u4e0d\u9700\u8981\u7279\u522b\u5904\u7406\uff0c\u76f4\u63a5\u4ecees\u91cc\u5c31\u53ef\u4ee5\u63a5\u5165\uff0c\u53ef\u4ee5\u9009\u62e9Es\u5185\u7f6e\u7684\u673a\u5668\u5b66\u4e60\u529f\u80fd\uff0c\u8fd9\u6837\u53c8\u5feb\u53c8\u8fc5\u901f\u3002\u4f46\u662f\u5982\u679c\u8981\u501f\u52a9\u66f4\u591a\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u6765\u8fdb\u884c\u5efa\u6a21\uff0c\u9009\u62e9python\u7684Eland\u6a21\u5757\u8fdb\u884c\u673a\u5668\u5b66\u4e60\u5c31\u6bd4\u8f83\u5408\u9002\u3002\u4e0b\u9762\u4f1a\u5c31\u8fd92\u79cd\u673a\u5668\u5b66\u4e60\u65b9\u5f0f,\u4ece\u5b89\u88c5\u5230\u5e94\u7528\u8fdb\u884c\u4e00\u4e00\u4ecb\u7ecd\u3002<\/p>\n

\n \"elasticsearch <\/p>\n

Es\u5185\u7f6e\u7684\u673a\u5668\u5b66\u4e60\u529f\u80fd<\/p>\n<\/p><\/div>\n

elasticsearch\u5185\u7f6e\u7684\u673a\u5668\u5b66\u4e60<\/h2>\n

Kibana\u4e3b\u9875\u4e0a\u52a0\u8f7d\u6837\u672cWeb\u65e5\u5fd7\u6570\u636e\u96c6\u540e\uff0c\u70b9\u51fb \u67e5\u770b\u6570\u636e<\/strong>> ML\u4f5c\u4e1a<\/strong>\u3002<\/p>\n

\u5728\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5f53\u60a8kibana_sample_data_logs \u5728\"\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\"<\/strong>\u6216\"\u5f02\u5e38\u68c0\u6d4b\"<\/strong>\u4f5c\u4e1a\u5411\u5bfc\u4e2d\u9009\u62e9\u7d22\u5f15\u6a21\u5f0f\u65f6\uff0c\u4f7f\u7528\u5176\u5df2\u77e5\u914d\u7f6e\u521b\u5efa\u4f5c\u4e1a\u3002\u9009\u62e9 Kibana\u793a\u4f8b\u6570\u636eWeb\u65e5\u5fd7<\/strong>\u914d\u7f6e\u3002<\/p>\n

Kibana\u652f\u6301\u56db\u79cd\u7c7b\u578b\u7684\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a<\/p>\n

    \n
  • 1. \u5728Kibana\u4e2d\uff0cSingle-metric jobs\uff1a\u6570\u636e\u5206\u6790\u4ec5\u5728\u4e00\u4e2a\u7d22\u5f15\u5b57\u6bb5\u4e0a\u6267\u884c<\/li>\n
  • 2. Multi-metric jobs\uff1a\u53ef\u4ee5\u5bf9\u591a\u4e2a\u7d22\u5f15\u5b57\u6bb5\u6267\u884c\u6570\u636e\u5206\u6790\uff1b \u4f46\u662f\uff0c\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u5206\u522b\u8fdb\u884c\u5206\u6790<\/li>\n
  • 3. Advanced jobs\uff1a\u53ef\u4ee5\u5bf9\u591a\u4e2a\u7d22\u5f15\u5b57\u6bb5\u6267\u884c\u6570\u636e\u5206\u6790\u3002\u63d0\u4f9b\u68c0\u6d4b\u5668\u548c\u5f71\u54cd\u8005\u7684\u5b8c\u6574\u914d\u7f6e\u8bbe\u7f6e<\/li>\n
  • 4. Population jobs\uff1a\u5bf9\u4e0d\u5e38\u89c1\u6570\u636e(\u4f8b\u5982\u68c0\u6d4b\u603b\u4f53\u4e2d\u7684\u5f02\u5e38\u503c)\u7684\u5206\u5e03\u884c\u4e3a\u7684\u6570\u636e\u5206\u6790<\/li>\n
  • \u73b0\u5728\u4ee5Single-metric jobs\u4e3a\u4f8b\uff0c\u5b66\u4e60\u5982\u4f55\u4f7f\u7528Elasticsearch\u5185\u5efa\u673a\u5668\u5b66\u4e60\u529f\u80fd\u3002<\/li>\n<\/ul>\n

    \u6837\u672c\u4f5c\u4e1a(low_request_rate)\u4e4b\u4e00\u662f\u5355\u4e2a\u5ea6\u91cf\u5f02\u5e38\u68c0\u6d4b\u4f5c\u4e1a<\/em>\u3002\u5b83\u5177\u6709\u4f7f\u7528\u8be5low_count\u529f\u80fd\u548c\u6709\u9650\u5de5\u4f5c\u5c5e\u6027\u7684\u5355\u4e2a\u68c0\u6d4b\u5668\u3002\u5982\u679c\u8981\u786e\u5b9a\u7f51\u7ad9\u4e0a\u7684\u8bf7\u6c42\u7387\u4f55\u65f6\u663e\u7740\u4e0b\u964d\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u8fd9\u6837\u7684\u5de5\u4f5c\u3002<\/p>\n

    \u8ba9\u6211\u4eec\u4ece\u5728Single Metric Viewer\u4e2d\u67e5\u770b<\/strong>\u8fd9\u4e2a\u7b80\u5355\u7684\u5de5\u4f5c\u5f00\u59cb \uff1a<\/p>\n

    \n \"elasticsearch\n <\/div>\n

    \u8be5\u89c6\u56fe\u5305\u542b\u4e00\u4e2a\u56fe\u8868\uff0c\u8be5\u56fe\u8868\u8868\u793a\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u5b9e\u9645\u503c\u548c\u671f\u671b\u503c\u3002\u4ec5\u5f53\u4f5c\u4e1a\u5df2model_plot_config\u542f\u7528\u65f6\u624d\u53ef\u7528\u3002\u5b83\u53ea\u80fd\u663e\u793a\u4e00\u4e2a\u65f6\u95f4\u5e8f\u5217\u3002<\/p>\n

    \u56fe\u8868\u4e2d\u7684\u84dd\u7ebf\u4ee3\u8868\u5b9e\u9645\u6570\u636e\u503c\u3002\u84dd\u8272\u9634\u5f71\u533a\u57df\u8868\u793a\u671f\u671b\u503c\u7684\u754c\u9650\u3002\u4e0a\u9650\u548c\u4e0b\u9650\u4e4b\u95f4\u7684\u533a\u57df\u662f\u6a21\u578b\u6700\u53ef\u80fd\u7684\u503c\u3002\u5982\u679c\u67d0\u4e2a\u503c\u4e0d\u5728\u8be5\u533a\u57df\u5185\uff0c\u5219\u53ef\u4ee5\u8bf4\u5b83\u662f\u5f02\u5e38\u7684\u3002<\/p>\n

    \u5c06\u65f6\u95f4\u9009\u62e9\u5668\u6ed1\u52a8\u5230\u65f6\u95f4\u5e8f\u5217\u4e2d\u5305\u542b\u7ea2\u8272\u5f02\u5e38\u6570\u636e\u70b9\u7684\u90e8\u5206\u3002\u5982\u679c\u5c06\u9f20\u6807\u60ac\u505c\u5728\u8be5\u70b9\u4e0a\uff0c\u5219\u53ef\u4ee5\u67e5\u770b\u66f4\u591a\u4fe1\u606f\u3002\u9664\u4e86\u5f02\u5e38\u4fa6\u6d4b\uff0ces\u8fd8\u53ef\u4ee5\u65b9\u4fbf\u7684\u505a\u6570\u503c\u56de\u5f52\u9884\u6d4b\u3002<\/p>\n

    python\u7684eland\u6a21\u5757<\/h2>\n

    \u5982\u679c\u9700\u8981\u5f15\u5165\u66f4\u591a\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8bad\u7ec3\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528eland\u6a21\u5757\u6765\u548cElasticSearch\u534f\u4f5c\u3002<\/p>\n

    \u4e3a\u4ec0\u4e48\u4f1a\u6709eland?<\/strong><\/p>\n

    \u6570\u636e\u79d1\u5b66\u5bb6\u901a\u5e38\u4e0d\u4e60\u60efNoSQL\u6570\u636e\u5e93\u5f15\u64ce\u6267\u884c\u5e38\u89c1\u4efb\u52a1\uff0c\u751a\u81f3\u4e0d\u4f9d\u8d56\u590d\u6742\u7684REST API\u8fdb\u884c\u5206\u6790\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Elasticsearch\u7684\u4f4e\u7ea7python\u5ba2\u6237\u7aef\u5904\u7406\u5927\u91cf\u6570\u636e\u4e5f\u4e0d\u662f\u90a3\u4e48\u76f4\u89c2\uff0c\u5e76\u4e14\u5bf9\u4e8e\u6765\u81eaSWE\u4ee5\u5916\u9886\u57df\u7684\u4eba\u6765\u8bf4\uff0c\u5b66\u4e60\u66f2\u7ebf\u6709\u4e9b\u9661\u5ced\u3002<\/p>\n

    \u5c3d\u7ba1Elastic\u4e3a\u589e\u5f3a\u7528\u4e8e\u5206\u6790\u548c\u6570\u636e\u79d1\u5b66\u7528\u4f8b\u7684ELK\u5806\u6808\u505a\u51fa\u4e86\u5de8\u5927\u7684\u52aa\u529b\uff0c\u4f46\u5b83\u4ecd\u7136\u7f3a\u4e4f\u4e0e\u73b0\u6709\u6570\u636e\u79d1\u5b66\u751f\u6001\u7cfb\u7edf(pandas\uff0cnumpy\uff0cscikit-learn\uff0cPyTorch\u548c\u5176\u4ed6\u6d41\u884c\u7684\u5e93)\u7684\u4fbf\u6377\u63a5\u53e3\u3002<\/p>\n

    \u7684\u63a8\u51fa\u662f\u4e00\u4e2a\u5168\u65b0\u7684Python Elasticsearch\u5ba2\u6237\u7aef\u548c\u5de5\u5177\u5305\uff0c\u5177\u6709\u5f3a\u5927(\u4e14\u719f\u6089)\u7684\u7c7b\u4f3c\u4e8epandas\u7684API\uff0c\u7528\u4e8e\u5206\u6790\uff0cETL\u548c\u673a\u5668\u5b66\u4e60\u3002<\/p>\n

    Eland\u5728\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u73b0\u6709\u7684Python API\u548c\u6570\u636e\u7ed3\u6784\u6765\u7b80\u5316\u5728numpy\uff0cpandas\uff0cscikit-learn\u548c\u5176Elasticsearch\u652f\u6301\u7684\u7b49\u6548\u9879\u4e4b\u95f4\u7684\u5207\u6362\u3002\u901a\u5e38\uff0c\u6570\u636e\u9a7b\u7559\u5728Elasticsearch\u4e2d\uff0c\u800c\u4e0d\u662f\u5185\u5b58\u4e2d\uff0c\u8fd9\u4f7fEland\u53ef\u4ee5\u8bbf\u95eeElasticsearch\u4e2d\u5b58\u50a8\u7684\u5927\u578b\u6570\u636e\u96c6\u3002Eland\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5de5\u5177\uff0c\u53ef\u4ee5\u4ece\uff0c\u548c\u7b49\u901a\u7528\u5e93\u7ecf\u8fc7\u8bad\u7ec3\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u4e0a\u4f20\u5230Elasticsearch\u4e2d\u3002<\/p>\n

    Eland\u4f7f\u6570\u636e\u79d1\u5b66\u5bb6\u53ef\u4ee5\u6709\u6548\u5730\u4f7f\u7528\u5df2\u7ecf\u5f3a\u5927\u7684Elasticsearch\u5206\u6790\u548cML\u529f\u80fd\uff0c\u800c\u65e0\u9700\u5bf9Elasticsearch\u53ca\u5176\u8bb8\u591a\u590d\u6742\u77e5\u8bc6\u6709\u6df1\u5165\u7684\u4e86\u89e3\u3002<\/p>\n

    Elasticsearch\u7684\u529f\u80fd\u548c\u6982\u5ff5\u88ab\u8f6c\u6362\u4e3a\u66f4\u6613\u4e8e\u8bc6\u522b\u7684\u8bbe\u7f6e\u3002\u4f8b\u5982\uff0cElasticsearch\u7d22\u5f15\u53ca\u5176\u6587\u6863\uff0c\u6620\u5c04\u548c\u5b57\u6bb5\u6210\u4e3a\u5177\u6709\u884c\u548c\u5217\u7684\u6570\u636e\u6846\uff0c\u5c31\u50cf\u6211\u4eec\u4ee5\u524d\u5728\u4f7f\u7528pandas\u65f6\u6240\u770b\u5230\u7684\u90a3\u6837\u3002<\/p>\n

    Eland\u7684\u5b89\u88c5<\/strong><\/p>\n

    \u53ef\u4ee5\u4f7f\u7528Pip\u4ece\u5b89\u88c5Eland \uff1a<\/p>\n

    $ python -m pip\u5b89\u88c5eland<\/code><\/pre>\n

    \u4e5f\u53ef\u4ee5\u4f7f\u7528Conda\u4ece\u5b89\u88c5Eland \uff1a<\/p>\n

    $ conda\u5b89\u88c5-c conda-forge eland<\/code><\/pre>\n

    Eland\u94fe\u63a5Es<\/strong><\/p>\n

    Eland\u4f7f\u7528\u8fde\u63a5\u5230Elasticsearch\u3002\u8be5\u5ba2\u6237\u7aef\u652f\u6301\u4e00\u7cfb\u5217\u3002\u53ef\u4ee5\u5c06\u5b9e\u4f8b\u4f20\u9012elasticsearch.Elasticsearch\u7ed9Eland API\uff0c\u4e5f\u53ef\u4ee5\u5c06\u5305\u542b\u4e3b\u673a\u7684\u5b57\u7b26\u4e32\u4f20\u9012\u7ed9\u4ee5\u4e0b\u5bf9\u8c61\uff1a<\/p>\n

    import eland as ed# Connecting to an Elasticsearch instance running on 'localhost:9200'df = ed.DataFrame(\"localhost:9200\", es_index_pattern=\"flights\")# Connecting to an Elastic Cloud instancefrom elasticsearch import Elasticsearches = Elasticsearch(cloud_id=\"cluster-name:...\",http_auth=(\"elastic\", \"\"))df = ed.DataFrame(es, es_index_pattern=\"flights\")<\/code><\/pre>\n

    \u7528eland\u8fdb\u884c\u673a\u5668\u5b66\u4e60<\/strong><\/p>\n

    eland.DataFrame\u5728\u7c7b\u4f3c\u4e8ePandas\u7684API\u4e2d\u5305\u88c5Elasticsearch\u7d22\u5f15\uff0c\u5e76\u5c06\u6240\u6709\u5bf9\u6570\u636e\u7684\u5904\u7406\u548c\u8fc7\u6ee4\u63a8\u8fdf\u5230Elasticsearch\u800c\u4e0d\u662f\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u4eceJupyter Notebook\u4e2d\u5728Elasticsearch\u4e2d\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u8ba1\u7b97\u673a\u8fc7\u8f7d\u3002<\/p>\n

    \u73b0\u5728\u53ef\u4ee5\u5bf9xboost\u6846\u67b6\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u540e\uff0c\u5c06\u6a21\u578b\u90e8\u7f72\u5230Elasticsearch\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5b9e\u73b0\u5bf9\u6570\u636e\u7684\u9884\u6d4b\u4e86\u3002\u4e00\u5207\u5f88\u7b80\u5355\u3002<\/p>\n

    >>> from xgboost import XGBClassifier>>> from eland.ml import ImportedMLModel# Train and exercise an XGBoost ML model locally>>> xgb_model = XGBClassifier(booster=\"gbtree\")>>> xgb_model.fit(training_data[0], training_data[1])>>> xgb_model.predict(training_data[0])[0 1 1 0 1 0 0 0 1 0]# Import the model into Elasticsearch>>> es_model = ImportedMLModel(es_client=\"localhost:9200\",model_id=\"xgb-classifier\",model=xgb_model,feature_names=[\"f0\", \"f1\", \"f2\", \"f3\", \"f4\"],)# Exercise the ML model in Elasticsearch with the training data>>> es_model.predict(training_data[0])[0 1 1 0 1 0 0 0 1 0]<\/code><\/pre>\n

    \u7ed3\u675f\u8bed<\/strong><\/p>\n

    es\u4f5c\u4e3a\u641c\u7d22\u5f15\u64ce\uff0c\u8d4b\u80fd\u4e86\u5feb\u901f\u6392\u5e8f\uff0c\u641c\u7d22\u7684\u573a\u666f\u3002\u73b0\u5728\u5185\u7f6e\u7684\u673a\u5668\u5b66\u4e60\u6a21\u5757\u4e3a\u501f\u52a9es\u641c\u7d22\u7684\u573a\u666f\u53c8\u589e\u52a0\u4e86\u5f02\u5e38\u4fa6\u6d4b\uff0c\u56de\u5f52\u9884\u6d4b\u7b49\u5f3a\u5927\u7684ai\u80fd\u529b\uff0c\u65e0\u7591\u4e3aes\u5728\u548c\u5176\u4ed6\u641c\u7d22\u5f15\u64ce\u7ade\u4e89\u4e2d\u589e\u52a0\u4e86\u5f3a\u5927\u52a9\u529b\u3002\u5bf9\u8fd9\u65b9\u9762\u6709\u5174\u8da3\u7684\u8bfb\u8005\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\u4eec\uff0c\u6301\u7eed\u83b7\u53d6\u8fd9\u65b9\u9762\u8d44\u8baf\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"elasticsearch \u5ba2\u6237\u7aef\u5de5\u5177_\u5982\u4f55\u7528ElasticSearch\u8fdb\u884c\u673a\u5668\u5b66\u4e60\u524d\u8a00\u673a\u5668\u5b66\u4e60\u5df2\u7ecf\u5728\u73b0\u5728\u7684\u5de5\u4e1a\u5b9e\u8df5\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5400"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5400"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5400\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}