{"id":89023,"date":"2026-08-02T09:01:06","date_gmt":"2026-08-02T01:01:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/89023.html"},"modified":"2026-08-02T09:01:06","modified_gmt":"2026-08-02T01:01:06","slug":"elasticsearch%ef%bc%9a%e6%90%9c%e7%b4%a2%e6%95%99%e7%a8%8b-%e5%90%91%e9%87%8f%e6%90%9c%e7%b4%a2%ef%bc%88%e4%ba%8c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/89023.html","title":{"rendered":"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u7ee7\u4e4b\u524d\u6587\u7ae0 \u201cElasticsearch&#xff1a;\u641c\u7d22\u6559\u7a0b &#8211; \u5168\u6587\u641c\u7d22&#xff08;\u4e00&#xff09;\u201d\u3002\u5728\u7ee7\u7eed\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u524d&#xff0c;\u4f60\u5fc5\u987b\u4ed4\u7ec6\u9605\u8bfb\u4e4b\u524d\u7684\u90a3\u7bc7\u6587\u7ae0\u3002<\/p>\n<\/p>\n<h3>Embedding \u7b80\u4ecb<\/h3>\n<p>\u5728 Machine Learning \u4e2d&#xff0c;embedding \u662f\u4e00\u4e2a vector&#xff08;\u6570\u5b57\u6570\u7ec4&#xff09;&#xff0c;\u7528\u4e8e\u8868\u793a\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u5bf9\u8c61&#xff0c;\u4f8b\u5982 words\u3001sentences\u3001images \u6216 videos\u3002<\/p>\n<p>embedding \u7684\u4e00\u4e2a\u91cd\u8981\u7279\u6027\u662f&#xff1a;\u5982\u679c\u4e24\u4e2a embeddings \u8868\u793a\u7684\u662f\u76f8\u4f3c\u6216\u76f8\u5173\u7684\u73b0\u5b9e\u4e16\u754c\u5b9e\u4f53&#xff0c;\u90a3\u4e48\u5b83\u4eec\u672c\u8eab\u4e5f\u4f1a\u5177\u6709\u4e00\u5b9a\u7684\u76f8\u4f3c\u6027\u3002\u56e0\u6b64&#xff0c;\u53ef\u4ee5\u5bf9 embeddings \u8fdb\u884c\u6bd4\u8f83&#xff0c;\u5e76\u8ba1\u7b97\u5b83\u4eec\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002<\/p>\n<p>\u4ece search application \u7684\u89d2\u5ea6\u6765\u770b&#xff0c;\u5728 vector space \u4e2d\u641c\u7d22 embeddings&#xff0c;\u901a\u5e38\u80fd\u591f\u627e\u5230\u4e0e\u6982\u5ff5\u76f8\u5173\u7684\u7ed3\u679c&#xff0c;\u800c\u4e0d\u4ec5\u4ec5\u662f\u4e0e\u641c\u7d22\u63d0\u793a\u4e2d\u8f93\u5165\u7684\u7cbe\u786e keywords \u5339\u914d\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u7684\u8fd9\u4e00\u90e8\u5206\u4e2d&#xff0c;\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u514d\u8d39\u63d0\u4f9b\u7684 machine learning models \u751f\u6210 embeddings&#xff0c;\u7136\u540e\u4f7f\u7528 Elasticsearch \u7684 vector database \u529f\u80fd\u6765\u5b58\u50a8\u548c\u641c\u7d22\u8fd9\u4e9b embeddings\u3002<\/p>\n<p>\u5728\u672c\u90e8\u5206\u7684\u6700\u540e&#xff0c;\u4f60\u8fd8\u5c06\u5b66\u4e60\u5982\u4f55\u5c06 vector search \u4e0e full-text search \u7684\u7ed3\u679c\u7ed3\u5408\u8d77\u6765&#xff0c;\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684 hybrid search \u89e3\u51b3\u65b9\u6848&#xff0c;\u4ece\u800c\u517c\u987e\u8fd9\u4e24\u79cd\u65b9\u6cd5\u7684\u4f18\u52bf\u3002<\/p>\n<\/p>\n<h3>\u751f\u6210 Embedding<\/h3>\n<p>\u5728\u672c\u8282\u4e2d&#xff0c;\u4f60\u5c06\u5b66\u4e60\u76ee\u524d\u7528\u4e8e\u751f\u6210 text embeddings \u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\u4e4b\u4e00&#xff0c;\u5b83\u57fa\u4e8e SentenceTransformers framework\u3002<\/p>\n<p>\u5728\u4f60\u63a2\u7d22\u5e76\u719f\u6089 embeddings \u7684\u4f7f\u7528\u8fc7\u7a0b\u4e2d&#xff0c;\u63a8\u8350\u4f7f\u7528 SentenceTransformers\u3002\u8be5 framework \u63d0\u4f9b\u7684 models \u53ef\u4ee5\u5b89\u88c5\u5230\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a&#xff0c;\u65e0\u9700 GPU \u4e5f\u80fd\u83b7\u5f97\u4e0d\u9519\u7684\u6027\u80fd&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u514d\u8d39\u4f7f\u7528\u3002<\/p>\n<\/p>\n<h4>\u5b89\u88c5 SentenceTransformers<\/h4>\n<p>SentenceTransformers framework \u4ee5 Python package \u7684\u5f62\u5f0f\u63d0\u4f9b\u3002<\/p>\n<p>\u8bf7\u786e\u4fdd\u4f60\u7684 Python virtual environment \u5df2\u6fc0\u6d3b&#xff0c;\u7136\u540e\u5728 terminal \u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u8be5 framework&#xff1a;<\/p>\n<p>pip install sentence-transformers <\/p>\n<p>\u4e0e\u5f80\u5e38\u4e00\u6837&#xff0c;\u6bcf\u5f53\u4f60\u5411\u9879\u76ee\u6dfb\u52a0\u65b0\u7684 dependencies \u65f6&#xff0c;\u6700\u597d\u66f4\u65b0\u4f60\u7684 requirements file&#xff1a;<\/p>\n<p>pip freeze &gt; requirements.txt <\/p>\n<h4>\u9009\u62e9\u4e00\u4e2a Model<\/h4>\n<p>\u4e0b\u4e00\u9879\u4efb\u52a1\u662f\u51b3\u5b9a\u4f7f\u7528\u54ea\u4e2a machine learning model \u6765\u751f\u6210 embeddings\u3002<\/p>\n<p>documentation \u4e2d\u63d0\u4f9b\u4e86\u4e00\u4efd pretrained models \u5217\u8868\u3002\u7531\u4e8e SentenceTransformers \u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684 framework&#xff0c;\u56e0\u6b64\u9664\u4e86\u5b98\u65b9\u63d0\u4f9b\u7684 models \u5916&#xff0c;\u8fd8\u6709\u8bb8\u591a\u7531\u5176\u4ed6\u7814\u7a76\u4eba\u5458\u521b\u5efa\u7684\u517c\u5bb9 models\u3002\u8981\u67e5\u770b\u6240\u6709\u53ef\u7528\u7684 models&#xff0c;\u53ef\u4ee5\u8bbf\u95ee HuggingFace \u4e0a\u5e26\u6709 SentenceTransformers \u6807\u7b7e\u7684 models\u3002<\/p>\n<p>\u5bf9\u4e8e\u672c\u6559\u7a0b\u6765\u8bf4&#xff0c;\u4e0d\u9700\u8981\u8fc7\u5ea6\u7ea0\u7ed3 model \u7684\u9009\u62e9&#xff0c;\u56e0\u4e3a\u4efb\u4f55 model \u90fd\u80fd\u591f\u6ee1\u8db3\u9700\u6c42\u3002<\/p>\n<p>SentenceTransformers documentation \u5bf9\u5176 pretrained models \u7ed9\u51fa\u4e86\u5982\u4e0b\u8bf4\u660e&#xff1a;<\/p>\n<p>\u201call-* models \u4f7f\u7528\u6240\u6709\u53ef\u7528\u7684\u8bad\u7ec3\u6570\u636e&#xff08;\u8d85\u8fc7 10 \u4ebf\u4e2a training pairs&#xff09;\u8fdb\u884c\u8bad\u7ec3&#xff0c;\u65e8\u5728\u4f5c\u4e3a\u901a\u7528\u6a21\u578b\u3002all-mpnet-base-v2 model \u63d0\u4f9b\u6700\u4f73\u8d28\u91cf&#xff0c;\u800c all-MiniLM-L6-v2 \u7684\u901f\u5ea6\u5feb 5 \u500d&#xff0c;\u540c\u65f6\u4ecd\u80fd\u63d0\u4f9b\u826f\u597d\u7684\u8d28\u91cf\u3002\u201d<\/p>\n<p>\u8fd9\u6bb5\u8bf4\u660e\u8868\u660e&#xff0c;all-MiniLM-L6-v2 model \u5728\u901f\u5ea6\u548c\u8d28\u91cf\u4e4b\u95f4\u53d6\u5f97\u4e86\u4e0d\u9519\u7684\u5e73\u8861&#xff0c;\u56e0\u6b64\u6211\u4eec\u5c06\u4f7f\u7528\u8fd9\u4e2a model\u3002<\/p>\n<p>\u8bf7\u5728\u8868\u683c\u4e2d\u627e\u5230\u8fd9\u4e2a model&#xff0c;\u7136\u540e\u70b9\u51fb \u201cinfo\u201d \u56fe\u6807\u67e5\u770b\u5b83\u7684\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802010102-6a6e96ce2e149.webp\" \/><\/p>\n<p>\u5173\u4e8e\u6240\u9009 model&#xff0c;\u8fd8\u6709\u4e00\u4e2a\u503c\u5f97\u4e86\u89e3\u7684\u91cd\u8981\u7ec6\u8282&#xff0c;\u90a3\u5c31\u662f\u5b83\u751f\u6210\u7684 embeddings \u7684\u957f\u5ea6&#xff0c;\u6362\u53e5\u8bdd\u8bf4&#xff0c;\u5c31\u662f\u751f\u6210\u7684 vectors \u5305\u542b\u591a\u5c11\u4e2a\u6570\u5b57&#xff08;dimensions&#xff09;\u3002<\/p>\n<p>\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981&#xff0c;\u56e0\u4e3a\u5b83\u4f1a\u76f4\u63a5\u5f71\u54cd\u6240\u9700\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/p>\n<p>\u5bf9\u4e8e all-MiniLM-L6-v2&#xff0c;\u751f\u6210\u7684 vectors \u5177\u6709 384 \u4e2a dimensions\u3002<\/p>\n<\/p>\n<h4>\u52a0\u8f7d Model<\/h4>\n<p>\u4e0b\u9762\u7684 Python \u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u52a0\u8f7d\u8be5 model\u3002\u4f60\u53ef\u4ee5\u5728 Python shell \u4e2d\u5c1d\u8bd5\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u3002<\/p>\n<p>from sentence_transformers import SentenceTransformer<br \/>\nmodel &#061; SentenceTransformer(&#039;all-MiniLM-L6-v2&#039;) <\/p>\n<p>\u7b2c\u4e00\u6b21\u6267\u884c\u6b64\u64cd\u4f5c\u65f6&#xff0c;\u6a21\u578b\u4f1a\u88ab\u4e0b\u8f7d\u5e76\u5b89\u88c5\u5230\u4f60\u7684\u865a\u62df\u73af\u5883\u4e2d&#xff0c;\u56e0\u6b64\u8c03\u7528\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u624d\u80fd\u8fd4\u56de\u3002\u4e00\u65e6\u6a21\u578b\u5b89\u88c5\u5b8c\u6210&#xff0c;\u5b9e\u4f8b\u5316\u5b83\u5e94\u8be5\u4e0d\u4f1a\u82b1\u8d39\u592a\u957f\u65f6\u95f4\u3002<\/p>\n<\/p>\n<h4>\u751f\u6210 Embeddings<\/h4>\n<p>\u6a21\u578b\u5b9e\u4f8b\u5316\u540e&#xff0c;\u4f60\u73b0\u5728\u5df2\u7ecf\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a embedding\u3002\u8981\u6267\u884c\u6b64\u64cd\u4f5c&#xff0c;\u5c06\u6e90\u6587\u672c\u4f20\u9012\u7ed9\u6a21\u578b.encode() \u65b9\u6cd5&#xff1a;<\/p>\n<p>embedding &#061; model.encode(&#039;The quick brown fox jumps over the lazy dog&#039;) <\/p>\n<p>\u7ed3\u679c\u662f\u4e00\u4e2a\u5305\u542b\u7ec4\u6210\u8be5 embedding \u7684\u6240\u6709\u6570\u5b57\u7684\u6570\u7ec4\u3002\u6b63\u5982\u4f60\u6240\u8bb0\u5f97\u7684&#xff0c;\u6240\u9009\u6a21\u578b\u751f\u6210\u7684 embeddings \u5177\u6709 384 \u4e2a\u7ef4\u5ea6&#xff0c;\u56e0\u6b64\u8fd9\u5c31\u662f embedding \u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<\/p>\n<h3>\u5728 Elasticsearch \u4e2d\u5b58\u50a8 Embeddings<\/h3>\n<p>Elasticsearch \u5b8c\u5168\u652f\u6301\u5b58\u50a8\u548c\u68c0\u7d22\u5411\u91cf&#xff0c;\u8fd9\u4f7f\u5176\u6210\u4e3a\u5904\u7406 embeddings \u7684\u7406\u60f3\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<h4>\u5b57\u6bb5\u7c7b\u578b<\/h4>\n<p>\u5728\u672c\u6559\u7a0b\u7684\u5168\u6587\u641c\u7d22\u7ae0\u8282\u4e2d&#xff0c;\u4f60\u5df2\u7ecf\u5b66\u4e60\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u6bb5\u7684\u7d22\u5f15\u3002\u5f53\u65f6\u63d0\u5230&#xff0c;Elasticsearch \u5927\u591a\u6570\u60c5\u51b5\u4e0b\u53ef\u4ee5\u6839\u636e\u6570\u636e\u672c\u8eab\u81ea\u52a8\u786e\u5b9a\u6bcf\u4e2a\u5b57\u6bb5\u6700\u9002\u5408\u4f7f\u7528\u7684\u7c7b\u578b\u3002\u5c3d\u7ba1 Elasticsearch 8.11 \u80fd\u591f\u81ea\u52a8\u6620\u5c04\u67d0\u4e9b\u5411\u91cf\u7c7b\u578b&#xff0c;\u4f46\u5728\u672c\u7ae0\u8282\u4e2d&#xff0c;\u4f60\u5c06\u663e\u5f0f\u5b9a\u4e49\u6b64\u7c7b\u578b&#xff0c;\u4ee5\u6b64\u4f5c\u4e3a\u5b66\u4e60 Elasticsearch \u4e2d\u7c7b\u578b\u6620\u5c04\u66f4\u591a\u77e5\u8bc6\u7684\u673a\u4f1a\u3002<\/p>\n<\/p>\n<h4>\u68c0\u7d22\u7c7b\u578b\u6620\u5c04<\/h4>\n<p>\u7d22\u5f15\u4e2d\u6bcf\u4e2a\u5b57\u6bb5\u5173\u8054\u7684\u7c7b\u578b\u662f\u901a\u8fc7\u4e00\u4e2a\u79f0\u4e3a\u6620\u5c04&#xff08;mapping&#xff09;\u7684\u8fc7\u7a0b\u786e\u5b9a\u7684&#xff0c;\u8be5\u8fc7\u7a0b\u53ef\u4ee5\u662f\u52a8\u6001\u7684&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u663e\u5f0f\u7684\u3002\u672c\u6559\u7a0b\u5168\u6587\u641c\u7d22\u90e8\u5206\u521b\u5efa\u7684\u6620\u5c04\u90fd\u662f\u7531 Elasticsearch \u52a8\u6001\u751f\u6210\u7684\u3002<\/p>\n<p>Elasticsearch \u5ba2\u6237\u7aef\u63d0\u4f9b\u4e86\u4e00\u4e2a get_mapping \u65b9\u6cd5&#xff0c;\u5b83\u4f1a\u8fd4\u56de\u67d0\u4e2a\u7ed9\u5b9a\u7d22\u5f15\u5f53\u524d\u751f\u6548\u7684\u7c7b\u578b\u6620\u5c04\u3002\u5982\u679c\u4f60\u60f3\u81ea\u884c\u63a2\u7d22\u8fd9\u4e9b\u6620\u5c04&#xff0c;\u8bf7\u542f\u52a8\u4e00\u4e2a Python shell&#xff0c;\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801&#xff1a;<\/p>\n<p>from app import es<br \/>\nes.es.indices.get_mapping(index&#061;&#039;my_documents&#039;) <\/p>\n<p>get_mapping() \u65b9\u6cd5\u8fd4\u56de\u7684\u54cd\u5e94\u662f\u4e00\u4e2a\u5b57\u5178&#xff0c;\u5176\u4e2d\u5305\u542b\u7d22\u5f15\u4e2d\u6bcf\u4e2a\u5b57\u6bb5\u7684\u4fe1\u606f\u3002\u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1&#xff0c;\u4e0b\u9762\u662f\u672c\u6559\u7a0b\u5168\u6587\u641c\u7d22\u90e8\u5206\u521b\u5efa\u7684 my_documents \u7d22\u5f15\u4e2d\u8fd9\u4e9b\u4fe1\u606f\u7684\u683c\u5f0f\u5316\u7ed3\u6784&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;my_documents&#034;: {<br \/>\n    &#034;mappings&#034;: {<br \/>\n      &#034;properties&#034;: {<br \/>\n        &#034;category&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;content&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;created_on&#034;: {<br \/>\n          &#034;type&#034;: &#034;date&#034;<br \/>\n        },<br \/>\n        &#034;name&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;rolePermissions&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;summary&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;updated_at&#034;: {<br \/>\n          &#034;type&#034;: &#034;date&#034;<br \/>\n        },<br \/>\n        &#034;url&#034;: {<br \/>\n          &#034;type&#034;: &#034;text&#034;,<br \/>\n          &#034;fields&#034;: {<br \/>\n            &#034;keyword&#034;: {<br \/>\n              &#034;type&#034;: &#034;keyword&#034;,<br \/>\n              &#034;ignore_above&#034;: 256<br \/>\n            }<br \/>\n          }<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u4ece\u8fd9\u91cc\u4f60\u53ef\u4ee5\u770b\u5230&#xff0c;created_on \u548c updated_at \u5b57\u6bb5\u88ab\u81ea\u52a8\u8bbe\u7f6e\u4e3a date \u7c7b\u578b&#xff0c;\u800c\u5176\u4ed6\u6240\u6709\u5b57\u6bb5\u90fd\u88ab\u8bbe\u7f6e\u4e3a text \u7c7b\u578b\u3002\u5728\u5c1d\u8bd5\u51b3\u5b9a\u7c7b\u578b\u65f6&#xff0c;Elasticsearch \u9996\u5148\u68c0\u67e5\u6570\u636e\u7684\u7c7b\u578b&#xff0c;\u8fd9\u6709\u52a9\u4e8e\u5b83\u4e3a\u5b57\u6bb5\u5206\u914d numeric\u3001boolean \u548c object \u7c7b\u578b\u3002\u5f53\u5b57\u6bb5\u6570\u636e\u662f\u5b57\u7b26\u4e32\u65f6&#xff0c;\u5b83\u8fd8\u4f1a\u5c1d\u8bd5\u67e5\u770b\u6570\u636e\u662f\u5426\u5339\u914d\u65e5\u671f\u6a21\u5f0f\u3002\u5982\u679c\u9700\u8981&#xff0c;\u4e5f\u53ef\u4ee5\u4e3a\u6570\u5b57\u542f\u7528\u57fa\u4e8e\u6a21\u5f0f\u7684\u5b57\u7b26\u4e32\u68c0\u6d4b\u3002<\/p>\n<p>text \u5b57\u6bb5\u5177\u6709\u4e00\u4e2a\u5e26\u6709 keyword \u6761\u76ee\u7684 fields \u5b9a\u4e49\u3002\u8fd9\u79f0\u4e3a\u5b50\u5b57\u6bb5&#xff0c;\u662f\u4e00\u79cd\u5728\u9002\u5f53\u60c5\u51b5\u4e0b\u53ef\u7528\u7684\u66ff\u4ee3\u7c7b\u578b\u6216\u8f85\u52a9\u7c7b\u578b\u3002\u5728 Elasticsearch \u4e2d&#xff0c;\u52a8\u6001\u7c7b\u578b\u7684 text \u5b57\u6bb5\u4f1a\u88ab\u8d4b\u4e88\u4e00\u4e2a keyword \u5b50\u5b57\u6bb5\u3002\u4f60\u5df2\u7ecf\u4f7f\u7528 category.keyword \u5b50\u5b57\u6bb5\u6765\u5bf9\u7ed9\u5b9a\u7c7b\u522b\u6267\u884c\u7cbe\u786e\u641c\u7d22\u3002\u4e3a\u4e86\u907f\u514d\u6dfb\u52a0\u5b50\u5b57\u6bb5&#xff0c;\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u663e\u5f0f\u7684 text \u6216 keyword \u6620\u5c04&#xff0c;\u7136\u540e\u8be5\u7c7b\u578b\u5c06\u6210\u4e3a\u4e3b\u8981\u4e14\u552f\u4e00\u7684\u7c7b\u578b\u3002<\/p>\n<\/p>\n<h4 style=\"background-color:transparent\">\u5411\u7d22\u5f15\u6dfb\u52a0\u5411\u91cf\u5b57\u6bb5<\/h4>\n<p>\u8ba9\u6211\u4eec\u5411\u7d22\u5f15\u6dfb\u52a0\u4e00\u4e2a\u65b0\u5b57\u6bb5&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6bcf\u4e2a\u6587\u6863\u7684 embedding\u3002<\/p>\n<p>\u663e\u5f0f\u6620\u5c04\u7684\u7ed3\u6784\u4e0e Elasticsearch \u5ba2\u6237\u7aef\u7684 get_mapping() \u65b9\u6cd5\u8fd4\u56de\u7684\u54cd\u5e94\u4e2d\u7684 mappings \u952e\u76f8\u5339\u914d\u3002\u53ea\u9700\u8981\u63d0\u4f9b\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u7c7b\u578b\u7684\u5b57\u6bb5&#xff0c;\u56e0\u4e3a\u6620\u5c04\u4e2d\u672a\u5305\u542b\u7684\u4efb\u4f55\u5b57\u6bb5\u4ecd\u4f1a\u50cf\u4e4b\u524d\u4e00\u6837\u88ab\u52a8\u6001\u8bbe\u7f6e\u7c7b\u578b\u3002<\/p>\n<p>\u4e0b\u9762\u4f60\u53ef\u4ee5\u770b\u5230 Search \u7c7b\u4e2d create_index() \u65b9\u6cd5\u7684\u65b0\u7248\u672c&#xff0c;\u5b83\u6dfb\u52a0\u4e86\u4e00\u4e2a\u540d\u4e3a embedding \u7684\u663e\u5f0f\u7c7b\u578b\u5b57\u6bb5\u3002\u5728 search.py \u4e2d\u66ff\u6362\u6b64\u65b9\u6cd5&#xff1a;<\/p>\n<p>class Search:<br \/>\n    # &#8230;<\/p>\n<p>    def create_index(self):<br \/>\n        self.es.indices.delete(index&#061;&#039;my_documents&#039;, ignore_unavailable&#061;True)<br \/>\n        self.es.indices.create(index&#061;&#039;my_documents&#039;, mappings&#061;{<br \/>\n            &#039;properties&#039;: {<br \/>\n                &#039;embedding&#039;: {<br \/>\n                    &#039;type&#039;: &#039;dense_vector&#039;,<br \/>\n                }<br \/>\n            }<br \/>\n        }) <\/p>\n<p>\u6b63\u5982\u4f60\u6240\u770b\u5230\u7684&#xff0c;embedding \u5b57\u6bb5\u88ab\u8d4b\u4e88\u4e86 dense_vector \u7c7b\u578b&#xff0c;\u8fd9\u662f\u5b58\u50a8 embeddings \u65f6\u5408\u9002\u7684\u7c7b\u578b\u3002\u7a0d\u540e\u4f60\u5c06\u5b66\u4e60\u53e6\u4e00\u79cd\u5411\u91cf\u7c7b\u578b sparse_vector&#xff0c;\u5b83\u5728\u5176\u4ed6\u7c7b\u578b\u7684\u8bed\u4e49\u641c\u7d22\u5e94\u7528\u4e2d\u5f88\u6709\u7528\u3002<\/p>\n<p>dense_vector \u7c7b\u578b\u63a5\u53d7\u51e0\u4e2a\u53c2\u6570&#xff0c;\u6240\u6709\u53c2\u6570\u90fd\u662f\u53ef\u9009\u7684\u3002<\/p>\n<ul>\n<li>dims&#xff1a;\u5c06\u8981\u5b58\u50a8\u7684\u5411\u91cf\u7684\u5927\u5c0f\u3002\u4ece 8.11 \u7248\u672c\u5f00\u59cb&#xff0c;\u5f53\u7b2c\u4e00\u4e2a\u6587\u6863\u88ab\u63d2\u5165\u65f6&#xff0c;\u7ef4\u5ea6\u4f1a\u88ab\u81ea\u52a8\u5206\u914d\u3002<\/li>\n<li>index&#xff1a;\u5fc5\u987b\u8bbe\u7f6e\u4e3a True&#xff0c;\u4ee5\u8868\u793a\u8fd9\u4e9b\u5411\u91cf\u5e94\u8be5\u88ab\u7d22\u5f15\u7528\u4e8e\u641c\u7d22\u3002\u8fd9\u662f\u9ed8\u8ba4\u503c\u3002<\/li>\n<li>similarity&#xff1a;\u6bd4\u8f83\u5411\u91cf\u65f6\u4f7f\u7528\u7684\u8ddd\u79bb\u51fd\u6570\u3002\u6700\u5e38\u89c1\u7684\u4e24\u4e2a\u662f dot_product \u548c cosine\u3002\u70b9\u79ef\u6548\u7387\u66f4\u9ad8&#xff0c;\u4f46\u5b83\u8981\u6c42\u5411\u91cf\u5df2\u7ecf\u5f52\u4e00\u5316\u3002\u9ed8\u8ba4\u503c\u662f cosine\u3002<\/li>\n<\/ul>\n<h4>\u5411\u6587\u6863\u6dfb\u52a0 Embeddings<\/h4>\n<p>\u5728\u4e0a\u4e00\u8282\u4e2d&#xff0c;\u4f60\u5df2\u7ecf\u5b66\u4e60\u4e86\u5982\u4f55\u4f7f\u7528 SentenceTransformers \u6846\u67b6\u548c all-MiniLM-L6-v2 \u6a21\u578b\u751f\u6210 embeddings\u3002\u73b0\u5728\u662f\u65f6\u5019\u5c06\u8be5\u6a21\u578b\u96c6\u6210\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4e86\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u53ef\u4ee5\u5728 Search \u7c7b\u7684\u6784\u9020\u51fd\u6570\u4e2d\u5b9e\u4f8b\u5316\u8be5\u6a21\u578b&#xff1a;<\/p>\n<p># &#8230;<br \/>\nfrom sentence_transformers import SentenceTransformer<\/p>\n<p># &#8230;<\/p>\n<p>class Search:<br \/>\n    def __init__(self):<br \/>\n        self.model &#061; SentenceTransformer(&#039;all-MiniLM-L6-v2&#039;)<br \/>\n        self.es &#061; Elasticsearch(cloud_id&#061;os.environ[&#039;ELASTIC_CLOUD_ID&#039;],<br \/>\n                                api_key&#061;os.environ[&#039;ELASTIC_API_KEY&#039;])<br \/>\n        client_info &#061; self.es.info()<br \/>\n        print(&#039;Connected to Elasticsearch!&#039;)<br \/>\n        pprint(client_info.body)<\/p>\n<p>    # &#8230; <\/p>\n<p>\u6b63\u5982\u4f60\u5728\u672c\u6559\u7a0b\u7684\u5168\u6587\u641c\u7d22\u90e8\u5206\u4e2d\u8bb0\u5f97\u7684\u90a3\u6837&#xff0c;Search \u7c7b\u5177\u6709 insert_document() \u548c insert_documents() \u65b9\u6cd5&#xff0c;\u5206\u522b\u7528\u4e8e\u5411\u7d22\u5f15\u4e2d\u63d2\u5165\u5355\u4e2a\u6587\u6863\u548c\u591a\u4e2a\u6587\u6863\u3002\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u73b0\u5728\u9700\u8981\u751f\u6210\u4e0e\u6bcf\u4e2a\u6587\u6863\u5bf9\u5e94\u7684 embeddings\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5757\u5c55\u793a\u4e86\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u7684\u65b0\u7248\u672c&#xff0c;\u4ee5\u53ca\u4e00\u4e2a\u65b0\u7684 get_embedding() \u8f85\u52a9\u65b9\u6cd5&#xff0c;\u8be5\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a embedding\u3002<\/p>\n<p>class Search:<br \/>\n    # &#8230;<\/p>\n<p>    def get_embedding(self, text):<br \/>\n        return self.model.encode(text)<\/p>\n<p>    def insert_document(self, document):<br \/>\n        return self.es.index(index&#061;&#039;my_documents&#039;, document&#061;{<br \/>\n            **document,<br \/>\n            &#039;embedding&#039;: self.get_embedding(document[&#039;summary&#039;]),<br \/>\n        })<\/p>\n<p>    def insert_documents(self, documents):<br \/>\n        operations &#061; []<br \/>\n        for document in documents:<br \/>\n            operations.append({&#039;index&#039;: {&#039;_index&#039;: &#039;my_documents&#039;}})<br \/>\n            operations.append({<br \/>\n                **document,<br \/>\n                &#039;embedding&#039;: self.get_embedding(document[&#039;summary&#039;]),<br \/>\n            })<br \/>\n        return self.es.bulk(operations&#061;operations) <\/p>\n<p>\u4fee\u6539\u540e\u7684\u65b9\u6cd5\u5411\u8981\u63d2\u5165\u7684\u6587\u6863\u6dfb\u52a0\u4e86\u65b0\u7684 embedding \u5b57\u6bb5\u3002\u8be5 embedding \u662f\u6839\u636e\u6bcf\u4e2a\u6587\u6863\u7684 summary \u5b57\u6bb5\u751f\u6210\u7684\u3002\u901a\u5e38\u60c5\u51b5\u4e0b&#xff0c;embeddings \u662f\u4ece\u53e5\u5b50\u6216\u77ed\u6bb5\u843d\u4e2d\u751f\u6210\u7684&#xff0c;\u56e0\u6b64\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;summary \u662f\u4e00\u4e2a\u7406\u60f3\u7684\u4f7f\u7528\u5b57\u6bb5\u3002\u5176\u4ed6\u53ef\u9009\u9879\u5305\u62ec name \u5b57\u6bb5&#xff0c;\u5b83\u5305\u542b\u6587\u6863\u7684\u6807\u9898&#xff0c;\u6216\u8005\u6587\u6863\u6b63\u6587\u4e2d\u7684\u524d\u51e0\u53e5\u8bdd\u3002<\/p>\n<p>\u5b8c\u6210\u8fd9\u4e9b\u66f4\u6539\u540e&#xff0c;\u53ef\u4ee5\u91cd\u65b0\u6784\u5efa\u7d22\u5f15&#xff0c;\u4f7f\u5176\u4e3a\u6bcf\u4e2a\u6587\u6863\u5b58\u50a8\u4e00\u4e2a embedding\u3002\u8981\u91cd\u65b0\u6784\u5efa\u7d22\u5f15&#xff0c;\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p>flask run <\/p>\n<p>\u5f53\u6211\u4eec\u91cd\u65b0\u8fd0\u884c\u4e0a\u9762\u7684\u547d\u4ee4\u540e&#xff0c;\u8fd9\u6b21 flask \u7684\u542f\u52a8\u6bd4\u8f83\u6162\u3002\u8fd9\u662f\u56e0\u4e3a\u5b83\u9700\u8981\u4e0b\u8f7d\u6a21\u578b all-MiniLM-L6-v2\u3002<\/p>\n<p>flask reindex<br \/>\n(.venv) $ flask reindex<br \/>\nWarning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.<br \/>\nLoading weights: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 103\/103 [00:00&lt;00:00, 30637.07it\/s]<br \/>\nConnected to Elasticsearch!<br \/>\n{&#039;cluster_name&#039;: &#039;elasticsearch&#039;,<br \/>\n &#039;cluster_uuid&#039;: &#039;G5xn8TT3StGeUFd9WJMy5A&#039;,<br \/>\n &#039;name&#039;: &#039;liuxgn.local&#039;,<br \/>\n &#039;tagline&#039;: &#039;You Know, for Search&#039;,<br \/>\n &#039;version&#039;: {&#039;build_date&#039;: &#039;2026-04-30T15:05:34.751113474Z&#039;,<br \/>\n             &#039;build_flavor&#039;: &#039;default&#039;,<br \/>\n             &#039;build_hash&#039;: &#039;2e8528e92361c3399724226deaf2b46f933e925b&#039;,<br \/>\n             &#039;build_snapshot&#039;: False,<br \/>\n             &#039;build_type&#039;: &#039;tar&#039;,<br \/>\n             &#039;lucene_version&#039;: &#039;10.4.0&#039;,<br \/>\n             &#039;minimum_index_compatibility_version&#039;: &#039;8.0.0&#039;,<br \/>\n             &#039;minimum_wire_compatibility_version&#039;: &#039;8.19.0&#039;,<br \/>\n             &#039;number&#039;: &#039;9.4.0&#039;}}<br \/>\nreindexing &#8230;<br \/>\nCreating the index &#8230;<br \/>\nIndex with 15 documents created in 205 milliseconds. <\/p>\n<p>\u5982\u679c\u4f60\u6709 Kibana \u5728\u8fd0\u884c&#xff0c;\u90a3\u4e48\u4f60\u53ef\u4ee5\u68c0\u67e5\u6700\u65b0\u7684 mapping&#xff1a;<\/p>\n<p>GET my_documents\/_mapping <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1534\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802010102-6a6e96ce32f69.png\" width=\"2426\" \/><\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u63d0\u9192\u4e00\u4e0b&#xff0c;flask reindex \u547d\u4ee4\u662f\u5728 app.py \u6587\u4ef6\u4e2d\u7684 reindex() \u51fd\u6570\u91cc\u5b9e\u73b0\u7684\u3002\u5b83\u8c03\u7528 Search \u7c7b\u7684 reindex() \u65b9\u6cd5&#xff0c;\u800c\u8be5\u65b9\u6cd5\u4f9d\u6b21\u8c03\u7528 create_index()&#xff0c;\u7136\u540e\u5c06 data.json \u6587\u4ef6\u4e2d\u7684\u6240\u6709\u6570\u636e\u4f20\u9012\u7ed9 insert_documents()\u3002<\/p>\n<\/p>\n<h3>k \u8fd1\u90bb&#xff08;kNN&#xff09;\u641c\u7d22<\/h3>\n<p>k \u8fd1\u90bb&#xff08;kNN&#xff09;\u7b97\u6cd5\u4f1a\u5bf9 dense_vector \u7c7b\u578b\u7684\u5b57\u6bb5\u6267\u884c\u76f8\u4f3c\u5ea6\u641c\u7d22\u3002\u8fd9\u79cd\u641c\u7d22\u66f4\u51c6\u786e\u5730\u79f0\u4e3a\u201c\u8fd1\u4f3c kNN\u201d&#xff0c;\u5b83\u63a5\u53d7\u4e00\u4e2a\u5411\u91cf\u6216 embedding \u4f5c\u4e3a\u641c\u7d22\u8bcd&#xff0c;\u5e76\u5728\u7d22\u5f15\u4e2d\u67e5\u627e\u63a5\u8fd1\u8be5\u5411\u91cf\u7684\u6761\u76ee\u3002<\/p>\n<p>\u5728\u672c\u8282\u4e2d&#xff0c;\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u4e0a\u4e00\u8282\u4e2d\u521b\u5efa\u7684\u6587\u6863 embeddings \u6267\u884c kNN \u641c\u7d22\u3002<\/p>\n<\/p>\n<h4>knn \u67e5\u8be2<\/h4>\n<p>\u5728\u672c\u6559\u7a0b\u7684\u5168\u6587\u641c\u7d22\u90e8\u5206\u4e2d&#xff0c;\u4f60\u5df2\u7ecf\u5b66\u4e60\u4e86\u4f20\u9012\u7ed9 Elasticsearch \u5ba2\u6237\u7aef search() \u65b9\u6cd5\u7684 query \u9009\u9879\u3002\u5728\u641c\u7d22\u5411\u91cf\u65f6&#xff0c;\u5219\u4f7f\u7528 knn \u9009\u9879\u3002<\/p>\n<p>\u4e0b\u9762\u4f60\u53ef\u4ee5\u770b\u5230 app.py \u4e2d handle_search() \u51fd\u6570\u7684\u65b0\u7248\u672c&#xff0c;\u8be5\u51fd\u6570\u4f1a\u9488\u5bf9\u7528\u6237\u5728\u641c\u7d22\u8868\u5355\u4e2d\u8f93\u5165\u7684\u67e5\u8be2\u8fd0\u884c kNN \u641c\u7d22\u3002<\/p>\n<p>&#064;app.post(&#039;\/&#039;)<br \/>\ndef handle_search():<br \/>\n    query &#061; request.form.get(&#039;query&#039;, &#039;&#039;)<br \/>\n    filters, parsed_query &#061; extract_filters(query)<br \/>\n    from_ &#061; request.form.get(&#039;from_&#039;, type&#061;int, default&#061;0)<\/p>\n<p>    results &#061; es.search(<br \/>\n        knn&#061;{<br \/>\n            &#039;field&#039;: &#039;embedding&#039;,<br \/>\n            &#039;query_vector&#039;: es.get_embedding(parsed_query),<br \/>\n            &#039;num_candidates&#039;: 50,<br \/>\n            &#039;k&#039;: 10,<br \/>\n        },<br \/>\n        size&#061;5,<br \/>\n        from_&#061;from_<br \/>\n    )<br \/>\n    return render_template(&#039;index.html&#039;, results&#061;results[&#039;hits&#039;][&#039;hits&#039;],<br \/>\n                           query&#061;query, from_&#061;from_,<br \/>\n                           total&#061;results[&#039;hits&#039;][&#039;total&#039;][&#039;value&#039;]) <\/p>\n<p>\u5728\u8fd9\u4e2a\u7248\u672c\u7684\u51fd\u6570\u4e2d&#xff0c;query \u9009\u9879\u88ab\u66ff\u6362\u4e3a knn\u3002\u7528\u4e8e\u5206\u9875\u7684 size \u548c from_ \u9009\u9879\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u51fd\u6570\u4e2d\u7684\u5176\u4ed6\u6240\u6709\u5185\u5bb9\u4ee5\u53ca index.html \u6a21\u677f\u4e5f\u4e0e\u4e4b\u524d\u76f8\u540c\u3002<\/p>\n<p>knn \u641c\u7d22\u9009\u9879\u63a5\u53d7\u591a\u4e2a\u7528\u4e8e\u914d\u7f6e\u641c\u7d22\u7684\u53c2\u6570&#xff1a;<\/p>\n<ul>\n<li>field&#xff1a;\u8981\u641c\u7d22\u7684\u7d22\u5f15\u5b57\u6bb5\u3002\u8be5\u5b57\u6bb5\u5fc5\u987b\u5177\u6709 dense_vector \u7c7b\u578b\u3002<\/li>\n<li>query_vector&#xff1a;\u7528\u4e8e\u641c\u7d22\u7684 embedding\u3002\u5b83\u5e94\u8be5\u662f\u6839\u636e\u641c\u7d22\u6587\u672c\u751f\u6210\u7684 embedding\u3002<\/li>\n<li>num_candidates&#xff1a;\u4ece\u6bcf\u4e2a\u5206\u7247\u4e2d\u8003\u8651\u7684\u5019\u9009\u6587\u6863\u6570\u91cf\u3002Elasticsearch \u4f1a\u4ece\u6bcf\u4e2a\u5206\u7247\u4e2d\u68c0\u7d22\u8fd9\u4e48\u591a\u5019\u9009\u9879&#xff0c;\u5c06\u5b83\u4eec\u5408\u5e76\u6210\u4e00\u4e2a\u5217\u8868&#xff0c;\u7136\u540e\u627e\u5230\u6700\u63a5\u8fd1\u7684 \u201ck\u201d \u4e2a\u7ed3\u679c\u4f5c\u4e3a\u8fd4\u56de\u7ed3\u679c\u3002<\/li>\n<li>k&#xff1a;\u8981\u8fd4\u56de\u7684\u7ed3\u679c\u6570\u91cf\u3002\u8fd9\u4e2a\u6570\u5b57\u4f1a\u76f4\u63a5\u5f71\u54cd\u6027\u80fd&#xff0c;\u56e0\u6b64\u5e94\u8be5\u5c3d\u53ef\u80fd\u4fdd\u6301\u8f83\u5c0f\u3002\u6b64\u9009\u9879\u4f20\u5165\u7684\u503c\u5fc5\u987b\u5c0f\u4e8e num_candidates\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7684\u8bbe\u7f6e&#xff0c;\u5c06\u8fd4\u56de 10 \u4e2a\u6700\u4f73\u5339\u914d\u7ed3\u679c\u3002<\/p>\n<p>\u6b22\u8fce\u4f60\u5c1d\u8bd5\u8fd9\u4e2a\u65b0\u7248\u672c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e24\u4e2a\u5f88\u597d\u7684\u793a\u4f8b&#xff0c;\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7406\u89e3\u8fd9\u79cd\u641c\u7d22\u7c7b\u578b\u7684\u5b9e\u7528\u6027&#xff1a;<\/p>\n<ul>\n<li>\u641c\u7d22 \u201choliday\u201d&#xff0c;\u8fd9\u662f\u82f1\u5f0f\u82f1\u8bed\u4e2d\u4e0e\u7f8e\u5f0f\u82f1\u8bed\u4e2d\u7684 \u201cvacation\u201d \u5bf9\u5e94\u7684\u8bcd&#xff0c;kNN \u641c\u7d22\u4f1a\u5c06 \u201cVacation Policy\u201d \u6587\u6863\u4f5c\u4e3a\u6700\u9ad8\u6392\u540d\u7ed3\u679c&#xff0c;\u5373\u4f7f\u6587\u6863\u4e2d\u6ca1\u6709\u51fa\u73b0 holiday \u8fd9\u4e2a\u8bcd\u3002<\/li>\n<li>\u641c\u7d22 \u201ccats and dogs\u201d \u6216\u4efb\u4f55\u5176\u4ed6\u4e0e\u5ba0\u7269\u76f8\u5173\u7684\u672f\u8bed&#xff0c;\u4f1a\u5c06 \u201cOffice Pet Policy\u201d \u6587\u6863\u4f5c\u4e3a\u6700\u9ad8\u6392\u540d\u7ed3\u679c&#xff0c;\u5373\u4f7f\u8be5\u6587\u6863\u7684\u6458\u8981\u4e2d\u6ca1\u6709\u63d0\u5230\u4efb\u4f55\u5177\u4f53\u5ba0\u7269\u3002<\/li>\n<\/ul>\n<h4>\u5728 kNN \u67e5\u8be2\u4e2d\u4f7f\u7528\u8fc7\u6ee4\u5668<\/h4>\n<p>\u6b63\u5982\u672c\u6559\u7a0b\u5168\u6587\u641c\u7d22\u90e8\u5206\u4e2d\u5b9a\u4e49\u7684\u90a3\u6837&#xff0c;\u641c\u7d22\u67e5\u8be2\u5141\u8bb8\u7528\u6237\u4f7f\u7528 category: \u8bed\u6cd5\u5728\u641c\u7d22\u6587\u672c\u7684\u4efb\u610f\u4f4d\u7f6e\u8bf7\u6c42\u4f7f\u7528\u7279\u5b9a\u7c7b\u522b\u3002app.py \u4e2d\u7684 extract_filters() \u51fd\u6570\u8d1f\u8d23\u67e5\u627e\u5e76\u4ece\u641c\u7d22\u67e5\u8be2\u4e2d\u5206\u79bb\u8fd9\u4e9b\u8fc7\u6ee4\u8868\u8fbe\u5f0f\u3002\u5728\u4e0a\u4e00\u8282\u4e2d\u7684 handle_search() \u51fd\u6570\u7248\u672c\u91cc&#xff0c;filters \u53d8\u91cf\u6ca1\u6709\u88ab\u4f7f\u7528&#xff0c;\u56e0\u6b64 category \u8fc7\u6ee4\u5668\u4f1a\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u5e78\u8fd0\u7684\u662f&#xff0c;knn \u9009\u9879\u4e5f\u652f\u6301\u8fc7\u6ee4\u529f\u80fd\u3002filter \u9009\u9879\u5b9e\u9645\u4e0a\u63a5\u53d7\u76f8\u540c\u7c7b\u578b\u7684\u8fc7\u6ee4\u5668&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u5c06\u8fc7\u6ee4\u5668\u76f4\u63a5\u63d2\u5165 knn \u67e5\u8be2\u4e2d&#xff0c;\u5b8c\u5168\u6309\u7167 extract_filters() \u51fd\u6570\u8fd4\u56de\u7684\u5f62\u5f0f\u4f7f\u7528&#xff1a;<\/p>\n<p>&#064;app.post(&#039;\/&#039;)<br \/>\ndef handle_search():<br \/>\n    query &#061; request.form.get(&#039;query&#039;, &#039;&#039;)<br \/>\n    filters, parsed_query &#061; extract_filters(query)<br \/>\n    from_ &#061; request.form.get(&#039;from_&#039;, type&#061;int, default&#061;0)<\/p>\n<p>    results &#061; es.search(<br \/>\n        knn&#061;{<br \/>\n            &#039;field&#039;: &#039;embedding&#039;,<br \/>\n            &#039;query_vector&#039;: es.get_embedding(parsed_query),<br \/>\n            &#039;k&#039;: 10,<br \/>\n            &#039;num_candidates&#039;: 50,<br \/>\n            **filters,<br \/>\n        },<br \/>\n        size&#061;5,<br \/>\n        from_&#061;from_<br \/>\n    )<br \/>\n    return render_template(&#039;index.html&#039;, results&#061;results[&#039;hits&#039;][&#039;hits&#039;],<br \/>\n                           query&#061;query, from_&#061;from_,<br \/>\n                           total&#061;results[&#039;hits&#039;][&#039;total&#039;][&#039;value&#039;]) <\/p>\n<p>\u805a\u5408\u4e5f\u53ef\u4ee5\u5f88\u597d\u5730\u7528\u4e8e kNN \u67e5\u8be2&#xff0c;\u56e0\u6b64\u4e5f\u53ef\u4ee5\u5c06\u5b83\u4eec\u91cd\u65b0\u6dfb\u52a0\u56de\u6765&#xff1a;<\/p>\n<p>&#064;app.post(&#039;\/&#039;)<br \/>\ndef handle_search():<br \/>\n    query &#061; request.form.get(&#039;query&#039;, &#039;&#039;)<br \/>\n    filters, parsed_query &#061; extract_filters(query)<br \/>\n    from_ &#061; request.form.get(&#039;from_&#039;, type&#061;int, default&#061;0)<\/p>\n<p>    results &#061; es.search(<br \/>\n        knn&#061;{<br \/>\n            &#039;field&#039;: &#039;embedding&#039;,<br \/>\n            &#039;query_vector&#039;: es.get_embedding(parsed_query),<br \/>\n            &#039;k&#039;: 10,<br \/>\n            &#039;num_candidates&#039;: 50,<br \/>\n            **filters,<br \/>\n        },<br \/>\n        aggs&#061;{<br \/>\n            &#039;category-agg&#039;: {<br \/>\n                &#039;terms&#039;: {<br \/>\n                    &#039;field&#039;: &#039;category.keyword&#039;,<br \/>\n                }<br \/>\n            },<br \/>\n            &#039;year-agg&#039;: {<br \/>\n                &#039;date_histogram&#039;: {<br \/>\n                    &#039;field&#039;: &#039;updated_at&#039;,<br \/>\n                    &#039;calendar_interval&#039;: &#039;year&#039;,<br \/>\n                    &#039;format&#039;: &#039;yyyy&#039;,<br \/>\n                },<br \/>\n            },<br \/>\n        },<br \/>\n        size&#061;5,<br \/>\n        from_&#061;from_<br \/>\n    )<br \/>\n    aggs &#061; {<br \/>\n        &#039;Category&#039;: {<br \/>\n            bucket[&#039;key&#039;]: bucket[&#039;doc_count&#039;]<br \/>\n            for bucket in results[&#039;aggregations&#039;][&#039;category-agg&#039;][&#039;buckets&#039;]<br \/>\n        },<br \/>\n        &#039;Year&#039;: {<br \/>\n            bucket[&#039;key_as_string&#039;]: bucket[&#039;doc_count&#039;]<br \/>\n            for bucket in results[&#039;aggregations&#039;][&#039;year-agg&#039;][&#039;buckets&#039;]<br \/>\n            if bucket[&#039;doc_count&#039;] &gt; 0<br \/>\n        },<br \/>\n    }<br \/>\n    return render_template(&#039;index.html&#039;, results&#061;results[&#039;hits&#039;][&#039;hits&#039;],<br \/>\n                           query&#061;query, from_&#061;from_,<br \/>\n                           total&#061;results[&#039;hits&#039;][&#039;total&#039;][&#039;value&#039;], aggs&#061;aggs) <\/p>\n<p>\u8fd9\u4e2a\u7248\u672c\u7684 handle_search() \u51fd\u6570\u5177\u6709\u4e0e\u5168\u6587\u641c\u7d22\u7248\u672c\u76f8\u540c\u7684\u529f\u80fd&#xff0c;\u53ea\u4e0d\u8fc7\u4f7f\u7528\u5411\u91cf\u641c\u7d22\u4ee3\u66ff\u4e86\u57fa\u4e8e\u5173\u952e\u8bcd\u7684\u641c\u7d22\u3002<\/p>\n<p>\u5728\u4e0b\u4e00\u8282\u4e2d&#xff0c;\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u7ed3\u5408\u8fd9\u4e24\u79cd\u4e0d\u540c\u641c\u7d22\u65b9\u6cd5\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<h3>\u6df7\u5408\u641c\u7d22&#xff1a;\u7ed3\u5408\u5168\u6587\u641c\u7d22\u548c kNN \u7ed3\u679c<\/h3>\n<p>\u73b0\u5728\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86\u4e24\u79cd\u4e0d\u540c\u7684\u6587\u6863\u96c6\u5408\u641c\u7d22\u65b9\u6cd5&#xff0c;\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u3002\u5982\u679c\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u7b26\u5408\u4f60\u7684\u9700\u6c42&#xff0c;\u90a3\u4e48\u4f60\u4e0d\u9700\u8981\u5176\u4ed6\u65b9\u6cd5&#xff0c;\u4f46\u5728\u5f88\u591a\u60c5\u51b5\u4e0b&#xff0c;\u6bcf\u79cd\u641c\u7d22\u65b9\u6cd5\u90fd\u4f1a\u8fd4\u56de\u53e6\u4e00\u79cd\u65b9\u6cd5\u53ef\u80fd\u9057\u6f0f\u7684\u6709\u4ef7\u503c\u7ed3\u679c&#xff0c;\u56e0\u6b64\u6700\u4f73\u9009\u62e9\u662f\u63d0\u4f9b\u4e00\u4e2a\u7ec4\u5408\u540e\u7684\u7ed3\u679c\u96c6\u3002<\/p>\n<p>\u9488\u5bf9\u8fd9\u4e9b\u60c5\u51b5&#xff0c;Elasticsearch \u63d0\u4f9b\u4e86 Reciprocal Rank Fusion&#xff0c;\u8fd9\u662f\u4e00\u79cd\u5c06\u4e24\u4e2a\u6216\u591a\u4e2a\u5217\u8868\u4e2d\u7684\u7ed3\u679c\u5408\u5e76\u4e3a\u4e00\u4e2a\u5217\u8868\u7684\u7b97\u6cd5\u3002<\/p>\n<\/p>\n<h4>RRF \u7684\u5de5\u4f5c\u539f\u7406<\/h4>\n<p>Elasticsearch \u5c06 RRF \u7b97\u6cd5\u96c6\u6210\u5230\u4e86\u641c\u7d22\u67e5\u8be2\u4e2d\u3002\u8bf7\u8003\u8651\u4e0b\u9762\u7684\u793a\u4f8b&#xff0c;\u5176\u4e2d\u5305\u542b query \u548c knn \u90e8\u5206&#xff0c;\u5206\u522b\u7528\u4e8e\u8bf7\u6c42\u5168\u6587\u641c\u7d22\u548c\u5411\u91cf\u641c\u7d22&#xff0c;\u4ee5\u53ca\u4e00\u4e2a rrf \u90e8\u5206&#xff0c;\u7528\u4e8e\u5c06\u5b83\u4eec\u5408\u5e76\u4e3a\u4e00\u4e2a\u7ed3\u679c\u5217\u8868\u3002<\/p>\n<p>self.es.search(<br \/>\n    query&#061;{<br \/>\n        # full-text search query here<br \/>\n    },<br \/>\n    knn&#061;{<br \/>\n        # vector search query here<br \/>\n    },<br \/>\n    rank&#061;{<br \/>\n        &#034;rrf&#034;: {}<br \/>\n    }<br \/>\n) <\/p>\n<p>\u867d\u7136 RRF \u5728\u4e0d\u8fdb\u884c\u4efb\u4f55\u914d\u7f6e\u7684\u60c5\u51b5\u4e0b\u5bf9\u8f83\u77ed\u7684\u7ed3\u679c\u5217\u8868\u6548\u679c\u76f8\u5f53\u597d&#xff0c;\u4f46\u6709\u4e00\u4e9b\u53c2\u6570\u53ef\u4ee5\u8c03\u6574&#xff0c;\u4ee5\u63d0\u4f9b\u6700\u4f73\u7ed3\u679c\u3002\u8bf7\u67e5\u9605\u6587\u6863\u4ee5\u8be6\u7ec6\u4e86\u89e3\u8fd9\u4e9b\u53c2\u6570\u3002<\/p>\n<\/p>\n<h4>RRF \u5b9e\u73b0<\/h4>\n<p>\u8981\u542f\u7528\u4e00\u4e2a\u540c\u65f6\u8fd4\u56de\u5168\u6587\u641c\u7d22\u548c\u5411\u91cf\u641c\u7d22\u65b9\u6cd5\u7ed3\u679c\u7684\u7ec4\u5408\u641c\u7d22&#xff0c;\u9700\u8981\u6062\u590d\u4e4b\u524d\u5728 handle_search() \u51fd\u6570\u4e2d\u4f7f\u7528\u7684\u5168\u6587\u641c\u7d22\u903b\u8f91\u3002\u4e3a\u4e86\u5b9e\u73b0\u6df7\u5408\u641c\u7d22\u7b56\u7565&#xff0c;search() \u65b9\u6cd5\u5fc5\u987b\u540c\u65f6\u63a5\u6536 query \u548c knn \u53c2\u6570&#xff0c;\u6bcf\u4e2a\u53c2\u6570\u5206\u522b\u8bf7\u6c42\u4e00\u4e2a\u72ec\u7acb\u7684\u67e5\u8be2\u3002\u8fd8\u9700\u8981\u6dfb\u52a0\u4e0a\u9762\u6240\u793a\u7684 rank \u90e8\u5206&#xff0c;\u4ee5\u5c06\u7ed3\u679c\u5408\u5e76\u4e3a\u4e00\u4e2a\u6392\u5e8f\u5217\u8868\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u5b9e\u73b0\u6df7\u5408\u641c\u7d22\u7b56\u7565\u7684 handle_search() \u51fd\u6570\u7248\u672c&#xff1a;<\/p>\n<p>&#064;app.post(&#039;\/&#039;)<br \/>\ndef handle_search():<br \/>\n    query &#061; request.form.get(&#039;query&#039;, &#039;&#039;)<br \/>\n    filters, parsed_query &#061; extract_filters(query)<br \/>\n    from_ &#061; request.form.get(&#039;from_&#039;, type&#061;int, default&#061;0)<\/p>\n<p>    if parsed_query:<br \/>\n        search_query &#061; {<br \/>\n            &#039;must&#039;: {<br \/>\n                &#039;multi_match&#039;: {<br \/>\n                    &#039;query&#039;: parsed_query,<br \/>\n                    &#039;fields&#039;: [&#039;name&#039;, &#039;summary&#039;, &#039;content&#039;],<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    else:<br \/>\n        search_query &#061; {<br \/>\n            &#039;must&#039;: {<br \/>\n                &#039;match_all&#039;: {}<br \/>\n            }<br \/>\n        }<\/p>\n<p>    results &#061; es.search(<br \/>\n        query&#061;{<br \/>\n            &#039;bool&#039;: {<br \/>\n                **search_query,<br \/>\n                **filters<br \/>\n            }<br \/>\n        },<br \/>\n        knn&#061;{<br \/>\n            &#039;field&#039;: &#039;embedding&#039;,<br \/>\n            &#039;query_vector&#039;: es.get_embedding(parsed_query),<br \/>\n            &#039;k&#039;: 10,<br \/>\n            &#039;num_candidates&#039;: 50,<br \/>\n            **filters,<br \/>\n        },<br \/>\n        rank&#061;{<br \/>\n            &#039;rrf&#039;: {}<br \/>\n        },<br \/>\n        aggs&#061;{<br \/>\n            &#039;category-agg&#039;: {<br \/>\n                &#039;terms&#039;: {<br \/>\n                    &#039;field&#039;: &#039;category.keyword&#039;,<br \/>\n                }<br \/>\n            },<br \/>\n            &#039;year-agg&#039;: {<br \/>\n                &#039;date_histogram&#039;: {<br \/>\n                    &#039;field&#039;: &#039;updated_at&#039;,<br \/>\n                    &#039;calendar_interval&#039;: &#039;year&#039;,<br \/>\n                    &#039;format&#039;: &#039;yyyy&#039;,<br \/>\n                },<br \/>\n            },<br \/>\n        },<br \/>\n        size&#061;5,<br \/>\n        from_&#061;from_,<br \/>\n    )<br \/>\n    aggs &#061; {<br \/>\n        &#039;Category&#039;: {<br \/>\n            bucket[&#039;key&#039;]: bucket[&#039;doc_count&#039;]<br \/>\n            for bucket in results[&#039;aggregations&#039;][&#039;category-agg&#039;][&#039;buckets&#039;]<br \/>\n        },<br \/>\n        &#039;Year&#039;: {<br \/>\n            bucket[&#039;key_as_string&#039;]: bucket[&#039;doc_count&#039;]<br \/>\n            for bucket in results[&#039;aggregations&#039;][&#039;year-agg&#039;][&#039;buckets&#039;]<br \/>\n            if bucket[&#039;doc_count&#039;] &gt; 0<br \/>\n        },<br \/>\n    }<br \/>\n    return render_template(&#039;index.html&#039;, results&#061;results[&#039;hits&#039;][&#039;hits&#039;],<br \/>\n                           query&#061;query, from_&#061;from_,<br \/>\n                           total&#061;results[&#039;hits&#039;][&#039;total&#039;][&#039;value&#039;], aggs&#061;aggs) <\/p>\n<p>\u4f7f\u7528\u8fd9\u4e2a\u7248\u672c\u540e&#xff0c;\u6bcf\u79cd\u641c\u7d22\u65b9\u6cd5\u7684\u6700\u4f73\u7ed3\u679c\u90fd\u4f1a\u88ab\u5408\u5e76\u3002\u70b9\u51fb\u6b64\u5904\u67e5\u770b\u5305\u542b\u8fd9\u4e9b\u66f4\u6539\u7684\u5b8c\u6574\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u6b63\u5bf9\u81ea\u7b7e\u540d\u7684 Elasticsearch \u96c6\u7fa4&#xff0c;\u8bf7\u53c2\u8003\u4ee3\u7801\u00a0GitHub &#8211; liu-xiao-guo\/search-tutorial-v2 \u00b7 GitHub<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1500\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802010103-6a6e96cfa661f.png\" width=\"2426\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u7ee7\u4e4b\u524d\u6587\u7ae0 \u201cElasticsearch&#xff1a;\u641c\u7d22\u6559\u7a0b &#8211; \u5168\u6587\u641c\u7d22&#xff08;\u4e00&#xff09;\u201d\u3002\u5728\u7ee7\u7eed\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u524d&#xff0c;\u4f60\u5fc5\u987b\u4ed4\u7ec6\u9605\u8bfb\u4e4b\u524d\u7684\u90a3\u7bc7\u6587\u7ae0\u3002 Embedding \u7b80\u4ecb<br \/>\n\u5728 Machine Learning \u4e2d&#xff0c;embedding \u662f\u4e00\u4e2a vector&#xff08;\u6570\u5b57\u6570\u7ec4&#xff09;&#xff0c;\u7528\u4e8e\u8868\u793a\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u5bf9\u8c61&#xff0c;\u4f8b\u5982 words\u3001sentences\u3001images \u6216 videos<\/p>\n","protected":false},"author":2,"featured_media":89021,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1299,3368,323,2215,100],"topic":[],"class_list":["post-89023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-elasticsearch","tag-3368","tag-323","tag-2215","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/89023.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u8fd9\u7bc7\u6587\u7ae0\u662f\u7ee7\u4e4b\u524d\u6587\u7ae0 \u201cElasticsearch&#xff1a;\u641c\u7d22\u6559\u7a0b - \u5168\u6587\u641c\u7d22&#xff08;\u4e00&#xff09;\u201d\u3002\u5728\u7ee7\u7eed\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u524d&#xff0c;\u4f60\u5fc5\u987b\u4ed4\u7ec6\u9605\u8bfb\u4e4b\u524d\u7684\u90a3\u7bc7\u6587\u7ae0\u3002 Embedding \u7b80\u4ecb \u5728 Machine Learning \u4e2d&#xff0c;embedding \u662f\u4e00\u4e2a vector&#xff08;\u6570\u5b57\u6570\u7ec4&#xff09;&#xff0c;\u7528\u4e8e\u8868\u793a\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u5bf9\u8c61&#xff0c;\u4f8b\u5982 words\u3001sentences\u3001images \u6216 videos\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/89023.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-02T01:01:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802010102-6a6e96ce2e149.webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89023.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/89023.html\",\"name\":\"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-02T01:01:06+00:00\",\"dateModified\":\"2026-08-02T01:01:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/89023.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/89023.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89023.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/89023.html","og_locale":"zh_CN","og_type":"article","og_title":"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u8fd9\u7bc7\u6587\u7ae0\u662f\u7ee7\u4e4b\u524d\u6587\u7ae0 \u201cElasticsearch&#xff1a;\u641c\u7d22\u6559\u7a0b - \u5168\u6587\u641c\u7d22&#xff08;\u4e00&#xff09;\u201d\u3002\u5728\u7ee7\u7eed\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u524d&#xff0c;\u4f60\u5fc5\u987b\u4ed4\u7ec6\u9605\u8bfb\u4e4b\u524d\u7684\u90a3\u7bc7\u6587\u7ae0\u3002 Embedding \u7b80\u4ecb \u5728 Machine Learning \u4e2d&#xff0c;embedding \u662f\u4e00\u4e2a vector&#xff08;\u6570\u5b57\u6570\u7ec4&#xff09;&#xff0c;\u7528\u4e8e\u8868\u793a\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u5bf9\u8c61&#xff0c;\u4f8b\u5982 words\u3001sentences\u3001images \u6216 videos","og_url":"https:\/\/www.wsisp.com\/helps\/89023.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-02T01:01:06+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802010102-6a6e96ce2e149.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/89023.html","url":"https:\/\/www.wsisp.com\/helps\/89023.html","name":"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-02T01:01:06+00:00","dateModified":"2026-08-02T01:01:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/89023.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/89023.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/89023.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Elasticsearch\uff1a\u641c\u7d22\u6559\u7a0b - \u5411\u91cf\u641c\u7d22\uff08\u4e8c\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=89023"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89023\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/89021"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=89023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=89023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=89023"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=89023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}