{"id":23264,"date":"2024-11-21T11:57:40","date_gmt":"2024-11-21T03:57:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23264\/"},"modified":"2024-11-21T11:57:40","modified_gmt":"2024-11-21T03:57:40","slug":"thinkphp6%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8celasticsearch%e5%85%a8%e6%96%87%e6%90%9c%e7%b4%a2%e6%93%8d%e4%bd%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23264\/","title":{"rendered":"ThinkPHP6\u4e2d\u5982\u4f55\u8fdb\u884cElasticsearch\u5168\u6587\u641c\u7d22\u64cd\u4f5c\uff1f"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\u548c\u6570\u636e\u91cf\u7684\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u8fdb\u884c\u5168\u6587\u641c\u7d22\u5df2\u7ecf\u6210\u4e3a\u4e86\u8d8a\u6765\u8d8a\u591a\u5f00\u53d1\u8005\u9762\u4e34\u7684\u95ee\u9898\u3002elasticsearch\u662f\u4e00\u79cd\u6d41\u884c\u7684\u5168\u6587\u641c\u7d22\u5f15\u64ce\uff0c\u5b83\u80fd\u591f\u5feb\u901f\u5904\u7406\u5927\u91cf\u7684\u6587\u672c\u6570\u636e\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u68c0\u7d22\u548c\u5206\u6790\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e86\u5f88\u591aweb\u5e94\u7528\u7a0b\u5e8f\u7684\u9996\u9009\u5de5\u5177\u3002\u73b0\u5728\uff0c6\u4e5f\u5df2\u7ecf\u5f00\u59cb\u652f\u6301elasticsearch\u5168\u6587\u641c\u7d22\u64cd\u4f5c\uff0c\u4e3a\u5f00\u53d1\u8005\u5e26\u6765\u66f4\u52a0\u9ad8\u6548\u7684\u641c\u7d22\u65b9\u6848\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728ThinkPHP6\u4e2d\u5b89\u88c5Elasticsearch\u652f\u6301\u5e93\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728composer.json\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6765\u5b8c\u6210\uff1a<\/p>\n<p>&#8220;require&#8221;: {<\/p>\n<pre>\"elasticsearch\/elasticsearch\": \"^7.0\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>}<\/p>\n<p>\u7136\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u6267\u884ccomposer update\u547d\u4ee4\uff0c\u5373\u53ef\u5b8c\u6210Elasticsearch\u652f\u6301\u5e93\u7684\u5b89\u88c5\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2aElasticsearch\u670d\u52a1\u63d0\u4f9b\u8005\uff0c\u5c06Elasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\uff0c\u4ee5\u4fbf\u6211\u4eec\u968f\u65f6\u53ef\u4ee5\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\u3002\u5728App\/Provider\u76ee\u5f55\u4e0b\uff0c\u521b\u5efaElasticsearchServiceProvider.php\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>namespace appprovider;<\/p>\n<p>use ElasticsearchClientBuilder;<br \/>use thinkService;<\/p>\n<p>class ElasticsearchServiceProvider extends Service<br \/>{<\/p>\n<pre>public function register()\n{\n    \/\/ \u83b7\u53d6config\/elasticsearch.php\u914d\u7f6e\n    $config = $this-&amp;gt;app-&amp;gt;config-&amp;gt;get('elasticsearch');\n\n    \/\/ \u521b\u5efaElasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\n    $client = ClientBuilder::create()-&amp;gt;setHosts($config['hosts'])-&amp;gt;build();\n\n    \/\/ \u5c06Elasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\n    $this-&amp;gt;app-&amp;gt;bind('elasticsearch', $client);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>}<\/p>\n<p>\u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4ececonfig\/elasticsearch.php\u914d\u7f6e\u6587\u4ef6\u4e2d\u83b7\u53d6Elasticsearch\u7684\u4e3b\u673a\u5730\u5740\uff0c\u7136\u540e\u4f7f\u7528ClientBuilder\u7c7b\u521b\u5efa\u4e00\u4e2aElasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\uff0c\u5e76\u5c06\u5176\u7ed1\u5b9a\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u5bb9\u5668\u4e2d\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u968f\u65f6\u4f7f\u7528\u5b83\u6765\u6267\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u4e86\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6f14\u793a\u5982\u4f55\u5728ThinkPHP6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fdb\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2aElasticsearchService\u670d\u52a1\u7c7b\uff0c\u8be5\u7c7b\u5305\u542b\u4e86\u51e0\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6267\u884c\u641c\u7d22\u64cd\u4f5c\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>namespace appservice;<\/p>\n<p>use ElasticsearchClient;<br \/>use ElasticsearchCommonExceptionsMissing404Exception;<br \/>use Throwable;<\/p>\n<p>class ElasticsearchService<br \/>{<\/p>\n<pre>protected $client;\n\npublic function __construct(Client $client)\n{\n    $this-&amp;gt;client = $client;\n}\n\n\/**\n * \u521b\u5efa\u7d22\u5f15\n *\n * @param string $indexName \u7d22\u5f15\u540d\u79f0\n * @return bool\n *\/\npublic function createIndex(string $indexName)\n{\n    $params = [\n        'index' =&amp;gt; $indexName,\n        'body' =&amp;gt; [\n            'mappings' =&amp;gt; [\n                'properties' =&amp;gt; [\n                    'title' =&amp;gt; [\n                        'type' =&amp;gt; 'text'\n                    ],\n                    'content' =&amp;gt; [\n                        'type' =&amp;gt; 'text'\n                    ]\n                ]\n            ]\n        ]\n    ];\n\n    try {\n        $response = $this-&amp;gt;client-&amp;gt;indices()-&amp;gt;create($params);\n        return true;\n    } catch (Throwable $e) {\n        throw new Exception('\u521b\u5efa\u7d22\u5f15\u5931\u8d25\uff1a' . $e-&amp;gt;getMessage());\n    }\n}\n\n\/**\n * \u5220\u9664\u7d22\u5f15\n *\n * @param string $indexName \u7d22\u5f15\u540d\u79f0\n * @return bool\n *\/\npublic function deleteIndex(string $indexName)\n{\n    try {\n        $response = $this-&amp;gt;client-&amp;gt;indices()-&amp;gt;delete(['index' =&amp;gt; $indexName]);\n        return true;\n    } catch (Missing404Exception $e) {\n        return false;\n    } catch (Throwable $e) {\n        throw new Exception('\u5220\u9664\u7d22\u5f15\u5931\u8d25\uff1a' . $e-&amp;gt;getMessage());\n    }\n}\n\n\/**\n * \u6dfb\u52a0\u6587\u6863\n *\n * @param string $indexName \u7d22\u5f15\u540d\u79f0\n * @param string $id \u6587\u6863ID\n * @param array $data \u6587\u6863\u6570\u636e\n * @return bool\n *\/\npublic function indexDocument(string $indexName, string $id, array $data)\n{\n    $params = [\n        'index' =&amp;gt; $indexName,\n        'id' =&amp;gt; $id,\n        'body' =&amp;gt; $data\n    ];\n\n    try {\n        $response = $this-&amp;gt;client-&amp;gt;index($params);\n        return true;\n    } catch (Throwable $e) {\n        throw new Exception('\u6dfb\u52a0\u6587\u6863\u5931\u8d25\uff1a' . $e-&amp;gt;getMessage());\n    }\n}\n\n\/**\n * \u641c\u7d22\u6587\u6863\n *\n * @param string $indexName \u7d22\u5f15\u540d\u79f0\n * @param string $query \u67e5\u8be2\u5b57\u7b26\u4e32\n * @return array\n *\/\npublic function searchDocuments(string $indexName, string $query)\n{\n    $params = [\n        'index' =&amp;gt; $indexName,\n        'body' =&amp;gt; [\n            'query' =&amp;gt; [\n                'match' =&amp;gt; [\n                    '_all' =&amp;gt; $query\n                ]\n            ]\n        ]\n    ];\n\n    try {\n        $response = $this-&amp;gt;client-&amp;gt;search($params);\n        return $response['hits']['hits'];\n    } catch (Throwable $e) {\n        throw new Exception('\u641c\u7d22\u6587\u6863\u5931\u8d25\uff1a' . $e-&amp;gt;getMessage());\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>}<\/p>\n<p>\u5728\u6b64\u670d\u52a1\u7c7b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u56db\u4e2a\u65b9\u6cd5\uff1acreateIndex\u3001deleteIndex\u3001indexDocument\u548csearchDocuments\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5c01\u88c5\u4e86Elasticsearch API\u7684\u8c03\u7528\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u3001\u5220\u9664\u7d22\u5f15\uff0c\u6dfb\u52a0\u548c\u641c\u7d22\u6587\u6863\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5c06\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u9875\u9762\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201carticles\u201d\u7684\u7d22\u5f15\uff0c\u5e76\u6dfb\u52a0\u4e00\u4e9b\u6587\u6863\uff0c\u7136\u540e\u4f7f\u7528\u641c\u7d22\u6846\u641c\u7d22\u6587\u6863\u3002\u5728App\/controller\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa\u4e00\u4e2aElasticsearchTestController.php\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>namespace appcontroller;<\/p>\n<p>use appServiceElasticsearchService;<br \/>use thinkRequest;<\/p>\n<p>class ElasticsearchTestController extends BaseController<br \/>{<\/p>\n<pre>protected $elasticsearchService;\n\npublic function __construct(ElasticsearchService $elasticsearchService)\n{\n    $this-&amp;gt;elasticsearchService = $elasticsearchService;\n}\n\npublic function index()\n{\n    $this-&amp;gt;elasticsearchService-&amp;gt;createIndex('articles');\n\n    \/\/ \u6dfb\u52a0\u6d4b\u8bd5\u6587\u6863\n    $this-&amp;gt;elasticsearchService-&amp;gt;indexDocument('articles', '1', [\n        'title' =&amp;gt; 'ThinkPHP',\n        'content' =&amp;gt; 'ThinkPHP\u662f\u4e00\u6b3e\u4f18\u79c0\u7684PHP\u5f00\u53d1\u6846\u67b6'\n    ]);\n    $this-&amp;gt;elasticsearchService-&amp;gt;indexDocument('articles', '2', [\n        'title' =&amp;gt; 'Laravel',\n        'content' =&amp;gt; 'Laravel\u662f\u4e00\u6b3e\u6d41\u884c\u7684PHP\u5f00\u53d1\u6846\u67b6'\n    ]);\n    $this-&amp;gt;elasticsearchService-&amp;gt;indexDocument('articles', '3', [\n        'title' =&amp;gt; 'Symfony',\n        'content' =&amp;gt; 'Symfony\u662f\u4e00\u6b3ePHP\u5f00\u53d1\u6846\u67b6'\n    ]);\n\n    \/\/ \u641c\u7d22\u6846\n    $search = Request::instance()-&amp;gt;get('search', '');\n\n    \/\/ \u641c\u7d22\u7ed3\u679c\n    $results = $this-&amp;gt;elasticsearchService-&amp;gt;searchDocuments('articles', $search);\n\n    \/\/ \u8fd4\u56de\u641c\u7d22\u7ed3\u679c\n    return $this-&amp;gt;fetch('index', [\n        'results' =&amp;gt; $results\n    ]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>}<\/p>\n<p>\u5728\u6b64\u63a7\u5236\u5668\u4e2d\uff0c\u6211\u4eec\u6ce8\u5165\u4e86ElasticsearchService\u670d\u52a1\uff0c\u5e76\u5728index\u65b9\u6cd5\u4e2d\u8c03\u7528\u4e86createIndex\u3001indexDocument\u548csearchDocuments\u65b9\u6cd5\u6765\u521b\u5efa\u7d22\u5f15\u3001\u6dfb\u52a0\u6587\u6863\u548c\u6267\u884c\u641c\u7d22\u64cd\u4f5c\u3002\u641c\u7d22\u6846\u548c\u641c\u7d22\u7ed3\u679c\u4e5f\u88ab\u5305\u542b\u5728\u4e86index\u65b9\u6cd5\u4e2d\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u5728ThinkPHP6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528Elasticsearch\u8fdb\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u7684\u6f14\u793a\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u672c\u4f8b\u4ec5\u4ec5\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6f14\u793a\u7528\u4f8b\uff0c\u5b9e\u9645\u9879\u76ee\u4e2d\u9700\u8981\u66f4\u52a0\u7ec6\u81f4\u5730\u8fdb\u884c\u7d22\u5f15\u8bbe\u8ba1\u548c\u6587\u6863\u7ba1\u7406\uff0c\u4ee5\u786e\u4fdd\u641c\u7d22\u6548\u7387\u548c\u641c\u7d22\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002<\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u968f\u7740Elasticsearch\u7684\u5e7f\u6cdb\u5e94\u7528\uff0c\u5b83\u5df2\u7ecf\u6210\u4e3a\u4e86Web\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4e00\u79cd\u975e\u5e38\u6d41\u884c\u548c\u9ad8\u6548\u7684\u5168\u6587\u641c\u7d22\u5f15\u64ce\u3002\u5728ThinkPHP6\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528Elasticsearch\u652f\u6301\u5e93\u548cElasticsearch API\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP6\u4e2d\u5982\u4f55\u8fdb\u884cElasticsearch\u5168\u6587\u641c\u7d22\u64cd\u4f5c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\u548c\u6570\u636e\u91cf\u7684\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u8fdb\u884c\u5168\u6587\u641c\u7d22\u5df2\u7ecf\u6210\u4e3a\u4e86\u8d8a\u6765\u8d8a\u591a\u5f00\u53d1\u8005\u9762\u4e34\u7684\u95ee\u9898\u3002elasticsearch\u662f\u4e00\u79cd\u6d41\u884c\u7684\u5168\u6587\u641c\u7d22\u5f15\u64ce\uff0c\u5b83\u80fd\u591f\u5feb\u901f\u5904\u7406\u5927\u91cf\u7684\u6587\u672c\u6570\u636e\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u68c0\u7d22\u548c\u5206\u6790\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e86\u5f88\u591aweb\u5e94\u7528\u7a0b\u5e8f\u7684\u9996\u9009\u5de5\u5177\u3002\u73b0\u5728\uff0c6\u4e5f\u5df2\u7ecf\u5f00\u59cb\u652f\u6301elasticsearch\u5168\u6587\u641c\u7d22\u64cd\u4f5c\uff0c\u4e3a\u5f00\u53d1\u8005\u5e26\u6765\u66f4\u52a0\u9ad8\u6548\u7684\u641c\u7d22\u65b9\u6848\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728ThinkPHP6\u4e2d\u5b89\u88c5Elasticsearch\u652f\u6301\u5e93\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728composer.json\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6765\u5b8c\u6210\uff1a &#8220;require&#8221;: { &#8220;elasticsearch\/elasticsearch&#8221;: &#8220;^7.0&#8221; \u767b\u5f55\u540e\u590d\u5236 } \u7136\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u6267\u884ccomposer update\u547d\u4ee4\uff0c\u5373\u53ef\u5b8c\u6210Elasticsearch\u652f\u6301\u5e93\u7684\u5b89\u88c5\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2aElasticsearch\u670d\u52a1\u63d0\u4f9b\u8005\uff0c\u5c06Elasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\uff0c\u4ee5\u4fbf\u6211\u4eec\u968f\u65f6\u53ef\u4ee5\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\u3002\u5728App\/Provider\u76ee\u5f55\u4e0b\uff0c\u521b\u5efaElasticsearchServiceProvider.php\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a namespace appprovider; use ElasticsearchClientBuilder;use thinkService; class ElasticsearchServiceProvider extends Service{ public function register() { \/\/ \u83b7\u53d6config\/elasticsearch.php\u914d\u7f6e $config = $this-&amp;gt;app-&amp;gt;config-&amp;gt;get(&#8216;elasticsearch&#8217;); \/\/ \u521b\u5efaElasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b $client = ClientBuilder::create()-&amp;gt;setHosts($config[&#8216;hosts&#8217;])-&amp;gt;build(); \/\/ \u5c06Elasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d $this-&amp;gt;app-&amp;gt;bind(&#8216;elasticsearch&#8217;, $client); } \u767b\u5f55\u540e\u590d\u5236 } \u5728\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4ececonfig\/elasticsearch.php\u914d\u7f6e\u6587\u4ef6\u4e2d\u83b7\u53d6Elasticsearch\u7684\u4e3b\u673a\u5730\u5740\uff0c\u7136\u540e\u4f7f\u7528ClientBuilder\u7c7b\u521b\u5efa\u4e00\u4e2aElasticsearch\u5ba2\u6237\u7aef\u5b9e\u4f8b\uff0c\u5e76\u5c06\u5176\u7ed1\u5b9a\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u5bb9\u5668\u4e2d\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u968f\u65f6\u4f7f\u7528\u5b83\u6765\u6267\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u4e86\u3002 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6f14\u793a\u5982\u4f55\u5728ThinkPHP6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fdb\u884c\u5168\u6587\u641c\u7d22\u64cd\u4f5c\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2aElasticsearchService\u670d\u52a1\u7c7b\uff0c\u8be5\u7c7b\u5305\u542b\u4e86\u51e0\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6267\u884c\u641c\u7d22\u64cd\u4f5c\u3002\u4ee3\u7801\u5982\u4e0b\uff1a namespace appservice; use ElasticsearchClient;use ElasticsearchCommonExceptionsMissing404Exception;use Throwable; class ElasticsearchService{ protected $client; public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23264","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=23264"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23264\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}