{"id":40860,"date":"2023-04-05T11:53:08","date_gmt":"2023-11-15T09:48:44","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/"},"modified":"2024-01-15T10:47:41","modified_gmt":"2024-01-15T02:47:41","slug":"%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","title":{"rendered":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u3002<\/p>\n<p>Elasticsearch\u7684\u6620\u5c04\u5e76\u6ca1\u6709\u7279\u522b\u590d\u6742\u7684\u90e8\u5206\uff0c<br \/>\n\u53ea\u9700\u8981\u5c06\u7c7b\u578b\u6307\u5b9a\u4e3a\u5173\u952e\u8bcd\u5373\u53ef\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c1\">#!\/usr\/bin\/python3\r\n# -*- coding:utf-8 -*-\r\n<\/span>\r\n<span class=\"kn\">from<\/span> <span class=\"nn\">elasticsearch<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">Elasticsearch<\/span>\r\n\r\n<span class=\"n\">es<\/span> <span class=\"o\">=<\/span> <span class=\"n\">Elasticsearch<\/span><span class=\"p\">(<\/span><span class=\"s\">'http:\/\/localhost:9200'<\/span><span class=\"p\">)<\/span>\r\n<span class=\"n\">mapping<\/span> <span class=\"o\">=<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"s\">\"mappings\"<\/span><span class=\"p\">:<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"s\">\"properties\"<\/span><span class=\"p\">:<\/span> <span class=\"p\">{<\/span>\r\n            <span class=\"s\">\"category\"<\/span> <span class=\"p\">:<\/span> <span class=\"p\">{<\/span><span class=\"s\">\"type\"<\/span> <span class=\"p\">:<\/span> <span class=\"s\">\"keyword\"<\/span><span class=\"p\">}<\/span>\r\n        <span class=\"p\">}<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n\r\n<span class=\"n\">es<\/span><span class=\"p\">.<\/span><span class=\"n\">indices<\/span><span class=\"p\">.<\/span><span class=\"n\">create<\/span><span class=\"p\">(<\/span><span class=\"n\">index<\/span><span class=\"o\">=<\/span><span class=\"s\">\"test\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">body<\/span><span class=\"o\">=<\/span><span class=\"n\">mapping<\/span><span class=\"p\">)<\/span>\r\n<span class=\"n\">es<\/span><span class=\"p\">.<\/span><span class=\"n\">close<\/span><span class=\"p\">()<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>$ .\/mapping.py\r\n<\/code><\/pre>\n<p>&#8211; \u5728\u8fd9\u91cc\uff0c\u8fdb\u884c\u6620\u5c04\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"c1\">#!\/usr\/bin\/python3\r\n# -*- coding:utf-8 -*-\r\n<\/span>\r\n<span class=\"kn\">from<\/span> <span class=\"nn\">elasticsearch<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">Elasticsearch<\/span>\r\n\r\n<span class=\"n\">es<\/span> <span class=\"o\">=<\/span> <span class=\"n\">Elasticsearch<\/span><span class=\"p\">(<\/span><span class=\"s\">'http:\/\/localhost:9200'<\/span><span class=\"p\">)<\/span>\r\n<span class=\"n\">data<\/span> <span class=\"o\">=<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"s\">\"category\"<\/span> <span class=\"p\">:<\/span> <span class=\"p\">[<\/span><span class=\"s\">\"aaa\"<\/span><span class=\"p\">,<\/span> <span class=\"s\">\"bbb\"<\/span><span class=\"p\">,<\/span> <span class=\"s\">\"ccc\"<\/span><span class=\"p\">]<\/span>\r\n<span class=\"p\">}<\/span>\r\n\r\n<span class=\"n\">es<\/span><span class=\"p\">.<\/span><span class=\"n\">index<\/span><span class=\"p\">(<\/span><span class=\"n\">index<\/span><span class=\"o\">=<\/span><span class=\"s\">\"test\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">body<\/span><span class=\"o\">=<\/span><span class=\"n\">data<\/span><span class=\"p\">)<\/span>\r\n\r\n<span class=\"n\">es<\/span><span class=\"p\">.<\/span><span class=\"n\">close<\/span><span class=\"p\">()<\/span>\r\n<\/code><\/pre>\n<p>\u5c31\u50cf\u4e0a\u9762\u63d0\u5230\u7684\u6570\u636e\u4e00\u6837\uff0c\u6570\u7ec4\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u6ce8\u518c\u3002<\/p>\n<pre class=\"post-pre\"><code>.\/regist.py\r\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c<\/p>\n<p>\u901a\u8fc7\u6ce8\u518c\u6570\u7ec4\uff0c<br \/>\n\u53ef\u4ee5\u5b9e\u73b0\u5728Kibana\u4e0a\u8fdb\u884c\u53ef\u89c6\u5316\u65f6\u6309\u7167\u7c7b\u522b\u8fdb\u884c\u663e\u793a\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u3002 Elasticsearch\u7684\u6620\u5c04\u5e76\u6ca1\u6709\u7279\u522b\u590d\u6742 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40860","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230elasticsearch\u7684\u65b9\u6cd5\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5\" \/>\n<meta property=\"og:description\" content=\"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u3002 Elasticsearch\u7684\u6620\u5c04\u5e76\u6ca1\u6709\u7279\u522b\u590d\u6742 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230elasticsearch\u7684\u65b9\u6cd5\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-15T09:48:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T02:47:41+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\",\"name\":\"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-11-15T09:48:44+00:00\",\"dateModified\":\"2024-01-15T02:47:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230elasticsearch\u7684\u65b9\u6cd5\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5","og_description":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u3002 Elasticsearch\u7684\u6620\u5c04\u5e76\u6ca1\u6709\u7279\u522b\u590d\u6742 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230elasticsearch\u7684\u65b9\u6cd5\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-11-15T09:48:44+00:00","article_modified_time":"2024-01-15T02:47:41+00:00","author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/","name":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-11-15T09:48:44+00:00","dateModified":"2024-01-15T02:47:41+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Python\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u6ce8\u518c\u5230Elasticsearch\u7684\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8python%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%b3%a8%e5%86%8c%e5%88%b0elasticsearch%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=40860"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40860\/revisions"}],"predecessor-version":[{"id":58761,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40860\/revisions\/58761"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=40860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=40860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=40860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}